rainforest_ruby_runtime 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +35 -0
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -6
- data/README.md +142 -2
- data/Rakefile +26 -5
- data/bin/rainforest_test +47 -2
- data/lib/rainforest_ruby_runtime.rb +4 -5
- data/lib/rainforest_ruby_runtime/drivers/sauce.rb +22 -11
- data/lib/rainforest_ruby_runtime/drivers/selenium.rb +34 -4
- data/lib/rainforest_ruby_runtime/dsl.rb +16 -2
- data/lib/rainforest_ruby_runtime/runner.rb +39 -67
- data/lib/rainforest_ruby_runtime/test.rb +1 -18
- data/lib/rainforest_ruby_runtime/variables/{registery.rb → registry.rb} +6 -6
- data/lib/rainforest_ruby_runtime/variables/scope.rb +1 -1
- data/lib/rainforest_ruby_runtime/version.rb +1 -1
- data/rainforest_ruby_runtime.gemspec +16 -5
- data/sample_tests/empty.rb +1 -1
- data/spec/rainforest_test_spec.rb +89 -0
- data/spec/runner_spec.rb +132 -0
- data/spec/spec_helper.rb +20 -0
- metadata +74 -26
- data/.travis.yml +0 -12
- data/lib/rainforest_ruby_runtime/drivers/browser_stack.rb +0 -42
- data/lib/rainforest_ruby_runtime/drivers/testing_bot.rb +0 -34
- data/test/runner_test.rb +0 -212
- data/test/test_helper.rb +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1504bf22a8dea19e857d7b408594412e1151a9ab
|
4
|
+
data.tar.gz: cfabcb8af8b10d8588fa570e61c1f725ae8b64aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 645ff7563f78bbd339f732588e2507af95c2b14389d0ab88a143491aaf652e6200770ea92163526d4b7cac92ecb7f4169fa170e0f308ec77c9bb03dad4c588b2
|
7
|
+
data.tar.gz: f5ef4ce3ad10defe54167650b16b95616ee355a929d45b3dc5317215923da9b58943647b9e34a17609134886a25b0bb47cc12127408415e79a4c7fe5b7d13563
|
@@ -0,0 +1,35 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
test:
|
4
|
+
docker:
|
5
|
+
- image: circleci/ruby:2.4.4
|
6
|
+
environment:
|
7
|
+
RUNTIME_ENV: test
|
8
|
+
steps:
|
9
|
+
- checkout
|
10
|
+
- run:
|
11
|
+
name: Install Ruby gems
|
12
|
+
command: |
|
13
|
+
bundle check --path=vendor/bundle || bundle install --path=vendor/bundle --jobs=4 --retry=3
|
14
|
+
- run:
|
15
|
+
name: Set up test output directory
|
16
|
+
command: sudo install -o circleci -d ~/rspec
|
17
|
+
- run:
|
18
|
+
name: RSpec
|
19
|
+
command: |
|
20
|
+
bundle exec rspec \
|
21
|
+
--color \
|
22
|
+
--require spec_helper \
|
23
|
+
--format documentation \
|
24
|
+
--format RspecJunitFormatter \
|
25
|
+
--out ~/rspec/rspec.xml \
|
26
|
+
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings --timings-type=filename)
|
27
|
+
- store_artifacts:
|
28
|
+
path: ~/rspec
|
29
|
+
- store_test_results:
|
30
|
+
path: ~/rspec
|
31
|
+
workflows:
|
32
|
+
version: 2
|
33
|
+
test_build:
|
34
|
+
jobs:
|
35
|
+
- test
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.4
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# 0.1.0 - 2018-04-13
|
2
|
+
|
3
|
+
- Support multiple browsers with `--browsers` param
|
4
|
+
- Change default browser to `chrome` (used to be `firefox`)
|
5
|
+
- Support running multiple scripts at once
|
6
|
+
- Use RSpec for running scripts and displaying results
|
7
|
+
- Remove support for BrowserStack and TestingBot
|
8
|
+
- Remove support for IE 8, 9, and 10 on SauceLabs
|
9
|
+
- Update browser versions on SauceLabs, add Microsoft Edge
|
10
|
+
- Add changelog
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Rainforest Ruby Runtime
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![CircleCI](https://circleci.com/gh/rainforestapp/rainforest_ruby_runtime/tree/master.svg?style=svg)](https://circleci.com/gh/rainforestapp/rainforest_ruby_runtime/tree/master)
|
4
4
|
|
5
5
|
Gem to run Rainforest Automated Tests locally or on Sauce Labs.
|
6
6
|
|
@@ -18,15 +18,155 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install rainforest_ruby_runtime
|
20
20
|
|
21
|
+
### Installing from source
|
22
|
+
|
23
|
+
$ git clone git@github.com:rainforestapp/rainforest_ruby_runtime.git
|
24
|
+
$ gem build
|
25
|
+
$ gem install
|
26
|
+
|
21
27
|
## Usage
|
22
28
|
|
29
|
+
To run the tests on Sauce Labs, first run `rainforest_test --prepare-sauce`, and then set the following environment variables:
|
30
|
+
|
31
|
+
- `CAPYBARA_DRIVER=sauce`
|
32
|
+
- `SAUCE_USERNAME=<your username>`
|
33
|
+
- `SAUCE_ACCESS_KEY=<your access key>`
|
34
|
+
|
23
35
|
You can then run the tests using the following command:
|
24
36
|
```
|
25
37
|
bundle exec rainforest_test <test-file.rb>
|
26
38
|
```
|
27
39
|
|
28
|
-
|
40
|
+
Rainforest Ruby Runtime supports test runs on Sauce Labs against Chrome, Firefox, IE, Edge, and Safari.
|
41
|
+
|
42
|
+
By default, your tests will run against Chrome. You can run one or more test scripts against multiple browsers with the following configuration:
|
43
|
+
|
44
|
+
```
|
45
|
+
bundle exec rainforest_test --browsers firefox,chrome,edge <test-file.rb>,<test-file1.rb>
|
46
|
+
```
|
47
|
+
## Validate failed test results on Rainforest
|
48
|
+
|
49
|
+
To run the associated Rainforest tests for any failed Selenium tests, follow these steps:
|
50
|
+
|
51
|
+
*Step 1:* Download your test scripts from Rainforest, then run your automated tests on Sauce labs per the instructions above
|
52
|
+
|
53
|
+
*Step 2:* Determine the number of results you need to return with the following calculation:
|
54
|
+
|
55
|
+
```
|
56
|
+
limit = number of scripts run * number of browsers selected
|
57
|
+
```
|
58
|
+
|
59
|
+
*Step 3:* Request the results from your last test run
|
60
|
+
|
61
|
+
You can find detailed instructions for making requests to Sauce Labs [here](https://wiki.saucelabs.com/display/DOCS/Job+Methods)
|
62
|
+
|
63
|
+
> NOTE: It's very important that no other users are executing tests concurrently. Your limit calculation may not include the proper results if other users are running tests at the same time.
|
64
|
+
|
65
|
+
Sample Response:
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
[
|
69
|
+
{
|
70
|
+
"browser_short_version"=>"35",
|
71
|
+
"video_url"=>"https://saucelabs.com/jobs/1234567890/video.flv",
|
72
|
+
"creation_time"=>12345678890,
|
73
|
+
"custom-data"=>nil,
|
74
|
+
"browser_version"=>"35.0.1916.114.",
|
75
|
+
"owner"=>"YOURUSERNAME",
|
76
|
+
"id"=>"12a34e56i78o90u",
|
77
|
+
"record_screenshots"=>true,
|
78
|
+
"record_video"=>true,
|
79
|
+
"build"=>nil,
|
80
|
+
"passed"=>false,
|
81
|
+
"public"=>"team",
|
82
|
+
"end_time"=>12345678900,
|
83
|
+
"status"=>"complete",
|
84
|
+
"log_url"=>"https://saucelabs.com/jobs/1234567890/selenium-server.log",
|
85
|
+
"start_time"=>1234567890,
|
86
|
+
"proxied"=>true,
|
87
|
+
"modification_time"=>12345678900,
|
88
|
+
"tags"=>[],
|
89
|
+
"name"=>"Rainforest [1]",
|
90
|
+
"commands_not_successful"=>1,
|
91
|
+
"consolidated_status"=>"failed",
|
92
|
+
"assigned_tunnel_id"=>"tunn1234567890ellll",
|
93
|
+
"error"=>nil,
|
94
|
+
"os"=>"Windows 2008",
|
95
|
+
"breakpointed"=>nil,
|
96
|
+
"browser"=>"googlechrome"
|
97
|
+
}
|
98
|
+
]
|
99
|
+
```
|
100
|
+
|
101
|
+
Filter your response array to include only failed results; `"passed" => false`.
|
102
|
+
|
103
|
+
*Step 4:* Extract required properties to re-run tests on Rainforest
|
104
|
+
|
105
|
+
The response for each result will include the browser, and the test ID, as the number within brackets in the `name` value.
|
106
|
+
Extract test information from the filtered results object:
|
107
|
+
|
108
|
+
Example results hash:
|
109
|
+
```
|
110
|
+
{"123"=>["ie11_1440_900", "windows10_edge"]}
|
111
|
+
```
|
112
|
+
|
113
|
+
*Step 5:* Run tests in Rainforest to verify the failed tests
|
114
|
+
|
115
|
+
Use Rainforest's CLI to Rainforest tests by ID against the failed broswers.
|
116
|
+
|
117
|
+
Example script to help you write yours:
|
29
118
|
|
119
|
+
```ruby
|
120
|
+
# Run your Rainforest scripts against Sauce Labs
|
121
|
+
bundle exec rainforest_test <test-file.rb>,<test-file1.rb>,<test-file2.rb> --browsers firefox,chrome,edge
|
122
|
+
|
123
|
+
# Calculate results limit, set environment info
|
124
|
+
limit = <automation script count> * <browser count> # replace placeholders with values for each run
|
125
|
+
username = ENV['SAUCE_USERNAME']
|
126
|
+
access_key = ENV['SAUCE_ACCESS_KEY']
|
127
|
+
|
128
|
+
# Make request to sauce labs
|
129
|
+
uri = URI("https://saucelabs.com/rest/v1/#{username}/jobs?limit=#{limit}&full=true")
|
130
|
+
resp = Net::HTTP.start(uri.host, uri.port, :use_ssl => 'https') do |http|
|
131
|
+
req = Net::HTTP::Get.new uri
|
132
|
+
req.basic_auth username, access_key
|
133
|
+
http.request req
|
134
|
+
end
|
135
|
+
|
136
|
+
# Parse response
|
137
|
+
tests = JSON.parse(resp.body)
|
138
|
+
tests = example
|
139
|
+
|
140
|
+
# Filter for only failed tests
|
141
|
+
failed_tests = tests.select do |test|
|
142
|
+
test['passed'] == false
|
143
|
+
end
|
144
|
+
|
145
|
+
# Mapping from Sauce browser name to Rainforest browser name
|
146
|
+
rf_browsers = {
|
147
|
+
'googlechrome' => 'chrome_1440_900',
|
148
|
+
'firefox' => 'firefox_1440_900',
|
149
|
+
'iexplore' => 'ie11_1440_900',
|
150
|
+
'microsoftedge' => 'windows10_edge',
|
151
|
+
'safari' => 'safari_1440_900',
|
152
|
+
}
|
153
|
+
|
154
|
+
# Find Rainforest test id from name in format "Some Name [1234]"
|
155
|
+
results = {}
|
156
|
+
failed_tests.each do |test|
|
157
|
+
name = test['name']
|
158
|
+
id = name[/^Rainforest \[(\d+)\]/]
|
159
|
+
next unless id
|
160
|
+
|
161
|
+
results[id] ||= []
|
162
|
+
results[id].push(rf_browsers[test['browser']])
|
163
|
+
end
|
164
|
+
|
165
|
+
# Execute rainforest cli once per test id
|
166
|
+
results.each do |test_id, browsers|
|
167
|
+
system("rainforest run #{test_id} --browsers #{browsers.join(',')}")
|
168
|
+
end
|
169
|
+
```
|
30
170
|
## Contributing
|
31
171
|
|
32
172
|
1. Fork it ( https://github.com/rainforestapp/rainforest_ruby_runtime/fork )
|
data/Rakefile
CHANGED
@@ -1,9 +1,30 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'open-uri'
|
2
5
|
|
3
|
-
|
6
|
+
GITHUB_REPO = 'https://raw.githubusercontent.com/rainforestapp/rainforest_ruby_runtime'
|
4
7
|
|
5
|
-
|
6
|
-
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |t|
|
9
|
+
ENV['CAPYBARA_DRIVER'] = 'selenium'
|
10
|
+
t.rspec_opts = '--color --format documentation'
|
7
11
|
end
|
8
12
|
|
9
|
-
task :
|
13
|
+
task :prepare_sauce do
|
14
|
+
sc =
|
15
|
+
case RUBY_PLATFORM
|
16
|
+
when /cygwin|mswin|mingw|bccwin|wince|emx/ then 'sc-windows.exe'
|
17
|
+
when /darwin/ then 'sc-osx'
|
18
|
+
else 'sc-linux'
|
19
|
+
end
|
20
|
+
|
21
|
+
FileUtils.mkdir_p('vendor/sauce')
|
22
|
+
url = "#{GITHUB_REPO}/v#{RainforestRubyRuntime::VERSION}/vendor/sauce/#{sc}"
|
23
|
+
|
24
|
+
File.open('vendor/sauce/sc', 'wb') do |file|
|
25
|
+
IO.copy_stream(open(url), file)
|
26
|
+
file.chmod(0755)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => [:spec]
|
data/bin/rainforest_test
CHANGED
@@ -3,6 +3,51 @@
|
|
3
3
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "../lib")
|
4
4
|
require 'rainforest_ruby_runtime'
|
5
5
|
|
6
|
-
|
6
|
+
def prepare_sauce
|
7
|
+
require 'rake'
|
7
8
|
|
8
|
-
|
9
|
+
gem_dir = __dir__
|
10
|
+
pwd = Dir.pwd
|
11
|
+
|
12
|
+
Dir.chdir(gem_dir)
|
13
|
+
|
14
|
+
Rake.application.init('rake', '-s')
|
15
|
+
Rake.application.load_rakefile
|
16
|
+
Rake.application[:prepare_sauce].invoke
|
17
|
+
|
18
|
+
Dir.chdir(pwd)
|
19
|
+
end
|
20
|
+
|
21
|
+
options = {browsers: %i(chrome)}
|
22
|
+
OptionParser.new do |opts|
|
23
|
+
opts.banner = "Usage: ruby rainforest_test [options] [file_paths]"
|
24
|
+
|
25
|
+
opts.on('--prepare-sauce', 'Sets up the Sauce Connect executable') do
|
26
|
+
prepare_sauce
|
27
|
+
puts 'Sauce Connect executable properly set up'
|
28
|
+
exit
|
29
|
+
end
|
30
|
+
|
31
|
+
opts.on('--browsers X,Y,Z', Array, 'Browsers') do |browsers|
|
32
|
+
invalid_browsers = browsers - RainforestRubyRuntime::Runner::BROWSERS
|
33
|
+
raise OptionParser::InvalidOption, "#{invalid_browsers.join(',')}" unless invalid_browsers.empty?
|
34
|
+
options[:browsers] = browsers.uniq.map(&:to_sym)
|
35
|
+
end
|
36
|
+
opts.on('-h', '--help', 'Displays Help') do
|
37
|
+
puts opts
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end.parse!
|
41
|
+
|
42
|
+
puts "Running against #{options[:browsers].join(',')}"
|
43
|
+
|
44
|
+
tests = []
|
45
|
+
while f = ARGF.file do
|
46
|
+
break if f.closed?
|
47
|
+
tests << ARGF.read(f.size)
|
48
|
+
ARGF.skip
|
49
|
+
end
|
50
|
+
|
51
|
+
RainforestRubyRuntime::Runner.new(browsers: options[:browsers]).run(tests)
|
52
|
+
|
53
|
+
puts "Your test completed successfully!"
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require "sauce"
|
2
2
|
require "sauce/capybara"
|
3
|
-
require "testingbot"
|
4
|
-
require "testingbot/capybara"
|
5
3
|
require "rspec/expectations"
|
6
4
|
require "logger"
|
7
5
|
|
@@ -13,12 +11,13 @@ require "rainforest_ruby_runtime/nil_delegator"
|
|
13
11
|
require "rainforest_ruby_runtime/dsl"
|
14
12
|
require "rainforest_ruby_runtime/runner"
|
15
13
|
require "rainforest_ruby_runtime/drivers/sauce"
|
16
|
-
require "rainforest_ruby_runtime/drivers/browser_stack"
|
17
|
-
require "rainforest_ruby_runtime/drivers/testing_bot"
|
18
14
|
require "rainforest_ruby_runtime/drivers/selenium"
|
19
15
|
require "rainforest_ruby_runtime/variables/value"
|
20
|
-
require "rainforest_ruby_runtime/variables/
|
16
|
+
require "rainforest_ruby_runtime/variables/registry"
|
21
17
|
require "rainforest_ruby_runtime/variables/scope"
|
22
18
|
|
23
19
|
module RainforestRubyRuntime
|
20
|
+
def self.root
|
21
|
+
File.dirname(__dir__)
|
22
|
+
end
|
24
23
|
end
|
@@ -7,28 +7,39 @@ module RainforestRubyRuntime
|
|
7
7
|
@options = options
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
|
10
|
+
def to_rspec(tests)
|
11
|
+
apply_config
|
12
|
+
|
13
|
+
RSpec.describe 'Rainforest', sauce: true, tests: tests do
|
14
|
+
metadata[:tests].each do |test|
|
15
|
+
it "[#{test.id}] #{test.title}" do
|
16
|
+
test.run
|
17
|
+
end
|
18
|
+
end
|
13
19
|
end
|
14
20
|
end
|
15
21
|
|
16
22
|
private
|
17
23
|
|
24
|
+
def apply_config
|
25
|
+
::Sauce.config do |c|
|
26
|
+
c[:browsers] = browsers
|
27
|
+
c[:sauce_connect_4_executable] = File.join(RainforestRubyRuntime.root, '/vendor/sauce/sc')
|
28
|
+
c[:start_local_application] = false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
18
32
|
def browsers
|
19
33
|
Array(options[:browsers]).map do |browser|
|
20
34
|
{
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
'firefox' => ["Windows 7", "Firefox", "30"],
|
27
|
-
'safari' => ["Mavericks", "Safari", "7"],
|
35
|
+
chrome: ['Windows 7', 'Chrome', 'latest'],
|
36
|
+
firefox: ['Windows 7', 'Firefox', 'latest'],
|
37
|
+
ie: ['Windows 7', 'Internet Explorer', 'latest'],
|
38
|
+
edge: ['Windows 10', 'microsoftedge', 'latest'],
|
39
|
+
safari: ['Mac 10.11', 'Safari', 'latest'],
|
28
40
|
}.fetch(browser)
|
29
41
|
end
|
30
42
|
end
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
34
|
-
|
@@ -1,14 +1,44 @@
|
|
1
1
|
module RainforestRubyRuntime
|
2
2
|
module Drivers
|
3
3
|
class Selenium
|
4
|
+
attr_reader :browsers
|
5
|
+
|
4
6
|
def initialize(options)
|
5
|
-
@
|
7
|
+
@browsers = options[:browsers]
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_rspec(tests)
|
11
|
+
RSpec.describe 'Rainforest', tests: tests, browsers: browsers do
|
12
|
+
metadata[:tests].each do |test|
|
13
|
+
describe "[#{test.id}] #{test.title}" do
|
14
|
+
metadata[:browsers].each do |browser|
|
15
|
+
let(:current_driver) { Capybara.current_session.driver }
|
16
|
+
|
17
|
+
after do
|
18
|
+
if current_driver.respond_to?(:finish!)
|
19
|
+
current_driver.finish!
|
20
|
+
elsif current_driver.respond_to?(:quit)
|
21
|
+
current_driver.quit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
specify browser do
|
26
|
+
# for whatever reason, this line no longer works if put in a `before` block
|
27
|
+
current_driver.options[:browser] = browser
|
28
|
+
|
29
|
+
test.run
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
6
35
|
end
|
7
36
|
|
8
|
-
|
9
|
-
|
37
|
+
private
|
38
|
+
|
39
|
+
def current_driver
|
40
|
+
Capybara.current_session.driver
|
10
41
|
end
|
11
42
|
end
|
12
43
|
end
|
13
44
|
end
|
14
|
-
|