I am automating using Cucumber and Watir Webdriver and I want to know if there is a way to clear the state of the browser instead of closing it after every run so that I can use Scenario Outline and I open just one instance of the browser and clear state of the browser for other examples listed in the example table
Scenario Outline: This is an example of what I want to achieve.
Given I visit the <Website>
Then the current page must be <page_title>
Example:
|Website|page_title|
|google| Google|
|Facebook|Welcome to Facebook|
Assuming that, in terms of resetting the browser, you just need to clear the cookies, you can use the following hooks.
# Create a browser that will be used for all scenarios
browser = Watir::Browser.new
Before do
@browser = browser
end
# Clear the state (cookies) before each scenario
Before do |scenario|
@browser.cookies.clear
end
# Close the browser after all scenarios completed
at_exit do
browser.close
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With