diff --git a/README.md b/README.md index 75fcb5a..69f7a29 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,10 @@ Capybara.default_driver = :persistent_selenium Should work just the same as if you used the standard Capybara Selenium driver, except for these two differences: -* The browser starts up first thing and sticks around. -* The last page you were on before your tests passed/failed stays there, so you can inspect it. +* The browser starts up first thing and sticks around, so you don't pay the startup/shutdown + penalty with each test run. +* The last page you were on before your tests passed/failed stays there, so you can inspect it + and adjust your tests. The browser's cookies and such are reset before the next test runs, so you still get the state cleared out before your next set of tests. @@ -32,3 +34,10 @@ cleared out before your next set of tests. It's DRb, which Just Works (tm), and a little reshuffling of the default Capybara Selenium driver's code. +#### When DRb doesn't Just Work (tm) + +You may see recycled object errorrs. Capybara is complex enough that, eventually, something +will get garbage collected on the server and an object on the client will notice. +I turned off garbage collection on the server but it still happens. +Just rerun the test. It doesn't happen too often. It's the price you pay for speed. + diff --git a/bin/persistent_selenium b/bin/persistent_selenium index a1bfd1d..7f790e6 100755 --- a/bin/persistent_selenium +++ b/bin/persistent_selenium @@ -4,4 +4,5 @@ $: << File.expand_path('../../lib', __FILE__) require 'persistent_selenium/cli' +GC.disable PersistentSelenium::CLI.start diff --git a/lib/persistent_selenium/browser.rb b/lib/persistent_selenium/browser.rb index 11ed202..c4dc45f 100644 --- a/lib/persistent_selenium/browser.rb +++ b/lib/persistent_selenium/browser.rb @@ -6,6 +6,7 @@ module PersistentSelenium class Browser < Capybara::Selenium::Driver def initialize(browser_type) @browser_type = browser_type + @__found_elements__ = [] end def browser @@ -43,10 +44,6 @@ module PersistentSelenium # instead. end end - - GC.enable - GC.start - GC.disable end def starting_page diff --git a/lib/persistent_selenium/cli.rb b/lib/persistent_selenium/cli.rb index 1cee11f..b91fa67 100644 --- a/lib/persistent_selenium/cli.rb +++ b/lib/persistent_selenium/cli.rb @@ -8,6 +8,7 @@ module PersistentSelenium def start require 'persistent_selenium/browser' require 'drb' + GC.disable PersistentSelenium.configure do |c| c.port = options[:port] @@ -16,10 +17,10 @@ module PersistentSelenium puts "Starting persistent_selenium on #{PersistentSelenium.port} with #{PersistentSelenium.browser}" - browser = Browser.new(PersistentSelenium.browser) - browser.browser + @browser = Browser.new(PersistentSelenium.browser) + @browser.browser - DRb.start_service PersistentSelenium.url, browser + DRb.start_service PersistentSelenium.url, @browser DRb.thread.join end