Add support for auto closing browser windows opened by selenium
Closed this issue · 6 comments
The problem is that every actor (user) object created with bbq for interaction with site has a new capybara session. Probably it is not a problem for rack test-however it is for selenium because browser windows hangs around until all tests are executed.
My current workaround:
class Service::TreeTest < CapybaraTest
def TestUser(*params, &block)
user = Bbq::TestUser.new(*params, &block)
@bbq_test_users ||= []
@bbq_test_users << user
return user
end
::Bbq::TestUser.class_eval do
def mode
page.mode
end
end
::Capybara::Selenium::Driver.class_eval do
def browser?
!!@browser
end
end
teardown do
@bbq_test_users ||= []
@bbq_test_users.select{|u| u.mode == :selenium}.each do |u|
u.page.driver.quit if u.page.driver.browser? # http://img98.imageshack.us/img98/8158/lawglupcze.png
end
end
test "something" do
user = TestUser(:driver => :selenium) # instead of user = user = Bbq::TestUser.new(:driver => :selenium)
end
end
What do you think about the idea that TestUser
without browser pool would actually instead belong to a different pool that would be responsible for closing browsers after every test (instead of resetting them like our normal pool does) ?
Sounds good to me.
Spawning new browser costs few seconds (1-3 on my machine). I think this would be too expensive.
Isn't that fixed by Browser pool actually?
Pool limits the number of browser instances and reuses them between tests (reseting each browser after test). Before pool was introduced, every actor spawned it's own browser window.
Regardless of that browser windows are closed at the the end of the whole test session.
This issue predates browser pool, which solved original pain of many browser windows taking system resources.
A question that remains - does closing and opening browser windows before/after each test scenario bring any value? In my opinion not, session reset in browser pool worked correctly for me so far. And this comes with performance penalty so I opt for closing this issue.
Fixed by session pool indeed.