Cucumber and ruby: print every step executed

154 views Asked by At

With the function below, I can receive a print of the last execution of the test, however I want to learn how to receive a print at every step executed by the automation.

How can this be done?

env.rb

# encoding: utf-8
require 'watir'
require 'rspec'

hooks.rb

# coding: utf-8
require 'json'
require 'magic_encoding'
require 'win32console'
require 'watir'
require 'rspec'


browser = Watir::Browser.new
browser.driver.manage.window.maximize

Before do 
@browser
    @browser = browser
  end

After do |_scenario|
  browser.screenshot.save 'screenshot.png'
  embed 'screenshot.png', 'image/png'
end

login.rb

given("que estou na tela de login") do

            @browser.goto "url"

         #I want a screenshot of this step

end
1

There are 1 answers

1
Justin Ko On

There is an AfterStep hook if you want to do an action after each step - eg:

AfterStep do
  browser.screenshot.save 'screenshot.png'
end