There is no difference in functionality from a Hooks perspective. They both work the same way, except that the in the second one you are getting access to the Scenario details (object).
Actually, you can come both the *Before *hooks to achieve the same result: Before do|scenario| @browser = browser ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil DataMagic.load_for_scenario(scenario) @browser.window.maximize @browser.driver.manage.timeouts.implicit_wait = 0 @browser.cookies.clear @browser.driver.manage.window.maximize PageObject.default_element_wait=(10) PageObject.javascript_framework = :jquery #Selenium::WebDriver.logger.level = :info end #before scenario On Friday, February 1, 2019 at 4:07:08 AM UTC-8, NaviHan wrote: > > Hi Lakshya > > Here is the hooks.rb used in our project.. > > Eventhough the the browser is assigned to instance variable @browser we > still get to see all the details you mentioned. So Im not quite getting the > difference between the two Before hooks > > require 'rubygems' > require 'page-object' > require 'watir' > require 'page-object/page_factory' > require 'log4r' > require 'cucumber' > require 'selenium-webdriver' > require 'fig_newton' > require 'watir-screenshot-stitch' > require 'mini_magick' > > args = ['--allow-running-insecure-content'] > browser = Watir::Browser.new :chrome, options: {args: args} > $code_retry = 30 > > Before do > @browser = browser > end > > > Before do|scenario| > ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil > DataMagic.load_for_scenario(scenario) > @browser.window.maximize > @browser.driver.manage.timeouts.implicit_wait = 0 > @browser.cookies.clear > @browser.driver.manage.window.maximize > PageObject.default_element_wait=(10) > PageObject.javascript_framework = :jquery > #Selenium::WebDriver.logger.level = :info > end #before scenario > > > > > # "after all" > After do |scenario| > @browser.execute_script("javascript:localStorage.clear();") > @browser.cookies.clear > if (scenario.passed?) > puts 'Scenario Passed !' > else > puts 'Scenario Failed !' > end > end > > > > AfterStep('@screen') do > filename = DateTime.now.strftime("%d%b%Y%H%M%S") > @browser.screenshot.save > ("C:/Users/lohit.kotian/Documents/Automation/screenshots-cucumber/#{filename}.png") > #@browser.screenshot.save > ("C:/Jenkins/workspace/screenshots-cucumber/#{filename}.png") > end > > > Around('@multipletimes') do |scenario, block| > $counter = 0 > $total_times_to_run = 6 > while $counter < $total_times_to_run do > block.call > puts("Total times scripts were repeated = #$counter" ) > $counter +=1 > end > end > > > After do |scenario| > take_screenshot(@browser, scenario) > end > > at_exit do > browser.close > end > > # need to check this code for the full page screenshots as a part of the > enhancement > > def take_screenshot(browser, scenario) > time = Time.now.strftime("%Y-%m-%d_%H%M") > opts = {:page_height_limit => 5000} > if scenario.failed? > scenario_name = scenario.name.gsub(/[^\w\-]/, ' ') > screenshot_path = "#{scenario_name}" + "_failure_" + time > > @browser.screenshot.save_stitch("./screenshots/#{screenshot_path}.png", > browser, opts) > end > end > > > > > > On Tuesday, 29 January 2019 16:47:10 UTC+11, NaviHan wrote: >> >> Hi all >> >> Im just looking for some good documentation which explains the usage of >> blocks in hooks.rb >> >> For example "Before", "After" , "AfterStep" etc... >> >> Thanks in advance >> > -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.