Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you close all open windows in capybara?

So when I run my tests individually, they work great. However, when I run my feature (multiple tests) my code is failing.
This is because when capybara exists, not all of my windows are closing and therefore my selenium drivers don't know which window to use.

Basically, what is happening is that my test is opening multiple windows. This is happening because my tests are clicking links which open new windows and checking the content in the new windows. Even though I am saying page.quit at the end of each test, this function isn't closing all open windows (closes active window but not the original window). When the 2nd test runs, it uses the originally create window, but when it goes to open the new pop up, it uses the wrong window.

How can I ensure that a new browser is being used during each test and all windows from the previous test are closed.
I am currently using page.reset! and page.quit.
Not sure, but can I say session.quit to close all open browser windows?

like image 294
Jason Avatar asked May 25 '12 18:05

Jason


1 Answers

This code works:

page.execute_script "window.close();"

I just execute this while in the window I want to close.

like image 141
Jason Avatar answered Sep 22 '22 05:09

Jason