Compare commits

..

3 Commits

Author SHA1 Message Date
John Bintz 02b1e7553e Fixes for modern Capybara versions. 2015-01-09 14:56:22 -05:00
John Bintz 5e205ea347 Split up Cucumber and RSpec support 2015-01-09 14:55:26 -05:00
John Bintz fdeb1b9eb5 Ensure browser type is initialized csafely 2015-01-09 11:32:16 -05:00
8 changed files with 9 additions and 96 deletions

View File

@ -1,5 +1,3 @@
# Persistent Selenium
Now you can keep that precious browser window open when doing continuous integration testing.
Save seconds, and sanity, with every test re-run!
@ -9,7 +7,7 @@ fix your tests and/or code.
Start an instance:
``` bash
persistent_selenium [ --port 9854 ] [ --browser firefox ] [ --chrome-extensions <file.crx> ... ]
persistent_selenium [ --port 9854 ] [ --browser firefox ]
```
Tell Capybara to use it:
@ -38,45 +36,11 @@ these two differences:
The browser's cache is disabled, and cookies are reset before the next test runs, so you still get the state
cleared out before your next set of tests.
### .persistent_selenium
Configure everything in your app with a `.persistent_selenium` file:
``` ruby
# .persistent_selenium
PersistentSelenium.configure do |c|
c.browser = :chrome
c.chrome_extensions = %w{AngularJS-Batarang.crx}
end
```
### Chrome Extensions
If, for example, you do a lot with AngularJS and want to use [Batarang](https://chrome.google.com/webstore/detail/angularjs-batarang/ighdmehidhipcmcojjgiloacoafjmpfk?hl=en),
download the extension, put it in your project's folder somewhere, and call `persistent_selenium` with the path
to the extension:
``` bash
persistent_selenium --browser chrome --chrome-extensions AngularJS-Batarang.crx
```
## Best practice
Use it with Foreman and Guard. Start up your test suite via Guard, configure your test suite to
use persistent_selenium, and run persistent_selenium alongside it:
``` yaml
guard: guard -g wip
ps: persistent_selenium
```
It's an integral part of my [integration testing setup](http://github.com/johnbintz/bintz-integration_testing_setup).
## Under the hood
### Under the hood
It's DRb, which mostly Just Works (tm), and has a little reshuffling of the default Capybara Selenium driver's code.
### When DRb doesn't Just Work (tm)
#### When DRb doesn't Just Work (tm)
You're most likely using `all` and invoking an action on one of the nodes within, I'd wager. If you need to find a node
to perform an action on, it's best to stick with `find`, since it's less likely that node will go out of

View File

@ -2,10 +2,6 @@
$: << File.expand_path('../../lib', __FILE__)
require 'persistent_selenium'
PersistentSelenium.load_dotfile
require 'persistent_selenium/cli'
GC.disable

View File

@ -3,7 +3,7 @@ require 'selenium-webdriver'
module PersistentSelenium
class << self
attr_writer :port, :browser, :timeout, :chrome_extensions
attr_writer :port, :browser
def port
@port ||= 9854
@ -13,14 +13,6 @@ module PersistentSelenium
@browser ||= :firefox
end
def timeout
@timeout ||= 120
end
def chrome_extensions
@chrome_extensions ||= []
end
def url
"druby://localhost:#{port}"
end
@ -28,11 +20,5 @@ module PersistentSelenium
def configure
yield self
end
def load_dotfile(file = '.persistent_selenium')
if File.file?(file)
load file
end
end
end
end

View File

@ -6,7 +6,6 @@ module PersistentSelenium
class Browser < Capybara::Selenium::Driver
def initialize(browser_type)
@browser_type = browser_type.to_s.to_sym
@frame_handles = {}
@__found_elements__ = []
end
@ -21,13 +20,7 @@ module PersistentSelenium
options = { :profile => profile }
when :chrome
switches = %w{--disk-cache-size=1 --media-cache-size=1}
PersistentSelenium.chrome_extensions.each do |extension|
switches.push("--load-extension=#{extension}")
end
options = { switches: switches }
options = { :switches => %w{--disk-cache-size=1 --media-cache-size=1} }
end
@browser ||= Selenium::WebDriver.for(@browser_type, options)

View File

@ -10,19 +10,14 @@ module PersistentSelenium
end
desc "start", "Start the server"
method_options :port => PersistentSelenium.port,
:browser => PersistentSelenium.browser,
:timeout => PersistentSelenium.timeout
method_option :chrome_extensions, :type => :array, :default => []
method_options :port => PersistentSelenium.port, :browser => PersistentSelenium.browser
def start
require 'persistent_selenium/browser'
require 'persistent_selenium/drb'
require 'drb'
PersistentSelenium.configure do |c|
c.port = options[:port]
c.browser = options[:browser] if options[:browser]
c.timeout = options[:timeout]
c.chrome_extensions = options[:chrome_extensions] if !options[:chrome_extensions].empty?
c.browser = options[:browser]
end
puts "Starting persistent_selenium on #{PersistentSelenium.port} with #{PersistentSelenium.browser}"

View File

@ -1,17 +0,0 @@
require 'drb'
module DRb
class DRbTCPSocket
alias :_set_sockopt :set_sockopt
def set_sockopt(soc)
_set_sockopt(soc)
optval = [ PersistentSelenium.timeout, 0 ].pack("l_2")
soc.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
soc.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
end
end
end

View File

@ -1,12 +1,9 @@
require 'persistent_selenium'
require 'persistent_selenium/browser'
require 'capybara/selenium/driver'
# make sure these classes exist on this end
[ Selenium::WebDriver::Error::StaleElementReferenceError, Selenium::WebDriver::Error::UnhandledError, Selenium::WebDriver::Error::ElementNotVisibleError ]
require 'persistent_selenium/drb'
Capybara.register_driver :persistent_selenium do |app|
require 'drb'
@ -19,7 +16,6 @@ Capybara.register_driver :persistent_selenium do |app|
end
DRb.start_service
browser = DRbObject.new nil, PersistentSelenium.url
server = Capybara::Server.new(app)

View File

@ -1,3 +1,3 @@
module PersistentSelenium
VERSION = "0.1.1"
VERSION = "0.0.2"
end