simple_sauce 1.0.0.pre.alpha → 1.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/simple_sauce/capybara_session.rb +33 -0
- data/lib/simple_sauce/version.rb +1 -1
- data/simple_sauce.gemspec +1 -0
- data/spec/capybara_session_spec.rb +87 -0
- data/spec/session_spec.rb +1 -1
- metadata +18 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d98345f5b70308f983dab7666e42db6f6038925507c8381000e2725ed0de5729
|
4
|
+
data.tar.gz: db5446374cc476310258535e7f425f6ee8717ed107abf1acf5fff9873f248ba0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9feeb9962ffe488da37b9f61de2de7d08d6c9785ef56285651c9412ee9af75002e4fc0af4d32d85247948321e09365cb41079063e534dcc9e6efc75d07d6c3c9
|
7
|
+
data.tar.gz: b4d3294c5c1ec85b36998dbb478989db8c96a1ba747b34f2ca37ca559cb79cb60fe6f2e805629abd4e20e04f5675d402991eafe487743e476df403e809eda187
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simple_sauce'
|
4
|
+
require 'capybara'
|
5
|
+
|
6
|
+
module SimpleSauce
|
7
|
+
class CapybaraSession < Session
|
8
|
+
def initialize(*)
|
9
|
+
super
|
10
|
+
|
11
|
+
Capybara.register_driver :sauce do |app|
|
12
|
+
Capybara::Selenium::Driver.new(app, **{browser: :remote}.merge(to_selenium))
|
13
|
+
end
|
14
|
+
Capybara.current_driver = :sauce
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
raise ArgumentError, "needs username; use `ENV['SAUCE_USERNAME']` or `Session#username=`" unless @username
|
19
|
+
raise ArgumentError, "needs access_key; use `ENV['SAUCE_ACCESS_KEY']` or `Session#access_key=`" unless @access_key
|
20
|
+
|
21
|
+
@capybara_driver = Capybara.current_session.driver
|
22
|
+
@driver = @capybara_driver.browser
|
23
|
+
end
|
24
|
+
|
25
|
+
def stop(result)
|
26
|
+
return if @driver.nil?
|
27
|
+
|
28
|
+
SauceWhisk::Jobs.change_status(@driver.session_id, result)
|
29
|
+
|
30
|
+
Capybara.current_session.quit
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/simple_sauce/version.rb
CHANGED
data/simple_sauce.gemspec
CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ['lib']
|
21
21
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
23
|
+
spec.add_development_dependency 'capybara', '~> 3.16'
|
23
24
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
25
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
26
|
spec.add_development_dependency 'rubocop', '~>0.66'
|
@@ -0,0 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
require 'simple_sauce/capybara_session'
|
6
|
+
|
7
|
+
module SimpleSauce
|
8
|
+
describe CapybaraSession do
|
9
|
+
let(:valid_response) do
|
10
|
+
{status: 200,
|
11
|
+
body: {value: {sessionId: '0', capabilities: Selenium::WebDriver::Remote::Capabilities.chrome}}.to_json,
|
12
|
+
headers: {"content_type": 'application/json'}}
|
13
|
+
end
|
14
|
+
let(:default_capabilities) do
|
15
|
+
{browserName: 'chrome',
|
16
|
+
browserVersion: 'latest',
|
17
|
+
platformName: 'Windows 10',
|
18
|
+
'sauce:options': {build: 'TEMP BUILD: 11'}}
|
19
|
+
end
|
20
|
+
|
21
|
+
def expect_request(body: nil, endpoint: nil)
|
22
|
+
body = (body || {desiredCapabilities: default_capabilities,
|
23
|
+
capabilities: {firstMatch: [default_capabilities]}}).to_json
|
24
|
+
endpoint ||= 'https://ondemand.us-west-1.saucelabs.com/wd/hub/session'
|
25
|
+
stub_request(:post, endpoint).with(body: body).to_return(valid_response)
|
26
|
+
end
|
27
|
+
|
28
|
+
before do
|
29
|
+
ENV['BUILD_TAG'] = ''
|
30
|
+
ENV['BUILD_NAME'] = 'TEMP BUILD'
|
31
|
+
ENV['BUILD_NUMBER'] = '11'
|
32
|
+
ENV['SAUCE_USERNAME'] = 'foo'
|
33
|
+
ENV['SAUCE_ACCESS_KEY'] = '123'
|
34
|
+
end
|
35
|
+
|
36
|
+
after do
|
37
|
+
ENV.delete 'BUILD_TAG'
|
38
|
+
ENV.delete 'BUILD_NAME'
|
39
|
+
ENV.delete 'BUILD_NUMBER'
|
40
|
+
ENV.delete 'SAUCE_USERNAME'
|
41
|
+
ENV.delete 'SAUCE_ACCESS_KEY'
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#new' do
|
45
|
+
it 'registers a Capybara Driver' do
|
46
|
+
CapybaraSession.new
|
47
|
+
|
48
|
+
expect(Capybara.drivers).to include(:sauce)
|
49
|
+
expect(Capybara.current_driver).to eq :sauce
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#start' do
|
54
|
+
it 'starts the session with Capybara driver' do
|
55
|
+
expect_request
|
56
|
+
|
57
|
+
driver = CapybaraSession.new.start
|
58
|
+
expect(driver).to eq Capybara.current_session.driver.browser
|
59
|
+
|
60
|
+
Capybara.current_session.driver.instance_variable_set('@browser', nil)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#stop' do
|
65
|
+
it 'quits the driver' do
|
66
|
+
cappy_driver = instance_double(Capybara::Selenium::Driver)
|
67
|
+
driver = instance_double(Selenium::WebDriver::Remote::Driver, session_id: '1234')
|
68
|
+
allow(cappy_driver).to receive(:browser).and_return(driver)
|
69
|
+
|
70
|
+
allow(SauceWhisk::Jobs).to receive(:change_status).with('1234', true)
|
71
|
+
|
72
|
+
session = CapybaraSession.new
|
73
|
+
|
74
|
+
allow(Capybara.current_session).to receive(:driver).and_return(cappy_driver)
|
75
|
+
allow(Capybara.current_session).to receive(:quit)
|
76
|
+
|
77
|
+
session.start
|
78
|
+
session.stop(true)
|
79
|
+
|
80
|
+
expect(SauceWhisk::Jobs).to have_received(:change_status).with('1234', true)
|
81
|
+
expect(Capybara.current_session).to have_received(:quit)
|
82
|
+
|
83
|
+
Capybara.current_session.driver.instance_variable_set('@browser', nil)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
data/spec/session_spec.rb
CHANGED
@@ -7,7 +7,7 @@ module SimpleSauce
|
|
7
7
|
describe Session do
|
8
8
|
let(:valid_response) do
|
9
9
|
{status: 200,
|
10
|
-
body: {value: {sessionId: 0, capabilities: Selenium::WebDriver::Remote::Capabilities.chrome}}.to_json,
|
10
|
+
body: {value: {sessionId: '0', capabilities: Selenium::WebDriver::Remote::Capabilities.chrome}}.to_json,
|
11
11
|
headers: {"content_type": 'application/json'}}
|
12
12
|
end
|
13
13
|
let(:default_capabilities) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_sauce
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.alpha
|
4
|
+
version: 1.0.0.pre.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Titus Fortner
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: capybara
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.16'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.16'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,10 +172,12 @@ files:
|
|
158
172
|
- README.md
|
159
173
|
- Rakefile
|
160
174
|
- lib/simple_sauce.rb
|
175
|
+
- lib/simple_sauce/capybara_session.rb
|
161
176
|
- lib/simple_sauce/options.rb
|
162
177
|
- lib/simple_sauce/session.rb
|
163
178
|
- lib/simple_sauce/version.rb
|
164
179
|
- simple_sauce.gemspec
|
180
|
+
- spec/capybara_session_spec.rb
|
165
181
|
- spec/options.yml
|
166
182
|
- spec/options_spec.rb
|
167
183
|
- spec/session_spec.rb
|
@@ -190,6 +206,7 @@ signing_key:
|
|
190
206
|
specification_version: 4
|
191
207
|
summary: Simple interface for interacting with Sauce Labs.
|
192
208
|
test_files:
|
209
|
+
- spec/capybara_session_spec.rb
|
193
210
|
- spec/options.yml
|
194
211
|
- spec/options_spec.rb
|
195
212
|
- spec/session_spec.rb
|