drugpl / bbq

Object oriented acceptance testing using personas.
MIT License
92 stars 9 forks source link

Add support for auto closing browser windows opened by selenium #11

Closed paneq closed 11 years ago

paneq commented 13 years ago

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
paneq commented 12 years ago

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) ?

mostlyobvious commented 12 years ago

Sounds good to me.

sevos commented 11 years ago

Spawning new browser costs few seconds (1-3 on my machine). I think this would be too expensive.

sevos commented 11 years ago

Isn't that fixed by Browser pool actually?

mostlyobvious commented 11 years ago

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.

Wdyt? @paneq @sevos

paneq commented 11 years ago

Fixed by session pool indeed.