persistent_selenium 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +39 -3
- data/bin/persistent_selenium +4 -0
- data/lib/persistent_selenium/browser.rb +8 -2
- data/lib/persistent_selenium/cli.rb +8 -3
- data/lib/persistent_selenium/drb.rb +17 -0
- data/lib/persistent_selenium/driver.rb +4 -3
- data/lib/persistent_selenium/version.rb +1 -1
- data/lib/persistent_selenium.rb +15 -1
- metadata +3 -2
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# Persistent Selenium
|
2
|
+
|
1
3
|
Now you can keep that precious browser window open when doing continuous integration testing.
|
2
4
|
Save seconds, and sanity, with every test re-run!
|
3
5
|
|
@@ -7,7 +9,7 @@ fix your tests and/or code.
|
|
7
9
|
Start an instance:
|
8
10
|
|
9
11
|
``` bash
|
10
|
-
persistent_selenium [ --port 9854 ] [ --browser firefox ]
|
12
|
+
persistent_selenium [ --port 9854 ] [ --browser firefox ] [ --chrome-extensions <file.crx> ... ]
|
11
13
|
```
|
12
14
|
|
13
15
|
Tell Capybara to use it:
|
@@ -36,11 +38,45 @@ these two differences:
|
|
36
38
|
The browser's cache is disabled, and cookies are reset before the next test runs, so you still get the state
|
37
39
|
cleared out before your next set of tests.
|
38
40
|
|
39
|
-
###
|
41
|
+
### .persistent_selenium
|
42
|
+
|
43
|
+
Configure everything in your app with a `.persistent_selenium` file:
|
44
|
+
|
45
|
+
``` ruby
|
46
|
+
# .persistent_selenium
|
47
|
+
PersistentSelenium.configure do |c|
|
48
|
+
c.browser = :chrome
|
49
|
+
c.chrome_extensions = %w{AngularJS-Batarang.crx}
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
### Chrome Extensions
|
54
|
+
|
55
|
+
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),
|
56
|
+
download the extension, put it in your project's folder somewhere, and call `persistent_selenium` with the path
|
57
|
+
to the extension:
|
58
|
+
|
59
|
+
``` bash
|
60
|
+
persistent_selenium --browser chrome --chrome-extensions AngularJS-Batarang.crx
|
61
|
+
```
|
62
|
+
|
63
|
+
## Best practice
|
64
|
+
|
65
|
+
Use it with Foreman and Guard. Start up your test suite via Guard, configure your test suite to
|
66
|
+
use persistent_selenium, and run persistent_selenium alongside it:
|
67
|
+
|
68
|
+
``` yaml
|
69
|
+
guard: guard -g wip
|
70
|
+
ps: persistent_selenium
|
71
|
+
```
|
72
|
+
|
73
|
+
It's an integral part of my [integration testing setup](http://github.com/johnbintz/bintz-integration_testing_setup).
|
74
|
+
|
75
|
+
## Under the hood
|
40
76
|
|
41
77
|
It's DRb, which mostly Just Works (tm), and has a little reshuffling of the default Capybara Selenium driver's code.
|
42
78
|
|
43
|
-
|
79
|
+
### When DRb doesn't Just Work (tm)
|
44
80
|
|
45
81
|
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
|
46
82
|
to perform an action on, it's best to stick with `find`, since it's less likely that node will go out of
|
data/bin/persistent_selenium
CHANGED
@@ -5,7 +5,7 @@ require 'base64'
|
|
5
5
|
module PersistentSelenium
|
6
6
|
class Browser < Capybara::Selenium::Driver
|
7
7
|
def initialize(browser_type)
|
8
|
-
@browser_type = browser_type
|
8
|
+
@browser_type = browser_type.to_s.to_sym
|
9
9
|
@__found_elements__ = []
|
10
10
|
end
|
11
11
|
|
@@ -20,7 +20,13 @@ module PersistentSelenium
|
|
20
20
|
|
21
21
|
options = { :profile => profile }
|
22
22
|
when :chrome
|
23
|
-
|
23
|
+
profile = Selenium::WebDriver::Chrome::Profile.new
|
24
|
+
|
25
|
+
PersistentSelenium.chrome_extensions.each do |extension|
|
26
|
+
profile.add_extension extension
|
27
|
+
end
|
28
|
+
|
29
|
+
options = { :profile => profile, :switches => %w{--disk-cache-size=1 --media-cache-size=1} }
|
24
30
|
end
|
25
31
|
|
26
32
|
@browser ||= Selenium::WebDriver.for(@browser_type, options)
|
@@ -10,14 +10,19 @@ module PersistentSelenium
|
|
10
10
|
end
|
11
11
|
|
12
12
|
desc "start", "Start the server"
|
13
|
-
method_options :port => PersistentSelenium.port,
|
13
|
+
method_options :port => PersistentSelenium.port,
|
14
|
+
:browser => PersistentSelenium.browser,
|
15
|
+
:timeout => PersistentSelenium.timeout
|
16
|
+
method_option :chrome_extensions, :type => :array, :default => []
|
14
17
|
def start
|
15
18
|
require 'persistent_selenium/browser'
|
16
|
-
require 'drb'
|
19
|
+
require 'persistent_selenium/drb'
|
17
20
|
|
18
21
|
PersistentSelenium.configure do |c|
|
19
22
|
c.port = options[:port]
|
20
|
-
c.browser = options[:browser]
|
23
|
+
c.browser = options[:browser] if options[:browser]
|
24
|
+
c.timeout = options[:timeout]
|
25
|
+
c.chrome_extensions = options[:chrome_extensions] if !options[:chrome_extensions].empty?
|
21
26
|
end
|
22
27
|
|
23
28
|
puts "Starting persistent_selenium on #{PersistentSelenium.port} with #{PersistentSelenium.browser}"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'drb'
|
2
|
+
|
3
|
+
module DRb
|
4
|
+
class DRbTCPSocket
|
5
|
+
alias :_set_sockopt :set_sockopt
|
6
|
+
|
7
|
+
def set_sockopt(soc)
|
8
|
+
_set_sockopt(soc)
|
9
|
+
|
10
|
+
optval = [ PersistentSelenium.timeout, 0 ].pack("l_2")
|
11
|
+
|
12
|
+
soc.setsockopt Socket::SOL_SOCKET, Socket::SO_RCVTIMEO, optval
|
13
|
+
soc.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'persistent_selenium'
|
2
|
+
require 'persistent_selenium/browser'
|
2
3
|
require 'capybara/selenium/driver'
|
3
4
|
|
4
5
|
# make sure these classes exist on this end
|
@@ -11,10 +12,10 @@ Before do
|
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
|
-
|
15
|
-
require 'drb'
|
15
|
+
require 'persistent_selenium/drb'
|
16
16
|
|
17
|
-
|
17
|
+
Capybara.register_driver :persistent_selenium do |app|
|
18
|
+
service = DRb.start_service
|
18
19
|
browser = DRbObject.new nil, PersistentSelenium.url
|
19
20
|
|
20
21
|
server = Capybara::Server.new(app)
|
data/lib/persistent_selenium.rb
CHANGED
@@ -3,7 +3,7 @@ require 'selenium-webdriver'
|
|
3
3
|
|
4
4
|
module PersistentSelenium
|
5
5
|
class << self
|
6
|
-
attr_writer :port, :browser
|
6
|
+
attr_writer :port, :browser, :timeout, :chrome_extensions
|
7
7
|
|
8
8
|
def port
|
9
9
|
@port ||= 9854
|
@@ -13,6 +13,14 @@ module PersistentSelenium
|
|
13
13
|
@browser ||= :firefox
|
14
14
|
end
|
15
15
|
|
16
|
+
def timeout
|
17
|
+
@timeout ||= 120
|
18
|
+
end
|
19
|
+
|
20
|
+
def chrome_extensions
|
21
|
+
@chrome_extensions ||= []
|
22
|
+
end
|
23
|
+
|
16
24
|
def url
|
17
25
|
"druby://localhost:#{port}"
|
18
26
|
end
|
@@ -20,5 +28,11 @@ module PersistentSelenium
|
|
20
28
|
def configure
|
21
29
|
yield self
|
22
30
|
end
|
31
|
+
|
32
|
+
def load_dotfile(file = '.persistent_selenium')
|
33
|
+
if File.file?(file)
|
34
|
+
load file
|
35
|
+
end
|
36
|
+
end
|
23
37
|
end
|
24
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: persistent_selenium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: selenium-webdriver
|
@@ -45,6 +45,7 @@ files:
|
|
45
45
|
- lib/persistent_selenium.rb
|
46
46
|
- lib/persistent_selenium/browser.rb
|
47
47
|
- lib/persistent_selenium/cli.rb
|
48
|
+
- lib/persistent_selenium/drb.rb
|
48
49
|
- lib/persistent_selenium/driver.rb
|
49
50
|
- lib/persistent_selenium/version.rb
|
50
51
|
- persistent_selenium.gemspec
|