testingbot 0.1.5 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +26 -0
  3. data/.travis.yml +7 -3
  4. data/LICENSE +1 -1
  5. data/README.md +207 -0
  6. data/bin/testingbot +4 -3
  7. data/lib/testingbot.rb +1 -5
  8. data/lib/testingbot/api.rb +153 -35
  9. data/lib/testingbot/version.rb +1 -1
  10. data/spec/integration/api_spec.rb +38 -18
  11. data/spec/resources/test.apk +1 -0
  12. data/spec/spec_helper.rb +6 -3
  13. metadata +55 -94
  14. data/README.rdoc +0 -237
  15. data/examples/android.rb +0 -14
  16. data/examples/capybara.rb +0 -22
  17. data/examples/capybara_multiple_browsers.rb +0 -38
  18. data/examples/cucumber/README.rdoc +0 -15
  19. data/examples/cucumber/Rakefile +0 -20
  20. data/examples/cucumber/features/support/env.rb +0 -13
  21. data/examples/cucumber/features/youtube.feature +0 -10
  22. data/examples/cucumber/features/youtube_steps.rb +0 -15
  23. data/examples/test_rspec.rb +0 -17
  24. data/examples/test_rspec1.rb +0 -36
  25. data/examples/test_unit.rb +0 -30
  26. data/lib/testingbot/capybara.rb +0 -66
  27. data/lib/testingbot/config.rb +0 -125
  28. data/lib/testingbot/cucumber.rb +0 -35
  29. data/lib/testingbot/hooks.rb +0 -287
  30. data/lib/testingbot/jasmine.rb +0 -29
  31. data/lib/testingbot/jasmine/README.rdoc +0 -16
  32. data/lib/testingbot/jasmine/Rakefile +0 -35
  33. data/lib/testingbot/jasmine/public/javascripts/Player.js +0 -22
  34. data/lib/testingbot/jasmine/public/javascripts/Song.js +0 -7
  35. data/lib/testingbot/jasmine/runner.rb +0 -4
  36. data/lib/testingbot/jasmine/spec/javascripts/PlayerSpec.js +0 -58
  37. data/lib/testingbot/jasmine/spec/javascripts/helpers/SpecHelper.js +0 -9
  38. data/lib/testingbot/jasmine/spec/javascripts/support/jasmine.yml +0 -73
  39. data/lib/testingbot/jasmine/test/Rakefile +0 -9
  40. data/lib/testingbot/jasmine/test/public/javascripts/Player.js +0 -22
  41. data/lib/testingbot/jasmine/test/public/javascripts/Song.js +0 -7
  42. data/lib/testingbot/jasmine/test/spec/javascripts/PlayerSpec.js +0 -58
  43. data/lib/testingbot/jasmine/test/spec/javascripts/helpers/SpecHelper.js +0 -9
  44. data/lib/testingbot/jasmine/test/spec/javascripts/support/jasmine.yml +0 -73
  45. data/lib/testingbot/selenium.rb +0 -127
  46. data/lib/testingbot/tunnel.rb +0 -104
  47. data/spec/integration/selenium1_spec.rb +0 -53
  48. data/spec/integration/selenium2_spec.rb +0 -60
  49. data/spec/integration/tunnel_spec.rb +0 -84
  50. data/spec/unit/api_spec.rb +0 -17
  51. data/spec/unit/config_spec.rb +0 -73
  52. data/spec/unit/tunnel_spec.rb +0 -41
  53. data/testingbot.gemspec +0 -25
  54. data/vendor/Testingbot-Tunnel.jar +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6c1801b21d64a6515b1fd8d1f1a6db23b0915dff62121b49a681d02eff530c2a
4
+ data.tar.gz: 30edd8ebbc255bf2b14005e9c5ea881b5bfc1ef6a19a1e8b9a24ed2bc2584f59
5
+ SHA512:
6
+ metadata.gz: 50e9843ec66a235debde34b17f2a40ab05bc545fd175959d14497b5b23a133beb9155408d61363cf307d2463b1aeb23cad50d081d05ff6a40dd431b9b82c3119
7
+ data.tar.gz: e781af83c71eeb24d0d086e29b1ee1e0bce71263b260045e1d2acc656f7d55409a03991bde4802edfae33bf474648184e45755bb7324ac6c9bcb8b0c1c48fc03
@@ -0,0 +1,26 @@
1
+ name: Test Changes
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ ruby: [ '2.5', '2.6' ]
11
+ name: Ruby ${{ matrix.ruby }} test
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: Build and test
18
+ run: |
19
+ sudo apt-get -yqq install libpq-dev
20
+ gem install bundler
21
+ bundle install --jobs 3 --retry 3
22
+ bundle exec rake spec
23
+ env:
24
+ TB_KEY: ${{ secrets.TB_KEY }}
25
+ TB_SECRET: ${{ secrets.TB_SECRET }}
26
+
data/.travis.yml CHANGED
@@ -1,5 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- before_script: echo "travis:rocks" > ~/.testingbot
5
- script: bundle exec rspec -P "spec/unit/*.rb"
3
+ - 2.0.0
4
+ - 2.1.1
5
+ - 2.3
6
+ - 2.4
7
+ - 2.5
8
+ - 2.6
9
+ script: bundle exec rake spec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 TestingBot
1
+ Copyright (c) TestingBot
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy
4
4
  of this software and associated documentation files (the "Software"), to deal
data/README.md ADDED
@@ -0,0 +1,207 @@
1
+ [![Gem Version](https://badge.fury.io/rb/testingbot.svg)](https://badge.fury.io/rb/testingbot)
2
+
3
+ # Testingbot-Ruby
4
+
5
+ This is the TestingBot Ruby client which makes it easy to
6
+ interact with the [TestingBot API](https://testingbot.com/support/api)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'testingbot'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install testingbot
21
+
22
+
23
+ ## Configuration
24
+
25
+ You'll need a [TestingBot account](https://testingbot.com). TestingBot offers free trials.
26
+
27
+ ## Setup
28
+
29
+ Once you have a TestingBot account, you can retrieve your unique TestingBot Key and Secret from the [TestingBot dashboard](https://testingbot.com/members)
30
+
31
+ ## Usage
32
+
33
+ ```ruby
34
+ @api = TestingBot::Api.new(key, secret)
35
+ ```
36
+
37
+ #### Environment variables
38
+ You can set these environment variables to authenticate with our API:
39
+
40
+ ```bash
41
+ TB_KEY=Your TestingBot Key
42
+ TB_SECRET=Your TestingBot Secret
43
+ ```
44
+
45
+ ### get_browsers
46
+ Gets a list of browsers you can test on
47
+
48
+ ```ruby
49
+ @api.get_browsers
50
+ ```
51
+
52
+ ### get_devices
53
+ Gets a list of (physical) devices you can test on
54
+
55
+ ```ruby
56
+ @api.get_devices
57
+ ```
58
+
59
+ ### get_available_devices
60
+ Gets a list of available (physical) devices you can test on
61
+
62
+ ```ruby
63
+ @api.get_available_devices
64
+ ```
65
+
66
+ ### get_user_info
67
+ Gets your user information
68
+
69
+ ```ruby
70
+ @api.get_user_info
71
+ ```
72
+
73
+ ### update_user_info
74
+ Updates your user information
75
+
76
+ ```ruby
77
+ @api.update_user_info({ "first_name" => 'my name' })
78
+ ```
79
+
80
+ ### update_test
81
+ Updates a Test with Meta-data to display on TestingBot.
82
+ For example, you can specify the test name and whether the test succeeded or failed:
83
+
84
+ ```ruby
85
+ @api.update_test(webdriver_session_id, { :name => new_name, :success => true })
86
+ ```
87
+
88
+ ### get_test
89
+ Gets meta information for a test/job by passing in the WebDriver sessionID of the test you ran on TestingBot:
90
+
91
+ ```ruby
92
+ @api.get_test(webdriver_session_id)
93
+ ```
94
+
95
+ ### get_tests
96
+ Gets a list of previous jobs/tests that you ran on TestingBot, order by last run:
97
+
98
+ ```ruby
99
+ @api.get_tests(0, 10)
100
+ ```
101
+
102
+ ### delete_test
103
+ Deletes a test from TestingBot
104
+
105
+ ```ruby
106
+ @api.delete_test(webdriver_session_id)
107
+ ```
108
+
109
+ ### stop_test
110
+ Stops a running test on TestingBot
111
+
112
+ ```ruby
113
+ @api.stop_test(webdriver_session_id)
114
+ ```
115
+
116
+ ### get_builds
117
+ Gets a list of builds that you ran on TestingBot, order by last run:
118
+
119
+ ```ruby
120
+ @api.get_builds(0, 10)
121
+ ```
122
+
123
+ ### get_build
124
+ Gets a build from TestingBot
125
+
126
+ ```ruby
127
+ @api.get_build(build_identifier)
128
+ ```
129
+
130
+ ### delete_build
131
+ Deletes a build from TestingBot
132
+
133
+ ```ruby
134
+ @api.delete_build(build_identifier)
135
+ ```
136
+
137
+ ### get_tunnels
138
+ Gets a list of active tunnels for your account.
139
+
140
+ ```ruby
141
+ @api.get_tunnels
142
+ ```
143
+
144
+ ### delete_tunnel
145
+ Deletes an active tunnel.
146
+
147
+ ```ruby
148
+ @api.delete_tunnel(tunnel_identifier)
149
+ ```
150
+
151
+ ### upload_local_file
152
+ Uploads a local file (APK or IPA file) to TestingBot Storage for Mobile App Testing.
153
+
154
+ ```ruby
155
+ @api.upload_local_file(localFilePath)
156
+ ```
157
+
158
+ ### upload_remote_file
159
+ Uploads a remote file (APK or IPA URL) to TestingBot Storage for Mobile App Testing.
160
+
161
+ ```ruby
162
+ @api.upload_remote_file(remoteFileUrl)
163
+ ```
164
+
165
+ ### get_uploaded_files
166
+ Retrieves files previously uploaded TestingBot Storage for Mobile App Testing.
167
+
168
+ ```ruby
169
+ @api.get_uploaded_files(offset = 0, count = 30)
170
+ ```
171
+
172
+ ### get_uploaded_file
173
+ Retrieves meta-data for a file previously uploaded to TestingBot Storage.
174
+
175
+ ```ruby
176
+ @api.get_uploaded_file(app_url)
177
+ ```
178
+
179
+ ### delete_uploaded_file
180
+ Deletes a previously uploaded file
181
+
182
+ ```ruby
183
+ @api.delete_uploaded_file(remoteFileUrl)
184
+ ```
185
+
186
+ ### upload_remote_file
187
+ Uploads a remote file (APK or IPA URL) to TestingBot Storage for Mobile App Testing.
188
+
189
+ ```ruby
190
+ @api.upload_remote_file(remoteFileUrl)
191
+ ```
192
+
193
+ ### get_authentication_hash
194
+ Calculates the hash necessary to share tests with other people
195
+
196
+ ```ruby
197
+ @api.get_authentication_hash(identifier)
198
+ ```
199
+
200
+ ## Contributing
201
+
202
+ 1. Fork this repository
203
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
204
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
205
+ 4. Push to the branch (`git push origin my-new-feature`)
206
+ 5. Create new Pull Request
207
+
data/bin/testingbot CHANGED
@@ -4,8 +4,9 @@ if ARGV.any?
4
4
  api_key, api_secret = ARGV.first.split(':')
5
5
  else
6
6
 
7
- p "This utility will help you set up your system to use testingbot.com's infrastructure."
8
- p "Once you have entered your api key and secret you will be ready to use our grid"
7
+ p "This utility will help you set up your system to use TestingBot's infrastructure."
8
+ p "Once you have entered your API key and secret you will be ready to use our grid"
9
+ p "You can get these credentials from the TestingBot dashboard: https://testingbot.com/members"
9
10
 
10
11
  p "Please enter your testingbot API KEY:"
11
12
  api_key = gets.chomp
@@ -15,4 +16,4 @@ end
15
16
 
16
17
  File.open(File.expand_path("~/.testingbot"), 'w') {|f| f.write("#{api_key}:#{api_secret}") }
17
18
 
18
- p "Your system is now ready to use testingbot.com's grid infrastructure."
19
+ p "Your system is now ready to use TestingBot's grid infrastructure."
data/lib/testingbot.rb CHANGED
@@ -1,5 +1 @@
1
- require "testingbot/version"
2
- require "testingbot/config"
3
- require "testingbot/selenium"
4
- require "testingbot/api"
5
- require "testingbot/hooks"
1
+ require "testingbot/api"
@@ -1,4 +1,6 @@
1
1
  require 'json'
2
+ require "rest-client"
3
+
2
4
  module TestingBot
3
5
 
4
6
  class Api
@@ -6,16 +8,49 @@ module TestingBot
6
8
  VERSION = 1
7
9
  API_URL = "https://api.testingbot.com"
8
10
 
9
- attr_reader :config
11
+ attr_reader :key, :secret, :options
12
+
13
+ def initialize(key = nil, secret = nil, options = {})
14
+ @key = key
15
+ @secret = secret
16
+ @options = {
17
+ :debug => false
18
+ }.merge(options)
19
+ if @key.nil? || @secret.nil?
20
+ cached_credentials = load_config_file
21
+ @key, @secret = cached_credentials unless cached_credentials.nil?
22
+ end
23
+
24
+ if @key.nil? || @secret.nil?
25
+ @key = ENV["TESTINGBOT_KEY"] if ENV["TESTINGBOT_KEY"]
26
+ @secret = ENV["TESTINGBOT_SECRET"] if ENV["TESTINGBOT_SECRET"]
27
+ end
10
28
 
11
- def initialize(opts = {})
12
- @config = TestingBot::Config.new(opts)
29
+ if @key.nil? || @secret.nil?
30
+ @key = ENV["TB_KEY"] if ENV["TB_KEY"]
31
+ @secret = ENV["TB_SECRET"] if ENV["TB_SECRET"]
32
+ end
33
+
34
+ raise "Please supply a TestingBot Key" if @key.nil?
35
+ raise "Please supply a TestingBot Secret" if @secret.nil?
13
36
  end
14
37
 
15
38
  def get_user_info
16
39
  get("/user")
17
40
  end
18
41
 
42
+ def get_browsers
43
+ get("/browsers")
44
+ end
45
+
46
+ def get_devices
47
+ get("/devices")
48
+ end
49
+
50
+ def get_available_devices
51
+ get("/devices/available")
52
+ end
53
+
19
54
  def update_user_info(params = {})
20
55
  new_params = {}
21
56
  params.keys.each do |key|
@@ -29,7 +64,7 @@ module TestingBot
29
64
  get("/tests?offset=#{offset}&count=#{count}")
30
65
  end
31
66
 
32
- def get_single_test(test_id)
67
+ def get_test(test_id)
33
68
  get("/tests/#{test_id}")
34
69
  end
35
70
 
@@ -47,19 +82,104 @@ module TestingBot
47
82
  response["success"]
48
83
  end
49
84
 
85
+ def stop_test(test_id)
86
+ response = put("/tests/#{test_id}/stop")
87
+ response["success"]
88
+ end
89
+
90
+ def get_builds(offset = 0, count = 10)
91
+ get("/builds?offset=#{offset}&count=#{count}")
92
+ end
93
+
94
+ def get_build(build_identifier)
95
+ get("/builds/#{build_identifier}")
96
+ end
97
+
98
+ def delete_build(build_identifier)
99
+ delete("/builds/#{build_identifier}")
100
+ end
101
+
102
+ def get_tunnels
103
+ get("/tunnel/list")
104
+ end
105
+
106
+ def delete_tunnel(tunnel_identifier)
107
+ delete("/tunnel/#{tunnel_identifier}")
108
+ end
109
+
110
+ def get_authentication_hash(identifier)
111
+ Digest::MD5.hexdigest("#{@key}:#{@secret}:#{identifier}")
112
+ end
113
+
114
+ def upload_local_file(file_path)
115
+ response = RestClient::Request.execute(
116
+ method: :post,
117
+ url: API_URL + "/v1/storage",
118
+ user: @key,
119
+ password: @secret,
120
+ timeout: 600,
121
+ payload: {
122
+ multipart: true,
123
+ file: File.new(file_path, 'rb')
124
+ }
125
+ )
126
+ parsed = JSON.parse(response.body)
127
+ parsed
128
+ end
129
+
130
+ def upload_remote_file(url)
131
+ post("/storage/", {
132
+ :url => url
133
+ })
134
+ end
135
+
136
+ def get_uploaded_files(offset = 0, count = 10)
137
+ get("/storage?offset=#{offset}&count=#{count}")
138
+ end
139
+
140
+ def get_uploaded_file(app_url)
141
+ get("/storage/#{app_url.gsub(/tb:\/\//, '')}")
142
+ end
143
+
144
+ def delete_uploaded_file(app_url)
145
+ response = delete("/storage/#{app_url.gsub(/tb:\/\//, '')}")
146
+ response["success"]
147
+ end
148
+
50
149
  private
51
150
 
151
+ def load_config_file
152
+ is_windows = false
153
+
154
+ begin
155
+ require 'rbconfig'
156
+ is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)
157
+ rescue
158
+ is_windows = (RUBY_PLATFORM =~ /w.*32/) || (ENV["OS"] && ENV["OS"] == "Windows_NT")
159
+ end
160
+
161
+ if is_windows
162
+ config_file = "#{ENV['HOMEDRIVE']}\\.testingbot"
163
+ else
164
+ config_file = File.expand_path("#{Dir.home}/.testingbot")
165
+ end
166
+
167
+ if File.exists?(config_file)
168
+ str = File.open(config_file) { |f| f.readline }.chomp
169
+ return str.split(':')
170
+ end
171
+
172
+ return nil
173
+ end
174
+
52
175
  def get(url)
53
- uri = URI(API_URL + '/v' + VERSION.to_s + url)
54
- req = Net::HTTP::Get.new(uri.request_uri)
55
- req.basic_auth @config[:client_key], @config[:client_secret]
56
- res = Net::HTTP.start(uri.host, uri.port) {|http|
57
- http.request(req)
58
- }
176
+ uri = API_URL + '/v' + VERSION.to_s + url
59
177
 
60
- parsed = JSON.parse(res.body)
178
+ response = RestClient::Request.execute method: :get, url: uri, user: @key, password: @secret
179
+ parsed = JSON.parse(response.body)
61
180
 
62
- if !parsed["error"].nil? && !parsed["error"].empty?
181
+ p parsed if @options[:debug]
182
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
63
183
  raise parsed["error"]
64
184
  end
65
185
 
@@ -67,17 +187,13 @@ module TestingBot
67
187
  end
68
188
 
69
189
  def put(url, params = {})
70
- uri = URI(API_URL + '/v' + VERSION.to_s + url)
71
- req = Net::HTTP::Put.new(uri.request_uri)
72
- req.basic_auth @config[:client_key], @config[:client_secret]
73
- req.set_form_data(params)
74
- res = Net::HTTP.start(uri.host, uri.port) {|http|
75
- http.request(req)
76
- }
190
+ uri = API_URL + '/v' + VERSION.to_s + url
77
191
 
78
- parsed = JSON.parse(res.body)
192
+ response = RestClient::Request.execute method: :put, url: uri, payload: params, user: @key, password: @secret
193
+ parsed = JSON.parse(response.body)
79
194
 
80
- if !parsed["error"].nil? && !parsed["error"].empty?
195
+ p parsed if @options[:debug]
196
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
81
197
  raise parsed["error"]
82
198
  end
83
199
 
@@ -85,17 +201,12 @@ module TestingBot
85
201
  end
86
202
 
87
203
  def delete(url, params = {})
88
- uri = URI(API_URL + '/v' + VERSION.to_s + url)
89
- req = Net::HTTP::Delete.new(uri.request_uri)
90
- req.basic_auth @config[:client_key], @config[:client_secret]
91
- req.set_form_data(params)
92
- res = Net::HTTP.start(uri.host, uri.port) {|http|
93
- http.request(req)
94
- }
95
-
96
- parsed = JSON.parse(res.body)
204
+ uri = API_URL + '/v' + VERSION.to_s + url
205
+ response = RestClient::Request.execute method: :delete, url: uri, payload: params, user: @key, password: @secret
206
+ parsed = JSON.parse(response.body)
97
207
 
98
- if !parsed["error"].nil? && !parsed["error"].empty?
208
+ p parsed if @options[:debug]
209
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
99
210
  raise parsed["error"]
100
211
  end
101
212
 
@@ -103,10 +214,17 @@ module TestingBot
103
214
  end
104
215
 
105
216
  def post(url, params = {})
106
- url = URI.parse(API_URL + '/v' + VERSION + url)
107
- http = Net::HTTP.new(url.host, url.port)
108
- http.basic_auth @config[:client_key], @config[:client_secret]
109
- response = http.post(url.path, params.map { |k, v| "#{k.to_s}=#{v}" }.join("&"))
217
+ uri = API_URL + '/v' + VERSION.to_s + url
218
+
219
+ response = RestClient::Request.execute method: :post, url: uri, payload: params, user: @key, password: @secret
220
+ parsed = JSON.parse(response.body)
221
+
222
+ p parsed if @options[:debug]
223
+ if !parsed.is_a?(Array) && !parsed["error"].nil? && !parsed["error"].empty?
224
+ raise parsed["error"]
225
+ end
226
+
227
+ parsed
110
228
  end
111
229
  end
112
230
  end