sauce 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +30 -0
- data/Gemfile +16 -0
- data/README.markdown +39 -145
- data/Rakefile +46 -20
- data/bin/sauce +72 -61
- data/gemfiles/rails2.gemfile +10 -0
- data/gemfiles/rails2.gemfile.lock +77 -0
- data/gemfiles/rails3.gemfile +9 -0
- data/gemfiles/rails3.gemfile.lock +137 -0
- data/lib/generators/sauce/install/install_generator.rb +1 -2
- data/lib/sauce.rb +0 -22
- data/lib/sauce/capybara.rb +70 -32
- data/lib/sauce/capybara/cucumber.rb +121 -0
- data/lib/sauce/config.rb +57 -13
- data/lib/sauce/connect.rb +22 -11
- data/lib/sauce/integrations.rb +27 -69
- data/lib/sauce/jasmine.rb +35 -0
- data/lib/sauce/jasmine/rake.rb +47 -0
- data/lib/sauce/jasmine/runner.rb +4 -0
- data/lib/sauce/job.rb +10 -6
- data/lib/sauce/raketasks.rb +0 -21
- data/lib/sauce/selenium.rb +9 -18
- data/lib/sauce/utilities.rb +0 -17
- data/sauce.gemspec +8 -60
- data/spec/integration/connect_integration_spec.rb +84 -0
- data/spec/sauce/capybara/cucumber_spec.rb +156 -0
- data/spec/sauce/capybara/spec_helper.rb +42 -0
- data/spec/sauce/capybara_spec.rb +121 -0
- data/spec/sauce/config_spec.rb +239 -0
- data/spec/sauce/jasmine_spec.rb +49 -0
- data/spec/sauce/selenium_spec.rb +57 -0
- data/spec/spec_helper.rb +4 -0
- data/support/Sauce-Connect.jar +0 -0
- data/test/test_integrations.rb +202 -0
- data/test/test_testcase.rb +13 -0
- metadata +170 -171
- data/examples/helper.rb +0 -16
- data/examples/other_spec.rb +0 -7
- data/examples/saucelabs_spec.rb +0 -12
- data/examples/test_saucelabs.rb +0 -13
- data/examples/test_saucelabs2.rb +0 -9
- data/support/sauce_connect +0 -938
- data/support/selenium-server.jar +0 -0
- data/support/simplejson/LICENSE.txt +0 -19
- data/support/simplejson/__init__.py +0 -437
- data/support/simplejson/decoder.py +0 -421
- data/support/simplejson/encoder.py +0 -501
- data/support/simplejson/ordered_dict.py +0 -119
- data/support/simplejson/scanner.py +0 -77
- data/support/simplejson/tool.py +0 -39
- data/test/test_config.rb +0 -112
- data/test/test_connect.rb +0 -45
- data/test/test_job.rb +0 -13
- data/test/test_selenium.rb +0 -50
- data/test/test_selenium2.rb +0 -9
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'sauce/capybara'
|
3
|
+
require 'sauce/capybara/cucumber'
|
4
|
+
|
5
|
+
describe Sauce::Capybara do
|
6
|
+
describe '#connect_tunnel' do
|
7
|
+
before :each do
|
8
|
+
$sauce_tunnel = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
let(:connector) do
|
12
|
+
connector = double()
|
13
|
+
connector.should_receive(:connect)
|
14
|
+
connector.should_receive(:wait_until_ready)
|
15
|
+
connector
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should not do anything if the sauce tunnel exists' do
|
19
|
+
$sauce_tunnel = 1337
|
20
|
+
Sauce::Capybara.connect_tunnel.should == 1337
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should connect if the tunnel is not connected' do
|
24
|
+
Sauce::Connect.should_receive(:new).and_return(connector)
|
25
|
+
|
26
|
+
Sauce::Capybara.connect_tunnel
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should pass the quiet option to Sauce::Connect' do
|
30
|
+
Sauce::Connect.should_receive(:new).with(
|
31
|
+
hash_including(:quiet => true)).and_return(connector)
|
32
|
+
Sauce::Capybara.connect_tunnel(:quiet => true)
|
33
|
+
end
|
34
|
+
|
35
|
+
after :each do
|
36
|
+
$sauce_tunnel = nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Sauce::Capybara::Driver do
|
41
|
+
describe '#browser' do
|
42
|
+
before :each do
|
43
|
+
# Stub out the selenium driver startup
|
44
|
+
Sauce::Selenium2.stub(:new).and_return(nil)
|
45
|
+
end
|
46
|
+
context 'when tunneling is disabled' do
|
47
|
+
it 'should not call #connect_tunnel' do
|
48
|
+
Sauce::Capybara.should_receive(:connect_tunnel).never
|
49
|
+
Sauce.config do |c|
|
50
|
+
c[:start_tunnel] = false
|
51
|
+
end
|
52
|
+
|
53
|
+
driver = Sauce::Capybara::Driver.new(nil)
|
54
|
+
driver.browser
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context 'with a mock app' do
|
59
|
+
let(:app) { double('Mock App for Driver') }
|
60
|
+
|
61
|
+
subject do
|
62
|
+
Sauce::Capybara::Driver.new(app)
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#find' do
|
66
|
+
let(:selector) { '#lol' }
|
67
|
+
|
68
|
+
context 'with an environment override' do
|
69
|
+
before :each do
|
70
|
+
ENV['SAUCE_DISABLE_RETRY'] = '1'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should not retry and raise the error' do
|
74
|
+
subject.should_receive(:base_find).with(selector).and_raise(Selenium::WebDriver::Error::UnknownError)
|
75
|
+
|
76
|
+
expect {
|
77
|
+
subject.find(selector)
|
78
|
+
}.to raise_error(Selenium::WebDriver::Error::UnknownError)
|
79
|
+
end
|
80
|
+
|
81
|
+
after :each do
|
82
|
+
ENV['SAUCE_DISABLE_RETRY'] = nil
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'should route through handle_retry' do
|
87
|
+
subject.should_receive(:base_find).with(selector) # BLECH
|
88
|
+
subject.find(selector)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should retry 3 times and then raise' do
|
92
|
+
subject.should_receive(:base_find).with(selector).exactly(4).times.and_raise(Selenium::WebDriver::Error::UnknownError)
|
93
|
+
|
94
|
+
expect {
|
95
|
+
subject.find(selector)
|
96
|
+
}.to raise_error(Selenium::WebDriver::Error::UnknownError)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe '#visit' do
|
101
|
+
it 'should route through #handle_retry' do
|
102
|
+
path = '/lol'
|
103
|
+
subject.should_receive(:base_visit).with(path)
|
104
|
+
subject.visit(path)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe '#current_url' do
|
109
|
+
it 'should route through #handle_retry' do
|
110
|
+
url = 'http://lol'
|
111
|
+
subject.should_receive(:base_current_url).and_return(url)
|
112
|
+
subject.current_url.should == url
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#install_hooks' do
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,239 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'sauce/config'
|
3
|
+
|
4
|
+
describe Sauce::Config do
|
5
|
+
let(:c) do
|
6
|
+
config = Sauce::Config.new
|
7
|
+
config.stub(:silence_warnings).and_return(true)
|
8
|
+
config
|
9
|
+
end
|
10
|
+
before :each do
|
11
|
+
Sauce.clear_config
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#[]' do
|
15
|
+
it "should return nil for options that don't exist" do
|
16
|
+
c = Sauce::Config.new
|
17
|
+
c[:undefined].should be_nil
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should return defaults if they haven't been set" do
|
21
|
+
c = Sauce::Config.new
|
22
|
+
c[:browser].should == Sauce::Config::DEFAULT_OPTIONS[:browser]
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return the value set in the constructor" do
|
26
|
+
c = Sauce::Config.new(:myoption => 1337)
|
27
|
+
c[:myoption].should == 1337
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#[]=" do
|
32
|
+
it "should allow setting arbitrary options" do
|
33
|
+
c[:setting_option] = 1337
|
34
|
+
c[:setting_option].should == 1337
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should allow using strings for keys" do
|
38
|
+
c["my-option"] = 1337
|
39
|
+
c["my-option"].should == 1337
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe 'deprecate method_missing' do
|
44
|
+
it 'should warn when accessing an old style method' do
|
45
|
+
c.stub(:silence_warnings).and_return(false)
|
46
|
+
c.should_receive(:warn).with(anything)
|
47
|
+
c.capture_traffic
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe '#host' do
|
52
|
+
it 'should return ondemand.saucelabs.com by default' do
|
53
|
+
c.host.should == 'ondemand.saucelabs.com'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#os' do
|
58
|
+
it 'should return the value set in the config block' do
|
59
|
+
Sauce.config do |config|
|
60
|
+
config.os = 'TEST_OS'
|
61
|
+
end
|
62
|
+
|
63
|
+
c = Sauce::Config.new
|
64
|
+
c.os.should == 'TEST_OS'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#to_browser_string' do
|
69
|
+
before :each do
|
70
|
+
@original_env = {}
|
71
|
+
Sauce::Config::ENVIRONMENT_VARIABLES.each do |key|
|
72
|
+
@original_env[key] = ENV[key] if ENV[key]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should create a browser string from the environment' do
|
77
|
+
ENV['SAUCE_USERNAME'] = "test_user"
|
78
|
+
ENV['SAUCE_ACCESS_KEY'] = "test_access"
|
79
|
+
ENV['SAUCE_OS'] = "Linux"
|
80
|
+
ENV['SAUCE_BROWSER'] = "firefox"
|
81
|
+
ENV['SAUCE_BROWSER_VERSION'] = "3."
|
82
|
+
|
83
|
+
config = Sauce::Config.new
|
84
|
+
browser_data = JSON.parse(config.to_browser_string)
|
85
|
+
browser_data.should == {'name' => 'Unnamed Ruby job',
|
86
|
+
'access-key' => 'test_access',
|
87
|
+
'os' => 'Linux',
|
88
|
+
'username' => 'test_user',
|
89
|
+
'browser-version' => '3.',
|
90
|
+
'browser' => 'firefox'}
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should create a browser string from parameters' do
|
94
|
+
config = Sauce::Config.new(:username => 'test_user',
|
95
|
+
:access_key => 'test_access',
|
96
|
+
:os => 'Linux',
|
97
|
+
:browser => 'firefox',
|
98
|
+
:browser_version => '3.')
|
99
|
+
|
100
|
+
browser_data = JSON.parse(config.to_browser_string)
|
101
|
+
browser_data.should == {'name' => 'Unnamed Ruby job',
|
102
|
+
'access-key' => 'test_access',
|
103
|
+
'os' => 'Linux',
|
104
|
+
'username' => 'test_user',
|
105
|
+
'browser-version' => '3.',
|
106
|
+
'browser' => 'firefox'}
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should create a browser string with optional parameters' do
|
110
|
+
config = Sauce::Config.new(:username => "test_user", :access_key => "test_access",
|
111
|
+
:os => "Linux", :browser => "firefox", :browser_version => "3.",
|
112
|
+
:"user-extensions-url" => "testing")
|
113
|
+
browser_data = JSON.parse(config.to_browser_string)
|
114
|
+
browser_data.should == {'name' => 'Unnamed Ruby job',
|
115
|
+
'access-key' => 'test_access',
|
116
|
+
'os' => 'Linux',
|
117
|
+
'username' => 'test_user',
|
118
|
+
'browser-version' => '3.',
|
119
|
+
'browser' => 'firefox',
|
120
|
+
'user-extensions-url' => 'testing'}
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should create a browser string with optional parameters as underscored symbols' do
|
124
|
+
config = Sauce::Config.new(:username => "test_user", :access_key => "test_access",
|
125
|
+
:os => "Linux", :browser => "firefox", :browser_version => "3.",
|
126
|
+
:user_extensions_url => "testing")
|
127
|
+
browser_data = JSON.parse(config.to_browser_string)
|
128
|
+
browser_data.should == {'name' => 'Unnamed Ruby job',
|
129
|
+
'access-key' => 'test_access',
|
130
|
+
'os' => 'Linux',
|
131
|
+
'username' => 'test_user',
|
132
|
+
'browser-version' => '3.',
|
133
|
+
'browser' => 'firefox',
|
134
|
+
'user-extensions-url' => 'testing'}
|
135
|
+
end
|
136
|
+
|
137
|
+
after :each do
|
138
|
+
Sauce::Config::ENVIRONMENT_VARIABLES.each do |key|
|
139
|
+
ENV[key] = @original_env[key]
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
describe '#to_desired_capabilities' do
|
145
|
+
context 'platforms' do
|
146
|
+
it 'should refer to Windows 2003 as WINDOWS' do
|
147
|
+
config = Sauce::Config.new(:os => "Windows 2003")
|
148
|
+
config.to_desired_capabilities[:platform].should == 'WINDOWS'
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should refer to Windows 2008 as VISTA' do
|
152
|
+
config = Sauce::Config.new(:os => "Windows 2008")
|
153
|
+
config.to_desired_capabilities[:platform].should == 'VISTA'
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'configuring Sauce' do
|
159
|
+
it 'should make foo? methods for set boolean values' do
|
160
|
+
c.some_option = true
|
161
|
+
c.some_option?.should be true
|
162
|
+
end
|
163
|
+
|
164
|
+
describe 'browsers=' do
|
165
|
+
it 'should default the config to the first item' do
|
166
|
+
Sauce.config do |config|
|
167
|
+
config.browsers = [['TEST_OS', 'TEST_BROWSER', 'TEST_BROWSER_VERSION']]
|
168
|
+
end
|
169
|
+
|
170
|
+
c = Sauce::Config.new
|
171
|
+
c.os.should == 'TEST_OS'
|
172
|
+
c.browser.should == 'TEST_BROWSER'
|
173
|
+
c.browser_version == 'TEST_BROWSER_VERSION'
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe 'browsers' do
|
178
|
+
it 'should return an Array of the (os, browser, version)' do
|
179
|
+
c.os = 'A'
|
180
|
+
c.browser = 'B'
|
181
|
+
c.browser_version = 'C'
|
182
|
+
|
183
|
+
c.browsers.should == [['A', 'B', 'C']]
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should allow overrides as constructor options' do
|
188
|
+
Sauce.config do |config|
|
189
|
+
config.browsers = [['OS1', 'BROWSER1', 'BROWSER_VERSION1']]
|
190
|
+
end
|
191
|
+
|
192
|
+
c = Sauce::Config.new(:os => 'OS2', :browser => 'BROWSER2',
|
193
|
+
:browser_version => 'BROWSER_VERSION2')
|
194
|
+
c.os.should == 'OS2'
|
195
|
+
c.browser.should == 'BROWSER2'
|
196
|
+
c.browser_version.should == 'BROWSER_VERSION2'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe Sauce do
|
202
|
+
describe '#get_config' do
|
203
|
+
context 'when #config has never been called' do
|
204
|
+
# See: <https://github.com/saucelabs/sauce_ruby/issues/59>
|
205
|
+
before :each do
|
206
|
+
# This is kind of hack-ish, but the best way I can think to properly
|
207
|
+
# prevent this class variable from existing
|
208
|
+
Sauce.instance_variable_set(:@cfg, nil)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should return a newly created Sauce::Config' do
|
212
|
+
dummy_config = double('Sauce::Config')
|
213
|
+
Sauce::Config.should_receive(:new).and_return(dummy_config)
|
214
|
+
Sauce.get_config.should_not be nil
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
context 'when config has been called' do
|
219
|
+
before :each do
|
220
|
+
Sauce.clear_config
|
221
|
+
Sauce.config do |c|
|
222
|
+
c[:some_setting] = true
|
223
|
+
end
|
224
|
+
end
|
225
|
+
it 'should return the same config with the same configuration' do
|
226
|
+
Sauce.get_config.should_not be nil
|
227
|
+
Sauce.get_config[:some_setting].should be true
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe '#clear_config' do
|
233
|
+
it 'should reset the config object' do
|
234
|
+
c = Sauce.get_config
|
235
|
+
Sauce.clear_config
|
236
|
+
c.should_not equal(Sauce.get_config)
|
237
|
+
end
|
238
|
+
end
|
239
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'sauce/jasmine'
|
3
|
+
|
4
|
+
describe Sauce::Jasmine::Driver do
|
5
|
+
describe '#initialize' do
|
6
|
+
let(:address) { 'http://saucelabs.com' }
|
7
|
+
let(:browser) { 'firefox' }
|
8
|
+
|
9
|
+
it 'should take set the @http_address' do
|
10
|
+
Sauce::Selenium2.stub(:new)
|
11
|
+
d = Sauce::Jasmine::Driver.new(browser, address)
|
12
|
+
d.http_address.should equal(address)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should initialize a Sauce driver' do
|
16
|
+
Sauce::Selenium2.should_receive(:new).with(hash_including(:browser => browser)).and_return(true)
|
17
|
+
d = Sauce::Jasmine::Driver.new(browser, address)
|
18
|
+
d.should_not be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
describe Jasmine::Config do
|
25
|
+
describe '#start' do
|
26
|
+
before :each do
|
27
|
+
# Stub out the creation of the Selenium2 driver itself
|
28
|
+
Sauce::Selenium2.stub(:new)
|
29
|
+
Sauce::Jasmine::Driver.stub(:new).and_return(driver)
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:driver) do
|
33
|
+
driver = mock('Sauce::Jasmine::Driver')
|
34
|
+
driver.stub(:connect)
|
35
|
+
driver
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should create a Sauce::Jasmine::Driver' do
|
39
|
+
Sauce::Jasmine::Driver.should_receive(:new).and_return(driver)
|
40
|
+
subject.start
|
41
|
+
subject.instance_variable_get(:@client).should be driver
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should call connect on the driver' do
|
45
|
+
driver.should_receive(:connect)
|
46
|
+
subject.start
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Sauce::Selenium2 do
|
4
|
+
let(:mock_driver) { Hash.new }
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
::Selenium::WebDriver.should_receive(:for).and_return(mock_driver)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
it 'should work without arguments' do
|
12
|
+
client = Sauce::Selenium2.new
|
13
|
+
client.should_not be nil
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should pass the job_name argument into the config' do
|
17
|
+
expected = 'Dummy Job Name'
|
18
|
+
client = Sauce::Selenium2.new(:job_name => expected)
|
19
|
+
client.config[:job_name].should == expected
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
context 'with an initialized object' do
|
25
|
+
before :each do
|
26
|
+
@client = Sauce::Selenium2.new
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#stop' do
|
30
|
+
it 'should call quit on the driver' do
|
31
|
+
@client.driver.should_receive(:quit).and_return(true)
|
32
|
+
@client.stop
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#session_id' do
|
37
|
+
it 'should query the driver for the session_id' do
|
38
|
+
expected = 101
|
39
|
+
bridge = mock('bridge')
|
40
|
+
bridge.should_receive(:session_id).and_return(expected)
|
41
|
+
@client.driver.should_receive(:bridge).and_return(bridge)
|
42
|
+
@client.session_id.should == expected
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#method_missing' do
|
47
|
+
it 'should pass #navigate#to onto the driver' do
|
48
|
+
url = 'http://example.com'
|
49
|
+
navigator = mock('navigator')
|
50
|
+
navigator.should_receive(:to).with(url).and_return(true)
|
51
|
+
@client.driver.should_receive(:navigate).and_return(navigator)
|
52
|
+
|
53
|
+
@client.navigate.to url
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|