diff --git a/README.md b/README.md index 75fcb5a..1e2870d 100644 --- a/README.md +++ b/README.md @@ -19,11 +19,19 @@ require 'persistent_selenium/driver' Capybara.default_driver = :persistent_selenium ``` +If you're using Cucumber, you can also install that hook: + +``` bash +persistent_selenium install +``` + 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 +40,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 da641b4..b71f54f 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 @@ -56,10 +57,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..f305424 100644 --- a/lib/persistent_selenium/cli.rb +++ b/lib/persistent_selenium/cli.rb @@ -3,6 +3,12 @@ require 'persistent_selenium' module PersistentSelenium class CLI < Thor + include Thor::Actions + + def self.source_root + File.expand_path('../../../skel', __FILE__) + end + desc "start", "Start the server" method_options :port => PersistentSelenium.port, :browser => PersistentSelenium.browser def start @@ -16,14 +22,19 @@ 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 + desc "install", "Install Cucumber hook for using persistent selenium" + def install + directory '.', '.' + end + default_task :start end end diff --git a/skel/features/support/persistent_selenium.rb b/skel/features/support/persistent_selenium.rb new file mode 100644 index 0000000..f774190 --- /dev/null +++ b/skel/features/support/persistent_selenium.rb @@ -0,0 +1,11 @@ +# get the driver ready for use +require 'persistent_selenium/driver' + +# set it for all tests +# Capybara.default_driver = Capybara.javascript_driver = :persistent_selenium +# +# or, set it via the ENV, with it being the default +# Before do +# Capybara.default_driver = Capybara.javascript_driver = (ENV['DRIVER'] || 'persistent_selenium').to_sym +# end +