Deepak Kumar Padhy
Deepak Kumar Padhy

Reputation: 4388

how to keep browser open (using existing session) for each scenario in capybara selenium

I am new to write integration tests in rails. Let's say i have below scenarios,

  1. Admin logs in.
  2. Creates a new user.
  3. Assign new role to user.

So currently for every scenario , it opens a new browser window (or may be resetting the session). As for login we are using 3rd party oauth it takes huge amount of time for login.

So i do not want to login for each scenario. Once after login it should execute scenarios one by one without asking for login again and again. But i am not sure how to achieve the same using rspec and selenium.

Any help would be greatly appreciated .

Upvotes: 1

Views: 1364

Answers (2)

Deepak Kumar Padhy
Deepak Kumar Padhy

Reputation: 4388

Capybara.current_session.instance_variable_set(:@touched, false)

Executing the above after each scenario maintains the session.

Upvotes: 3

Thomas Walpole
Thomas Walpole

Reputation: 49870

Selenium shouldn't be opening a new browser window for each scenario (unless you're specifically closing the tab in an after block), but it should reset it to about:blank. As for the rest of your request, it would be completely bypassing the intention of feature/integration tests where each test should be completely isolated from the other tests. What you should be doing, if you don't want to manually login for each test, is using the test mode of whatever auth library you're using to allow you to shortcut the login.

For instance, if using OmniAuth - see https://github.com/omniauth/omniauth/wiki/Integration-Testing

Upvotes: 0

Related Questions