selenium-grid-parser 0.0.1
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/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +30 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/parse +26 -0
- data/lib/nodes/client/grid_node_client.rb +16 -0
- data/lib/nodes/configuration/capabilities.rb +15 -0
- data/lib/nodes/configuration/node_configuration.rb +21 -0
- data/lib/nodes/data/grid_node_data.rb +18 -0
- data/lib/nodes/grid_node.rb +29 -0
- data/lib/nodes/grid_node_set.rb +31 -0
- data/lib/selenium_grid_console_parser.rb +36 -0
- data/selenium-grid-parser.gemspec +25 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 421cc5fd051b83f53df4dc063d64011711a696c2
|
4
|
+
data.tar.gz: a38e5f7b782457f6e317ea98ce66780ab975e42b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f4668a8e84d99f1a4410e62e41083e30e022a73698f5c51c4c2f139d3aa9a699e34007f0790315d90a41d75fafa890aa4200b5a39396c964eaae312810f1061c
|
7
|
+
data.tar.gz: 945edfb912845155f9eef6109e887f594deab8035c1da85a1d35ce39f9b610b50043a70bbb751b74af7c2199ed517c401e4ea983dd1db51807e7ee43e927a660
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
selenium-grid-parser (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (9.0.5)
|
10
|
+
httparty (0.14.0)
|
11
|
+
multi_xml (>= 0.5.2)
|
12
|
+
mini_portile2 (2.1.0)
|
13
|
+
multi_xml (0.5.5)
|
14
|
+
nokogiri (1.6.8.1)
|
15
|
+
mini_portile2 (~> 2.1.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
|
18
|
+
PLATFORMS
|
19
|
+
ruby
|
20
|
+
|
21
|
+
DEPENDENCIES
|
22
|
+
bundler (~> 1.7)
|
23
|
+
byebug
|
24
|
+
httparty (~> 0.13)
|
25
|
+
nokogiri (~> 1.6)
|
26
|
+
rake (~> 10.0)
|
27
|
+
selenium-grid-parser!
|
28
|
+
|
29
|
+
BUNDLED WITH
|
30
|
+
1.12.5
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 TODO: Write your name
|
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,31 @@
|
|
1
|
+
# Selenium::Grid::Parser
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'selenium-grid-parser'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install selenium-grid-parser
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/selenium-grid-parser/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "selenium_grid_console_parser"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/parse
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$stderr.sync = true
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
require 'selenium_grid_console_parser'
|
8
|
+
|
9
|
+
# default options
|
10
|
+
url = "http://0.0.0.0:4444"
|
11
|
+
output = "hasg"
|
12
|
+
|
13
|
+
# parse arguments
|
14
|
+
file = __FILE__
|
15
|
+
ARGV.options do |opts|
|
16
|
+
opts.on("-u", "--url=val", String) { |val| url = val }
|
17
|
+
opts.on("-o", "--out-put=val", String) { |val| output = val }
|
18
|
+
opts.on_tail("-h", "--help") { exec "grep ^#/<'#{file}'|cut -c4-" }
|
19
|
+
opts.parse!
|
20
|
+
end
|
21
|
+
|
22
|
+
if output == "json"
|
23
|
+
puts SeleniumGridConsoleParser::Parser.new(url).nodes.to_json
|
24
|
+
else
|
25
|
+
puts SeleniumGridConsoleParser::Parser.new(url).nodes.to_hash
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module SeleniumGridConsoleParser
|
4
|
+
module Nodes
|
5
|
+
class GridNodeClient
|
6
|
+
def initialize(url)
|
7
|
+
@url = url
|
8
|
+
end
|
9
|
+
|
10
|
+
def sessions
|
11
|
+
response = HTTParty.get("#{@url}/wd/hub/sessions")
|
12
|
+
return response.body if response.code == 200
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SeleniumGridConsoleParser
|
2
|
+
module GridNode
|
3
|
+
class Capabilities < Hash
|
4
|
+
def self.build (capabilities_from_console)
|
5
|
+
capabilities_hash = {}
|
6
|
+
capabilities_string = capabilities_from_console.match("{(.*)}")[1].split(", ")
|
7
|
+
capabilities_string.each do |capability|
|
8
|
+
capability_key_value = capability.split("=")
|
9
|
+
capabilities_hash[capability_key_value[0]] = capability_key_value[1]
|
10
|
+
end
|
11
|
+
Capabilities[capabilities_hash]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "nodes/configuration/capabilities"
|
2
|
+
require "byebug"
|
3
|
+
|
4
|
+
module SeleniumGridConsoleParser
|
5
|
+
module GridNode
|
6
|
+
class GridNodeConfiguration < Hash
|
7
|
+
def self.build(configuration_html_elements)
|
8
|
+
configuration = {}
|
9
|
+
configuration_html_elements.each do |parameter_html_element|
|
10
|
+
parameter = parameter_html_element.text.split(": ")
|
11
|
+
if parameter[0] != "capabilities"
|
12
|
+
configuration[parameter[0]] = parameter[1]
|
13
|
+
else
|
14
|
+
configuration[parameter[0]] = Capabilities.build(parameter[1])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
GridNodeConfiguration[configuration]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'nodes/client/grid_node_client'
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module SeleniumGridConsoleParser
|
6
|
+
module Nodes
|
7
|
+
class GridNodeData
|
8
|
+
def initialize(node)
|
9
|
+
@node = node
|
10
|
+
end
|
11
|
+
|
12
|
+
def sessions
|
13
|
+
node_client = GridNodeClient.new(@node.remoteHost)
|
14
|
+
JSON.parse(node_client.sessions)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'nodes/data/grid_node_data'
|
2
|
+
|
3
|
+
module SeleniumGridConsoleParser
|
4
|
+
module Nodes
|
5
|
+
class GridNode
|
6
|
+
attr_reader :remoteHost, :configuration
|
7
|
+
|
8
|
+
def initialize(configuration)
|
9
|
+
@remoteHost = configuration["remoteHost"]
|
10
|
+
@configuration = configuration.delete_if {|key, value| key == "remoteHost"}
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@configuration["capabilities"]["applicationName"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def free?
|
18
|
+
sessions = GridNodeData.new(self).sessions
|
19
|
+
@free = sessions["value"].size == 0 ? true : false
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash
|
23
|
+
grid_node_hash = self.instance_variables.each_with_object({}) { |var, hash| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
|
24
|
+
grid_node_hash["free"] = free?
|
25
|
+
grid_node_hash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module SeleniumGridConsoleParser
|
4
|
+
module Nodes
|
5
|
+
class GridNodeSet < Set
|
6
|
+
def to_json
|
7
|
+
JSON.pretty_generate(to_hash)
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_hash
|
11
|
+
hashObject = {}
|
12
|
+
hashObject["nodes"] = self.to_a.map { |o| Hash[o.to_hash.each_pair.to_a] }
|
13
|
+
end
|
14
|
+
|
15
|
+
def free_nodes
|
16
|
+
free_nodes = GridNodeSet.new()
|
17
|
+
self.each do |node|
|
18
|
+
free_nodes.add(node) if node.free?
|
19
|
+
end
|
20
|
+
free_nodes
|
21
|
+
end
|
22
|
+
|
23
|
+
def first_free_node
|
24
|
+
self.each do |node|
|
25
|
+
return node if node.free?
|
26
|
+
end
|
27
|
+
return nil
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
|
4
|
+
require 'nodes/grid_node'
|
5
|
+
require 'nodes/grid_node_set'
|
6
|
+
require 'nodes/configuration/node_configuration'
|
7
|
+
|
8
|
+
module SeleniumGridConsoleParser
|
9
|
+
class << self
|
10
|
+
def nodes(url)
|
11
|
+
Parser.new(url).nodes
|
12
|
+
end
|
13
|
+
end
|
14
|
+
class Parser
|
15
|
+
|
16
|
+
def initialize(url)
|
17
|
+
@page = Nokogiri::HTML(open("#{url}/grid/console"))
|
18
|
+
end
|
19
|
+
|
20
|
+
def nodes
|
21
|
+
extract_node(@page.css("div[class='proxy']"))
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def extract_node(nodes_elements)
|
27
|
+
nodes = SeleniumGridConsoleParser::Nodes::GridNodeSet.new()
|
28
|
+
nodes_elements.each do |node_elements|
|
29
|
+
configuration_elements = node_elements.css("[type='config'] > p")
|
30
|
+
configuration = SeleniumGridConsoleParser::GridNode::GridNodeConfiguration.build(configuration_elements)
|
31
|
+
nodes.add (SeleniumGridConsoleParser::Nodes::GridNode.new(configuration))
|
32
|
+
end
|
33
|
+
nodes
|
34
|
+
end
|
35
|
+
end
|
36
|
+
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
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "selenium-grid-parser"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["jjortega"]
|
9
|
+
spec.email = ["juanjortcan@gmail.com"]
|
10
|
+
spec.summary = %q{Selenium-Grid doesn't have a pretty API so let parse it!}
|
11
|
+
spec.description = %q{Selenium-Grid doesn't have a pretty API so this gem is for parser the result of /grid/console to know
|
12
|
+
which nodes are free to use them when running your tests}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "nokogiri", "~> 1.6"
|
24
|
+
spec.add_development_dependency "httparty", "~> 0.13"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: selenium-grid-parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jjortega
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-21 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: nokogiri
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.13'
|
69
|
+
description: |-
|
70
|
+
Selenium-Grid doesn't have a pretty API so this gem is for parser the result of /grid/console to know
|
71
|
+
which nodes are free to use them when running your tests
|
72
|
+
email:
|
73
|
+
- juanjortcan@gmail.com
|
74
|
+
executables:
|
75
|
+
- console
|
76
|
+
- parse
|
77
|
+
extensions: []
|
78
|
+
extra_rdoc_files: []
|
79
|
+
files:
|
80
|
+
- ".gitignore"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/parse
|
88
|
+
- lib/nodes/client/grid_node_client.rb
|
89
|
+
- lib/nodes/configuration/capabilities.rb
|
90
|
+
- lib/nodes/configuration/node_configuration.rb
|
91
|
+
- lib/nodes/data/grid_node_data.rb
|
92
|
+
- lib/nodes/grid_node.rb
|
93
|
+
- lib/nodes/grid_node_set.rb
|
94
|
+
- lib/selenium_grid_console_parser.rb
|
95
|
+
- selenium-grid-parser.gemspec
|
96
|
+
homepage: ''
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.5.1
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Selenium-Grid doesn't have a pretty API so let parse it!
|
120
|
+
test_files: []
|