selenium-helper 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/selenium-helper.rb +55 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7f4480c96b6bb5b66d0c48cd78f87f6a130d04c
|
4
|
+
data.tar.gz: e1343900f006896ab47e247f1b2864b38f02ac84
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6586aa7301890d6f222b9724976463e3b21a403a79d97b6ed23c5e08972799b88d5140af910999ec2087cc1942992d0ae37b3e1e3e3357e5afea3098e8b3ef88
|
7
|
+
data.tar.gz: 7804f501a7f177b4051bf122a6aee620b3423a8a197a8b94e99335da803372a21f7b7cca88338390d790289623bb6138b97025ae11840e8ade19e1b45cb7fc20
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "open-uri"
|
3
|
+
require "selenium-webdriver"
|
4
|
+
require "timeout"
|
5
|
+
|
6
|
+
module SeleniumHelper
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def for(*args)
|
10
|
+
remote(*args) if args.include?(:remote)
|
11
|
+
return Selenium::WebDriver.for(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def remote(bridge, opts = {})
|
17
|
+
timeout = opts.delete(:timeout) { 3600 }
|
18
|
+
opts = opts.dup
|
19
|
+
url = opts.delete(:url) { "http://#{Selenium::WebDriver::Platform.localhost}:4444" }
|
20
|
+
uri = url.kind_of?(URI) ? url : URI.parse(url)
|
21
|
+
uri.path = "/grid/console/"
|
22
|
+
browser = opts.delete(:desired_capabilities) { Selenium::WebDriver::Remote::Capabilities.firefox }.browser_name
|
23
|
+
|
24
|
+
begin
|
25
|
+
Timeout.timeout(timeout) do
|
26
|
+
raise "no node is connected to hub" unless any_nodes_connected_to_hub?(uri)
|
27
|
+
until any_nodes_available?(uri, browser)
|
28
|
+
sleep 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
rescue Timeout::Error
|
32
|
+
raise Timeout::Error, "no available nodes after #{timeout} seconds"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def any_nodes_available?(uri, browser)
|
37
|
+
doc = Nokogiri::HTML(open(uri))
|
38
|
+
nodes = doc.xpath("//img[contains(@title,'WebDriver') and
|
39
|
+
contains(@title, 'browserName=#{browser}')]"
|
40
|
+
).count
|
41
|
+
return nodes > 0 ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
def any_nodes_connected_to_hub?(uri)
|
45
|
+
begin
|
46
|
+
doc = Nokogiri::HTML(open(uri))
|
47
|
+
nodes = doc.xpath("//p[@class='proxyname' and not(contains(.,'refused'))]").count
|
48
|
+
return nodes == 0 ? false : true
|
49
|
+
rescue Errno::ECONNREFUSED
|
50
|
+
# hub is not running
|
51
|
+
raise Errno::ECONNREFUSED, "#{uri.host}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: selenium-helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Majorvin Tan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: ''
|
14
|
+
email: majorvin@yahoo.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/selenium-helper.rb
|
20
|
+
homepage: http://rubygems.org/gems/selenium_helper
|
21
|
+
licenses: []
|
22
|
+
metadata: {}
|
23
|
+
post_install_message:
|
24
|
+
rdoc_options: []
|
25
|
+
require_paths:
|
26
|
+
- lib
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
requirements: []
|
38
|
+
rubyforge_project:
|
39
|
+
rubygems_version: 2.0.3
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: Selenium Helper helps the integration with Selenium Grid2
|
43
|
+
test_files: []
|