cbthelper 0.0.1 → 1.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 +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +9 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +20 -0
- data/LICENSE.txt +21 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cbthelper.gemspec +29 -0
- data/lib/.DS_Store +0 -0
- data/lib/cbthelper.rb +39 -34
- data/lib/cbthelper/.DS_Store +0 -0
- data/lib/cbthelper/AutomatedTest.rb +41 -42
- data/lib/cbthelper/CapsBuilder.rb +26 -27
- data/lib/cbthelper/Snapshot.rb +16 -24
- data/lib/cbthelper/TestHistoryBuilder.rb +25 -38
- data/lib/cbthelper/Video.rb +17 -28
- data/lib/cbthelper/version.rb +3 -0
- metadata +51 -8
- data/lib/cbthelper/Globals.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 161f8104cb47450096f365dea539df6f962a6563bc8325b6150b5ce7d89481ea
|
4
|
+
data.tar.gz: 5d04fa37f9a50b45caf54f7a4bb90f4e8c8eafbd621bbc7ff2bcc0adaec6304e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '067458e98a2b601beac02fc495b234daa2463d103375570e8a90cb9dae467844614b94a29182f255818aa7f2a75cc9bb6bcd53927054d242779158796146a15c'
|
7
|
+
data.tar.gz: e3c5e0ae30ab7032ec4731c71af4c174aad0dbb016e8f1844da3ec93a0bc9d1524fbcbf61c9320eb0b0cb83beb1a998638a0fcb9be409f15cef27d416129cc97
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Daphne Magsby
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Cbthelper
|
2
|
+
|
3
|
+
|
4
|
+
cbthelper (Ruby) wraps CrossBrowserTesting's selenium api into an easy to use library.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'cbthelper'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install cbthelper
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
See example.rb. Don't forget to set your username and authkey in that file.
|
25
|
+
|
26
|
+
Or visit https://help.crossbrowsertesting.com/selenium-testing/getting-started/cbthelper-ruby/
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/crossbrowsertesting/cbthelper-ruby.
|
31
|
+
|
32
|
+
## License
|
33
|
+
|
34
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cbthelper"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/cbthelper.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "cbthelper/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cbthelper"
|
8
|
+
spec.version = Cbthelper::VERSION
|
9
|
+
spec.authors = ["Daphne Magsby"]
|
10
|
+
spec.email = ["daphnem@crossbrowsertesting.com"]
|
11
|
+
|
12
|
+
spec.summary = "cbthelper"
|
13
|
+
spec.description = "cbthelper wraps CrossBrowserTesting's (https://crossbrowsertesting.com/apidocs/v3/selenium.html) into an easy to use library."
|
14
|
+
spec.homepage = "https://help.crossbrowsertesting.com/selenium-testing/getting-started/cbthelper-ruby/"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/crossbrowsertesting/cbthelper-ruby"
|
19
|
+
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
29
|
+
end
|
data/lib/.DS_Store
ADDED
Binary file
|
data/lib/cbthelper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative "cbthelper/
|
1
|
+
require_relative "cbthelper/version"
|
2
2
|
require_relative "cbthelper/AutomatedTest"
|
3
3
|
require_relative "cbthelper/CapsBuilder"
|
4
4
|
require_relative "cbthelper/Snapshot"
|
@@ -6,43 +6,48 @@ require_relative "cbthelper/TestHistoryBuilder"
|
|
6
6
|
require_relative "cbthelper/Video"
|
7
7
|
require "rest-client"
|
8
8
|
require "json"
|
9
|
-
|
10
|
-
=begin
|
11
|
-
Used to get the selenium capability builder
|
12
|
-
Generating the CapsBuilder pulls in a large amount of data, so user should not call the constrcutor manually
|
13
|
-
=end
|
14
|
-
$CAPSBUILDER = CapsBuilder.new
|
15
|
-
return $CAPSBUILDER
|
16
|
-
end
|
9
|
+
require "selenium-webdriver"
|
17
10
|
|
11
|
+
module Cbthelper
|
12
|
+
#Used to get the selenium capability builder
|
13
|
+
#Generating the CapsBuilder pulls in a large amount of data, so user should not call the constrcutor manually
|
14
|
+
def self.getCapsBuilder
|
15
|
+
@@caps = CapsBuilder.new
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
#Sets the username and authkey used to make the HTTP requests
|
19
|
+
def self.login(username, authkey)
|
20
|
+
@@username= username
|
21
|
+
@@authkey = authkey
|
22
|
+
end
|
23
23
|
|
24
|
-
|
24
|
+
#Used to get the TestHistoryBuilder
|
25
|
+
#Can also just call the constructor. Method created to match getCapsBuilder()
|
26
|
+
def self.getTestHistoryBuilder
|
27
|
+
return TestHistoryBuilder.new
|
28
|
+
end
|
25
29
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
return TestHistoryBuilder.new
|
32
|
-
end
|
30
|
+
#Returns a ruby hash with the test history, filtering based on the options given.
|
31
|
+
#@param options: a ruby hash created by the TestHistoryBuilder
|
32
|
+
def self.getTestHistory(options)
|
33
|
+
return JSON.parse(RestClient.get("https://#{@@username}:#{@@authkey}@crossbrowsertesting.com/api/v3/selenium/", params: options))
|
34
|
+
end
|
33
35
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
#Creates an automated test from the selenium session id
|
37
|
+
#@param sessid: string for the seleneium session/test id. Should come from WebDriver
|
38
|
+
def self.getTestFromId(sessid)
|
39
|
+
return AutomatedTest.new(sessid)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.username
|
43
|
+
@@username
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.authkey
|
47
|
+
@@authkey
|
48
|
+
end
|
41
49
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
:param sessid: string for the seleneium session/test id. Should come from WebDriver
|
46
|
-
=end
|
47
|
-
return AutomatedTest.new(sessid)
|
50
|
+
def self.caps
|
51
|
+
@@caps
|
52
|
+
end
|
48
53
|
end
|
Binary file
|
@@ -1,67 +1,63 @@
|
|
1
|
-
require_relative "Globals"
|
2
1
|
require_relative "Snapshot"
|
3
2
|
require_relative "Video"
|
3
|
+
require_relative "../cbthelper.rb"
|
4
4
|
require "rest-client"
|
5
5
|
require "json"
|
6
6
|
|
7
|
+
#Helpful representation of a selenium test
|
7
8
|
class AutomatedTest
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
=end
|
9
|
+
|
10
|
+
|
11
|
+
#@param testId: the selenium session ID, usually from webdriver
|
13
12
|
def initialize(testId)
|
14
13
|
@testId = testId
|
15
14
|
end
|
16
15
|
|
16
|
+
#Sets the score for our test in the CBT app
|
17
|
+
#@param score: should be 'pass', 'fail', or 'unset'.
|
17
18
|
def setScore(score)
|
18
|
-
|
19
|
-
Sets the score for our test in the CBT app
|
20
|
-
:param score: should be 'pass', 'fail', or 'unset'. The main module exposes SCORE_PASS, SCORE_FAIL, SCORE_UNSET
|
21
|
-
=end
|
22
|
-
RestClient.put("https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3"+ "/selenium/#{@testId}",
|
19
|
+
RestClient.put("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}",
|
23
20
|
"action=set_score&score=#{score}")
|
24
21
|
end
|
25
22
|
|
23
|
+
#Sets the description for the test in the web app
|
26
24
|
def setDescription(description)
|
27
|
-
|
28
|
-
RestClient.put("https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3"+ "/selenium/#{@testId}",
|
25
|
+
RestClient.put("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}",
|
29
26
|
"action=set_description&description=#{description}")
|
30
27
|
end
|
31
28
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
if score != ""
|
29
|
+
|
30
|
+
#@param score is optional, will combine setScore and stopTest
|
31
|
+
#Sends the command to our api to stop the selenium test. Similar to driver.quit()
|
32
|
+
def stop(score = nil)
|
33
|
+
if score != nil
|
38
34
|
setScore(score)
|
39
|
-
RestClient.delete("https://#{
|
35
|
+
RestClient.delete("https://#{Cbthelper.username}:#{$Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}")
|
40
36
|
end
|
41
37
|
|
42
38
|
end
|
43
39
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
:
|
49
|
-
=
|
50
|
-
response = RestClient.post("https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3" + "/selenium/#{@testId}/snapshots",
|
40
|
+
#Sends the command to take a snapshot and returns a Snapshot instance
|
41
|
+
#@param description: (optional) shortcut for Snapshot.setDescription
|
42
|
+
def takeSnapshot(description= nil)
|
43
|
+
|
44
|
+
#@return : the Snapshot instance for this snapshot
|
45
|
+
response = RestClient.post("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots",
|
51
46
|
"selenium_test_id=#{@testId}")
|
52
47
|
hash = /(?<="hash": ")((\w|\d)*)/.match(response)[0]
|
53
48
|
snap = Snapshot.new(hash, @testId)
|
54
|
-
if description !=
|
49
|
+
if description != nil
|
55
50
|
snap.setDescription(description)
|
56
51
|
end
|
57
52
|
return snap
|
58
53
|
|
59
54
|
end
|
60
55
|
|
56
|
+
#Returns all snapshots for this test
|
61
57
|
def getSnapshots()
|
62
|
-
|
63
|
-
snaps = JSON.parse(RestClient.get("https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3/selenium/" + @testId +"/snapshots/"))
|
58
|
+
snaps = JSON.parse(RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots/"))
|
64
59
|
ret = []
|
60
|
+
|
65
61
|
for snap in snaps
|
66
62
|
ret.push(Snapshot.new(snap["hash"], @testId))
|
67
63
|
|
@@ -69,62 +65,65 @@ class AutomatedTest
|
|
69
65
|
return ret
|
70
66
|
end
|
71
67
|
|
68
|
+
#Downloads all snapshots for this test into the provided directory
|
72
69
|
def saveAllSnapshots(directory, useDescription=false)
|
73
|
-
#Downloads all snapshots for this test into the provided directory
|
74
70
|
prefix = "image"
|
75
71
|
snaps = getSnapshots
|
76
72
|
makeDirectory(directory)
|
73
|
+
|
77
74
|
for i in 0...snaps.size
|
78
75
|
if useDescription and snaps[i].info["description"] != ""
|
79
76
|
img = snaps[i].info["description"] + ".png"
|
80
77
|
else
|
81
78
|
img = prefix + i.to_s + ".png"
|
82
79
|
end
|
83
|
-
snaps[i].
|
80
|
+
snaps[i].saveSnapshot(File.join(directory, img))
|
84
81
|
end
|
85
|
-
|
86
82
|
end
|
87
83
|
|
88
|
-
|
89
|
-
|
90
|
-
response = RestClient.get("https://#{
|
84
|
+
#Return the video recording for this test
|
85
|
+
def RecordingVideo(description=nil)
|
86
|
+
response = RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos")
|
91
87
|
hash = /(?<="hash": ")((\w|\d)*)/.match(response)[0]
|
92
88
|
video = Video.new(hash, @testId)
|
93
|
-
if description !=
|
89
|
+
if description != nil
|
94
90
|
video.setDescription(description)
|
95
91
|
end
|
96
92
|
return video
|
97
93
|
|
98
94
|
end
|
99
95
|
|
96
|
+
#Returns all videos for this test
|
100
97
|
def getVideos
|
101
|
-
|
102
|
-
videos = JSON.parse(RestClient.get("https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3/selenium/" + @testId +"/videos/"))
|
98
|
+
videos = JSON.parse(RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos/"))
|
103
99
|
ret = []
|
100
|
+
|
104
101
|
for video in videos
|
105
102
|
ret.push(Video.new(video["hash"], @testId))
|
106
103
|
|
107
104
|
end
|
105
|
+
|
108
106
|
return ret
|
109
107
|
end
|
110
108
|
|
109
|
+
#Downloads all videos for this test into a directory
|
111
110
|
def saveAllVideos(directory, useDescription=false)
|
112
|
-
# Downloads all videos for this test into a directory
|
113
111
|
prefix = "video"
|
114
112
|
videos = getVideos
|
115
113
|
makeDirectory(directory)
|
114
|
+
|
116
115
|
for i in 0...videos.size
|
117
116
|
if useDescription and videos[i].info["description"] != ""
|
118
117
|
vid = videos[i].info["description"] + ".mp4"
|
119
118
|
else
|
120
119
|
vid = prefix + i.to_s + ".mp4"
|
121
120
|
end
|
122
|
-
videos[i].
|
121
|
+
videos[i].saveVideo(File.join(directory, vid))
|
123
122
|
end
|
124
123
|
|
125
124
|
end
|
126
125
|
|
127
|
-
|
126
|
+
private
|
128
127
|
def makeDirectory(dir)
|
129
128
|
Dir.mkdir(dir) unless Dir.exist?(dir)
|
130
129
|
|
@@ -1,12 +1,13 @@
|
|
1
|
+
require_relative "../cbthelper.rb"
|
1
2
|
require "rest-client"
|
2
3
|
require "json"
|
3
|
-
require_relative "Globals"
|
4
4
|
|
5
|
+
|
6
|
+
#Builder for generating selenium capabilities
|
7
|
+
#All of the with... methods return self for method chaining
|
5
8
|
class CapsBuilder
|
6
|
-
|
7
|
-
|
8
|
-
All of the with... methods return self for method chaining
|
9
|
-
=end
|
9
|
+
|
10
|
+
|
10
11
|
def initialize
|
11
12
|
@capsData = JSON.parse(RestClient.get("https://crossbrowsertesting.com/api/v3/selenium/browsers"))
|
12
13
|
@platform = nil
|
@@ -19,66 +20,62 @@ class CapsBuilder
|
|
19
20
|
@recordNetwork = nil
|
20
21
|
end
|
21
22
|
|
23
|
+
#Sets the platform (OS) the user wants to use. The string will be compared against the 'name' and 'api_name' properties returned from the selenium api.
|
24
|
+
#@param platform: a string specifying the platform (eg. Windows 7, Mac 10.13)
|
22
25
|
def withPlatform(platform)
|
23
|
-
=begin
|
24
|
-
|
25
|
-
Sets the platform (OS) the user wants to use. The string will be compared against the 'name' and 'api_name' properties returned from the selenium api.
|
26
|
-
:param platform: a string specifying the platform (eg. Windows 7, Mac 10.13)
|
27
|
-
=end
|
28
26
|
@platform = platform
|
29
27
|
self
|
30
28
|
end
|
31
29
|
|
30
|
+
#Sets the browser the user wants to use. The string will be compared against the 'name' and 'api_name' properties returned from the selenium api.
|
31
|
+
#@param browser: as string specifying the browser (eg. Edge 17, Chrome 55x64)
|
32
32
|
def withBrowserApiName(browser)
|
33
|
-
=begin
|
34
|
-
Sets the browser the user wants to use. The string will be compared against the 'name' and 'api_name' properties returned from the selenium api.
|
35
|
-
:param browser: as string specifying the browser (eg. Edge 17, Chrome 55x64)
|
36
|
-
=end
|
37
33
|
@browser = browser
|
38
34
|
self
|
39
35
|
end
|
40
|
-
|
36
|
+
|
37
|
+
#Sets the screen size for the test
|
41
38
|
def withResolution(width, height)
|
42
|
-
# Sets the screen size for the test
|
43
39
|
@width = width
|
44
40
|
@height = height
|
45
41
|
self
|
46
42
|
end
|
47
43
|
|
44
|
+
#Sets the name of the test in the web app
|
48
45
|
def withName(name)
|
49
|
-
# Sets the name of the test in the web app
|
50
46
|
@name = name
|
51
47
|
self
|
52
48
|
end
|
53
49
|
|
50
|
+
#Sets the build number in the web app
|
54
51
|
def withBuild(build)
|
55
|
-
#Sets the build number in the web app
|
56
52
|
@version = build
|
57
53
|
self
|
58
54
|
end
|
59
55
|
|
56
|
+
#Records a video for the length of the test
|
60
57
|
def withRecordVideo(bool)
|
61
|
-
#Records a video for the length of the test
|
62
58
|
@recordVideo = bool
|
63
59
|
self
|
64
60
|
end
|
65
61
|
|
62
|
+
#Records network traffic for the length of the test
|
66
63
|
def withRecordNetwork(bool)
|
67
|
-
#Records network traffic for the length of the test
|
68
64
|
@recordNetwork = bool
|
69
65
|
self
|
70
66
|
end
|
71
67
|
|
68
|
+
#Used to generate the capabilites using any options the user specifies
|
72
69
|
def build
|
73
|
-
#Used to generate the capabilites using any options the user specifies
|
74
70
|
return choose
|
75
71
|
end
|
76
72
|
|
73
|
+
#Determines the best platform based on user input :param target
|
77
74
|
def bestOption(options, target)
|
78
|
-
#Determines the best platform based on user input :param target
|
79
75
|
if target != nil
|
80
76
|
target =target.downcase
|
81
77
|
end
|
78
|
+
|
82
79
|
for option in options
|
83
80
|
name = option['name'].downcase
|
84
81
|
apiName = option['name'].downcase
|
@@ -89,9 +86,10 @@ class CapsBuilder
|
|
89
86
|
return nil
|
90
87
|
end
|
91
88
|
|
89
|
+
#Determines the best platform based on user input :param target when no platform provided
|
92
90
|
def bestBrowserNoPlatform(target)
|
93
|
-
#Determines the best platform based on user input :param target when no platform provided
|
94
91
|
target = target.downcase
|
92
|
+
|
95
93
|
for platform in @capsData
|
96
94
|
for browser in platform['browsers']
|
97
95
|
name = browser['name'].downcase
|
@@ -100,11 +98,13 @@ class CapsBuilder
|
|
100
98
|
end
|
101
99
|
end
|
102
100
|
end
|
101
|
+
|
103
102
|
return nil
|
104
103
|
end
|
105
104
|
|
105
|
+
private
|
106
|
+
#Sets the capabilities passed to the WebDriver
|
106
107
|
def choose
|
107
|
-
#Sets the capabilities passed to the WebDriver
|
108
108
|
data = @capsData
|
109
109
|
caps = Selenium::WebDriver::Remote::Capabilities.new
|
110
110
|
if @platform
|
@@ -113,6 +113,7 @@ class CapsBuilder
|
|
113
113
|
if @browser
|
114
114
|
caps['browser_api_name'] = @browser
|
115
115
|
end
|
116
|
+
|
116
117
|
if @width and @height
|
117
118
|
caps['screenResolution'] = @width.to_s + 'x' + @height.to_s
|
118
119
|
end
|
@@ -136,6 +137,4 @@ class CapsBuilder
|
|
136
137
|
end
|
137
138
|
|
138
139
|
|
139
|
-
|
140
|
-
|
141
|
-
end
|
140
|
+
end
|
data/lib/cbthelper/Snapshot.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "../cbthelper.rb"
|
2
2
|
require "json"
|
3
3
|
require "rest-client"
|
4
4
|
|
5
|
+
#Represents a snapshot for selenium tests
|
5
6
|
class Snapshot
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
=end
|
7
|
+
|
8
|
+
|
9
|
+
#@param hash: the hash for this image, returned by rest api when taking a screenshot
|
10
|
+
#@param test: an AutomatedTest object that represents a test currently running
|
11
11
|
attr_accessor :info
|
12
12
|
def initialize(hash, test)
|
13
13
|
@hash = hash
|
@@ -15,35 +15,27 @@ class Snapshot
|
|
15
15
|
getInfo
|
16
16
|
end
|
17
17
|
|
18
|
+
#Calls out to api to get updated info for this snapshot
|
19
|
+
#@return : a hash object with all of the info for this Snapshot
|
18
20
|
def getInfo
|
19
|
-
=
|
20
|
-
Calls out to api to get updated info for this snapshot
|
21
|
-
:returns: a hash object with all of the info for this Snapshot
|
22
|
-
|
23
|
-
=end
|
24
|
-
@info = JSON.parse(RestClient.get("https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3/selenium/" + @testId +"/snapshots/"+ @hash))
|
25
|
-
return @info
|
21
|
+
@info = JSON.parse(RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots/#{@hash}"))
|
26
22
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
url = "https://#{
|
23
|
+
|
24
|
+
#Sets the description for this snapshot
|
25
|
+
def setDescription(description)
|
26
|
+
url = "https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/snapshots/#{@hash}"
|
31
27
|
@info = RestClient.put(url, "description=#{description}")
|
32
28
|
|
33
29
|
end
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
#:param location: a string with the location and filename for the image. Should have a .png extension
|
38
|
-
saveSnapshot(location)
|
39
|
-
end
|
40
|
-
|
31
|
+
#Downloads the snapshot to the given location
|
32
|
+
#@param location: a string with the location and filename for the image. Should have a .png extension
|
41
33
|
def saveSnapshot(location)
|
42
34
|
url = getInfo["image"]
|
43
35
|
path = File.split(location)[0]
|
44
36
|
Dir.mkdir(path) unless Dir.exist?(path)
|
45
37
|
|
46
|
-
#
|
38
|
+
#downloads the image to the given location in chunks
|
47
39
|
File.open(location, "wb") {|f|
|
48
40
|
block = proc { |response|
|
49
41
|
response.read_body do |chunk|
|
@@ -1,93 +1,82 @@
|
|
1
|
+
#Builder to generate options for getting test history
|
2
|
+
#All of the with... methods return self for method chaining
|
3
|
+
|
1
4
|
class TestHistoryBuilder
|
2
|
-
|
3
|
-
|
4
|
-
All of the with... methods return self for method chaining
|
5
|
-
=end
|
5
|
+
|
6
|
+
|
6
7
|
def initialize
|
7
8
|
@options = {}
|
8
9
|
end
|
9
10
|
|
11
|
+
#Sets the max number of tests to return
|
10
12
|
def withLimit(limit)
|
11
|
-
# Sets the max number of tests to return
|
12
13
|
@options["num"] = limit
|
13
14
|
self
|
14
15
|
end
|
15
16
|
|
17
|
+
#If set, will only return active or inactive tests
|
18
|
+
#@param active: boolean value
|
16
19
|
def withActive(active)
|
17
|
-
=begin
|
18
|
-
If set, will only return active or inactive tests
|
19
|
-
:param active: boolean value
|
20
|
-
=end
|
21
20
|
@options["active"] = active
|
22
21
|
self
|
23
22
|
end
|
24
23
|
|
24
|
+
#Will only return tests that match the name given
|
25
25
|
def withName(name)
|
26
|
-
# Will only return tests that match the name given
|
27
26
|
@options["name"] = name
|
28
27
|
self
|
29
28
|
end
|
30
29
|
|
30
|
+
# Will only return tests that match the build given
|
31
31
|
def withBuild(build)
|
32
|
-
# Will only return tests that match the build given
|
33
32
|
@options["build"] = build
|
34
33
|
self
|
35
34
|
end
|
36
35
|
|
36
|
+
#Will only return tests that navigate to the same url
|
37
37
|
def withUrl(url)
|
38
|
-
# Will only return tests that navigate to the same url
|
39
38
|
@options["url"] = url
|
40
39
|
self
|
41
40
|
end
|
42
41
|
|
42
|
+
#Will only return tests with the score specified ('pass', 'fail', 'unset')
|
43
43
|
def withScore(score)
|
44
|
-
#Will only return tests with the score specified ('pass', 'fail', 'unset')
|
45
44
|
@options["score"] = score
|
46
45
|
self
|
47
46
|
end
|
48
47
|
|
48
|
+
#Will only return tests with the same platform (OS)
|
49
|
+
#@param platform: string with the platform (eg. 'Windows 10', 'Mac OS 10.13')
|
49
50
|
def withPlatform(platform)
|
50
|
-
=begin
|
51
|
-
Will only return tests with the same platform (OS)
|
52
|
-
:param platform: string with the platform (eg. 'Windows 10', 'Mac OS 10.13')
|
53
|
-
=end
|
54
51
|
@options["platform"] = platform
|
55
52
|
self
|
56
53
|
end
|
57
54
|
|
55
|
+
#Will only return tests with the same platformType (OS Family)
|
56
|
+
#@param platformType: string with the platform type (eg. 'Windows', 'Mac', 'Android')
|
58
57
|
def withPlatformType(platformType)
|
59
|
-
=begin
|
60
|
-
Will only return tests with the same platformType (OS Family)
|
61
|
-
:param platformType: string with the platform type (eg. 'Windows', 'Mac', 'Android')
|
62
|
-
=end
|
63
58
|
@options["platformType"] = platformType
|
64
59
|
self
|
65
60
|
end
|
66
61
|
|
62
|
+
#Will only return tests that used the same browser
|
63
|
+
#@param browser: a string with the browser name and version: (eg. Chrome 65)
|
67
64
|
def withBrowser(browser)
|
68
|
-
=begin
|
69
|
-
Will only return tests that used the same browser
|
70
|
-
:param browser: a string with the browser name and version: (eg. Chrome 65)
|
71
|
-
=end
|
72
65
|
@options["browser"] = browser
|
73
66
|
self
|
74
67
|
end
|
75
68
|
|
69
|
+
#Will only return tests that used the same browser type
|
70
|
+
#@param browserType: a string representing the browser family (eg. 'Chrome', 'Edge', 'Safari')
|
71
|
+
|
76
72
|
def withBrowserType(browserType)
|
77
|
-
=begin
|
78
|
-
Will only return tests that used the same browser type
|
79
|
-
:param browserType: a string representing the browser family (eg. 'Chrome', 'Edge', 'Safari')
|
80
|
-
=end
|
81
73
|
@options["browserType"] = browserType
|
82
74
|
self
|
83
75
|
end
|
84
76
|
|
77
|
+
#Will only return tests that used the same resolution
|
78
|
+
#@param resolution: a string with the form 'WIDTHxHEIGHT' (eg. '1024x768')
|
85
79
|
def withResolution(resolution)
|
86
|
-
=begin
|
87
|
-
Will only return tests that used the same resolution
|
88
|
-
:param resolution: a string with the form 'WIDTHxHEIGHT' (eg. '1024x768')
|
89
|
-
|
90
|
-
=end
|
91
80
|
@options["resolution"]= resolution
|
92
81
|
self
|
93
82
|
end
|
@@ -102,11 +91,9 @@ class TestHistoryBuilder
|
|
102
91
|
self
|
103
92
|
end
|
104
93
|
|
94
|
+
#Generates the test history options
|
95
|
+
#@return : a ruby hash to pass to getTestHistory()
|
105
96
|
def build
|
106
|
-
=begin
|
107
|
-
Generates the test history options
|
108
|
-
:returns: a ruby hash to pass to getTestHistory()
|
109
|
-
=end
|
110
97
|
return @options
|
111
98
|
end
|
112
99
|
|
data/lib/cbthelper/Video.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
require_relative "
|
1
|
+
require_relative "../cbthelper.rb"
|
2
2
|
require "json"
|
3
3
|
require "rest-client"
|
4
4
|
|
5
|
+
#Represents a video recording for a selenium test
|
5
6
|
class Video
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
=end
|
11
|
-
|
7
|
+
|
8
|
+
|
9
|
+
#@param hash: the hash for this video, returned by rest api when starting a recording
|
10
|
+
#@param test: an AutomatedTest object that represents a test currently running
|
12
11
|
attr_accessor :info
|
13
12
|
def initialize(hash, test)
|
14
13
|
@hash = hash
|
@@ -17,44 +16,34 @@ class Video
|
|
17
16
|
|
18
17
|
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
=end
|
25
|
-
@info = JSON.parse(RestClient.get("https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3/selenium/" + @testId +"/videos/"+ @hash))
|
26
|
-
return @info
|
27
|
-
|
19
|
+
#Calls out to api to get updated info for this video
|
20
|
+
#@return : a hash object with all of the info for this video
|
21
|
+
def getInfo
|
22
|
+
@info = JSON.parse(RestClient.get("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos/#{@hash}"))
|
28
23
|
end
|
29
24
|
|
30
25
|
def stopRecording
|
31
|
-
#
|
32
|
-
RestClient.delete("https://#{
|
26
|
+
#Sends the command to stop a video recording
|
27
|
+
RestClient.delete("https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos/#{@hash}")
|
33
28
|
|
34
29
|
end
|
35
30
|
|
31
|
+
#Sets the description for this video
|
36
32
|
def setDescription(description)
|
37
|
-
|
38
|
-
url = "https://#{$USERNAME}:#{$AUTHKEY}@crossbrowsertesting.com/api/v3/selenium/" + @testId + "/videos/" + @hash
|
33
|
+
url = "https://#{Cbthelper.username}:#{Cbthelper.authkey}@crossbrowsertesting.com/api/v3/selenium/#{@testId}/videos/#{@hash}"
|
39
34
|
@info = RestClient.put(url, "description=#{description}")
|
40
35
|
|
41
36
|
end
|
42
37
|
|
43
|
-
|
44
|
-
#:param location: a string with the location and filename for the video. Should have a .mp4 extension
|
45
|
-
saveVideo(location)
|
46
|
-
end
|
38
|
+
#@param location: a string with the location and filename for the video. Should have a .mp4 extension
|
47
39
|
def saveVideo(location)
|
48
40
|
url = getInfo["video"]
|
49
|
-
|
50
|
-
stopRecording
|
51
|
-
end
|
41
|
+
stopRecording unless info["is_finished"]
|
52
42
|
|
53
|
-
#
|
54
43
|
path = File.split(location)[0]
|
55
44
|
Dir.mkdir(path) unless Dir.exist?(path)
|
56
45
|
|
57
|
-
#
|
46
|
+
#downloads the video to the given location in chunks
|
58
47
|
File.open(location, "wb") {|f|
|
59
48
|
block = proc { |response|
|
60
49
|
response.read_body do |chunk|
|
metadata
CHANGED
@@ -1,33 +1,76 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cbthelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daphne Magsby
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
12
|
-
dependencies:
|
11
|
+
date: 2018-11-05 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
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'
|
13
41
|
description: cbthelper wraps CrossBrowserTesting's (https://crossbrowsertesting.com/apidocs/v3/selenium.html)
|
14
42
|
into an easy to use library.
|
15
|
-
email:
|
43
|
+
email:
|
44
|
+
- daphnem@crossbrowsertesting.com
|
16
45
|
executables: []
|
17
46
|
extensions: []
|
18
47
|
extra_rdoc_files: []
|
19
48
|
files:
|
49
|
+
- ".DS_Store"
|
50
|
+
- ".gitignore"
|
51
|
+
- Gemfile
|
52
|
+
- Gemfile.lock
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- cbthelper.gemspec
|
59
|
+
- lib/.DS_Store
|
20
60
|
- lib/cbthelper.rb
|
61
|
+
- lib/cbthelper/.DS_Store
|
21
62
|
- lib/cbthelper/AutomatedTest.rb
|
22
63
|
- lib/cbthelper/CapsBuilder.rb
|
23
|
-
- lib/cbthelper/Globals.rb
|
24
64
|
- lib/cbthelper/Snapshot.rb
|
25
65
|
- lib/cbthelper/TestHistoryBuilder.rb
|
26
66
|
- lib/cbthelper/Video.rb
|
27
|
-
|
67
|
+
- lib/cbthelper/version.rb
|
68
|
+
homepage: https://help.crossbrowsertesting.com/selenium-testing/getting-started/cbthelper-ruby/
|
28
69
|
licenses:
|
29
70
|
- MIT
|
30
|
-
metadata:
|
71
|
+
metadata:
|
72
|
+
homepage_uri: https://help.crossbrowsertesting.com/selenium-testing/getting-started/cbthelper-ruby/
|
73
|
+
source_code_uri: https://github.com/crossbrowsertesting/cbthelper-ruby
|
31
74
|
post_install_message:
|
32
75
|
rdoc_options: []
|
33
76
|
require_paths:
|