selenium-phantomjs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +35 -0
- data/Rakefile +1 -0
- data/lib/selenium/phantomjs.rb +38 -0
- data/lib/selenium/phantomjs/instance.rb +71 -0
- data/lib/selenium/phantomjs/version.rb +5 -0
- data/lib/selenium/phantomjs/web_driver.rb +17 -0
- data/selenium-phantomjs.gemspec +25 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7472d3680be5b6fad11feef0321c7afcfd5a8b7
|
4
|
+
data.tar.gz: 3d8d65f998265f65fe3709ca8243d5624d7ee8ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4ae4d4d5be1c741bdf030aa076681d52c4631674486121e272cf421a3e2e71a96483ad39e3453017c864369b8b77fa18579bf3a1f263ad2ab78d12ad2e6a07c3
|
7
|
+
data.tar.gz: 9c5d225d0c8725bf328a564dce3b8014d5dd03244f1691e54eece60e709e83e25a696edb632843fd85be14c22e97a01af4cc314511a5de6ff8322ba0b984c0cf
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Andrew Slotin
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Selenium::Phantomjs
|
2
|
+
|
3
|
+
Provides integration between selenium-webdriver and PhantomJS via Ghostdriver
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'selenium-phantomjs'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install selenium-phantomjs
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
To use PhantomJS as a browser for Selenium test just add to your ```spec_helper.rb``` or ```Spork.prefork``` block
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
Capybara.default_driver = :selenium_phantomjs
|
25
|
+
```
|
26
|
+
|
27
|
+
Please note that Ghostdriver needs [Selenium Hub](https://code.google.com/p/selenium/wiki/Grid2) to run at ```localhost:4444```.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
1. Fork it
|
32
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
33
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
34
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
35
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'selenium-webdriver'
|
2
|
+
|
3
|
+
require 'selenium/phantomjs/version'
|
4
|
+
require 'selenium/phantomjs/instance'
|
5
|
+
require 'selenium/phantomjs/web_driver'
|
6
|
+
|
7
|
+
Selenium::Phantomjs::WebDriver.new('tmp/pids/phantomjs.pid').run
|
8
|
+
|
9
|
+
module Selenium
|
10
|
+
module Phantomjs
|
11
|
+
extend self
|
12
|
+
|
13
|
+
def register_driver
|
14
|
+
begin
|
15
|
+
require 'selenium/webdriver'
|
16
|
+
rescue LoadError
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined? Selenium::WebDriver
|
20
|
+
Capybara.register_driver :selenium_phantomjs do |app|
|
21
|
+
Capybara::Selenium::Driver.new(app, options)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def options
|
27
|
+
{
|
28
|
+
browser: :remote,
|
29
|
+
url: "#{WebDriver::SELENIUM_GRID_URL}/wd/hub",
|
30
|
+
desired_capabilities: {
|
31
|
+
browserName: :phantomjs
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
Selenium::Phantomjs.register_driver
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Selenium
|
2
|
+
module Phantomjs
|
3
|
+
class Instance
|
4
|
+
PHANTOMJS_BIN = %x{which phantomjs}.strip.freeze
|
5
|
+
|
6
|
+
attr_reader :pid_file
|
7
|
+
|
8
|
+
def initialize(pid_file)
|
9
|
+
raise "Please install phantomjs first and make sure that phantomjs is in your PATH" if PHANTOMJS_BIN == ''
|
10
|
+
|
11
|
+
pid_dir = File.dirname(pid_file)
|
12
|
+
FileUtils.mkpath(pid_dir) unless File.directory? pid_dir
|
13
|
+
|
14
|
+
@pid_file = pid_file
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(args, options = {})
|
18
|
+
die!
|
19
|
+
|
20
|
+
arguments = if args.is_a? Hash
|
21
|
+
args.map do |k, v|
|
22
|
+
if v
|
23
|
+
%Q{--#{k}="#{v}"}
|
24
|
+
else
|
25
|
+
"--#{k}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
Array(args)
|
30
|
+
end
|
31
|
+
|
32
|
+
raise ArgumentError.new("PhantomJS: interactive shell is not supported.") if arguments.empty?
|
33
|
+
|
34
|
+
@pid = Process.spawn(%Q{#{PHANTOMJS_BIN} #{arguments.join(" ")}}, options)
|
35
|
+
Process.detach(@pid)
|
36
|
+
|
37
|
+
sleep 1
|
38
|
+
raise "PhantomJS: failed to start" unless alive?
|
39
|
+
File.open(pid_file, 'w') { |f| f.write @pid }
|
40
|
+
|
41
|
+
@pid
|
42
|
+
end
|
43
|
+
|
44
|
+
def alive?
|
45
|
+
!! pid && begin
|
46
|
+
!! Process.kill(0, pid)
|
47
|
+
rescue Errno::ESRCH, RangeError
|
48
|
+
false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def die!
|
53
|
+
Process.kill('TERM', pid) if alive?
|
54
|
+
File.delete(pid_file) if File.exists? pid_file
|
55
|
+
@pid = nil
|
56
|
+
end
|
57
|
+
|
58
|
+
def pid
|
59
|
+
@pid ||= if File.exists? pid_file
|
60
|
+
File.open(pid_file, 'r') do |f|
|
61
|
+
begin
|
62
|
+
f.readline.to_s.strip.to_i
|
63
|
+
rescue EOFError
|
64
|
+
nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Selenium
|
2
|
+
module Phantomjs
|
3
|
+
class WebDriver < Instance
|
4
|
+
LOG = 'log/phantomjs.log'.freeze
|
5
|
+
LOGLEVEL = 'WARN'.freeze
|
6
|
+
SELENIUM_GRID_URL = "http://#{Selenium::WebDriver::Platform.localhost}:4444".freeze
|
7
|
+
|
8
|
+
def run(options = {[:out, :err] => [LOG, 'a']})
|
9
|
+
super({
|
10
|
+
:wd => nil,
|
11
|
+
:'webdriver-selenium-grid-hub' => SELENIUM_GRID_URL,
|
12
|
+
:'webdriver-loglevel' => LOGLEVEL
|
13
|
+
}, options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'selenium/phantomjs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "selenium-phantomjs"
|
8
|
+
spec.version = Selenium::Phantomjs::VERSION
|
9
|
+
spec.authors = ["Andrew Slotin"]
|
10
|
+
spec.email = ["andrew.slotin@gmail.com"]
|
11
|
+
spec.summary = %q{Running specs with Capybara, Selenium and PhantomJS}
|
12
|
+
spec.description = %q{This gem provides integration between selenium-webdriver and phantomjs via ghostdriver}
|
13
|
+
spec.homepage = "http://github.com/andrewslotin"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "selenium-webdriver"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: selenium-phantomjs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Slotin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: selenium-webdriver
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: This gem provides integration between selenium-webdriver and phantomjs
|
56
|
+
via ghostdriver
|
57
|
+
email:
|
58
|
+
- andrew.slotin@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/selenium/phantomjs.rb
|
69
|
+
- lib/selenium/phantomjs/instance.rb
|
70
|
+
- lib/selenium/phantomjs/version.rb
|
71
|
+
- lib/selenium/phantomjs/web_driver.rb
|
72
|
+
- selenium-phantomjs.gemspec
|
73
|
+
homepage: http://github.com/andrewslotin
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Running specs with Capybara, Selenium and PhantomJS
|
97
|
+
test_files: []
|