Hi Critina, You don't have to close browser (@browser.close) on *After* hook.That closes browser after each scenario execution. Also, you don't have to start a new browser on before hooks because that starts a new browser before each scenario execution.
You could use a lazy loading on Before like: Before do @browser ||= Watir::Browser.new :firefox # If browser exist, uses the existing browser session, else creates a new instance end There is a hook called at_exit that executes a block of code after all scenarios execution. But the issue here is that @browser is not reachable within that hook, so you wont be able to use @browser.close I think about two things you could do here. One is to use $browser instead @browser across all the code, but it is not so good to use global variables. In this case you will be able to use $browser.close on at_exit hook. Second is a little similar to the first. You could use a global variable on after hook to make a copy of browser in a global variable to be able to close browser: After do $browser_copy = @browser end at_exit do $browser_copy.close end I know that it is not the best way, but it works. With this second idea you would not have to change @browser to $browser in all your code. Hope it help Regards El miércoles, 22 de octubre de 2014 11:29:49 UTC-3, christina escribió: > > Hi I have a question. > > I am using testgen gem and created the project and i get the > hooks.rb which contains > > > require 'watir-webdriver' > > > Before do > @browser = Watir::Browser.new :firefox > > end > > > After do > @browser.close > end > > > No I have no idea what i have to do to not use it. I want to run all > scenarios on the same browser. > > Can one help me and telling me what do I have to do? > > > Kind reards, > Cristina > > > > -- -- Before posting, please read http://watir.com/support. In short: search before you ask, be nice. [email protected] http://groups.google.com/group/watir-general [email protected] --- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
