Sorry, I assumed otherwise because you posted in the Watir group :).

I haven't used the Around hook before, so I decided to figure it out and 
explain it here. Hopefully someone more experienced can chime in if my 
answer is incomplete or incorrect. 

So, it appears that the Around hook is specifically designed to provide 
access to the *scenario *(*Cucumber::Core::Test::Case*) object and a *block 
*(*Proc*). The *block* is what holds the execution logic/steps in your 
Scenario (source 
<https://app.cucumber.pro/projects/cucumber-ruby/documents/branch/master/features/docs/exception_in_around_hook.feature>)
 
AND the Before/After hooks. If you don't *call* the *block*, the 
Before/After hooks and the Scenario steps will not execute. This 
establishes the execution order as Around hook > Before/After hook > 
Scenario steps. You can test this by printing something from the 
Before/After hooks and commenting out *block.call *in your Around hook*.* 
You'll 
see that nothing is printed, including the Scenario steps, until you 
uncomment *block.call*.

Now that we know the Before/After hooks are invoked by the *block *from the 
Around hook, there is no further use of the *block *once it is called. 
Therefore, the Before/After hooks only allow us to work with the *scenario *
object.

Hope this explains the reasoning behind the difference in the syntax.

On Tuesday, January 29, 2019 at 2:01:06 AM UTC-8, NaviHan wrote:

> Thanks Laskhya. Im aware of the use of the hooks. But rathet confused by 
> the syntax.. Here are the blocks in my projects hooks.rb
>
> Sometimes "scenario" is passed, Sometimes "scenario" and "block" are 
> passed. Its quite confusing how exactly its doing?
>
> Before do
>  @browser = browser
> end
> Before do|scenario|
>  ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
>  DataMagic.load('order_details.yml')
>  DataMagic.load_for_scenario(scenario)
> end
> 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
>
>
>
>
> 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.

Reply via email to