Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset the state of the browser without closing it?

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|
like image 628
Vamsi Avatar asked Dec 20 '25 20:12

Vamsi


1 Answers

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
like image 92
Justin Ko Avatar answered Dec 24 '25 12:12

Justin Ko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!