sauce_bindings 1.1.1 → 1.3.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/.rubocop.yml +12 -6
- data/CHANGES.md +46 -0
- data/LICENSE.txt +1 -1
- data/README.md +11 -87
- data/Rakefile +15 -1
- data/lib/sauce_bindings/capybara_session.rb +0 -3
- data/lib/sauce_bindings/errors.rb +7 -0
- data/lib/sauce_bindings/logger.rb +20 -0
- data/lib/sauce_bindings/options.rb +23 -5
- data/lib/sauce_bindings/session.rb +98 -18
- data/lib/sauce_bindings/version.rb +1 -1
- data/lib/sauce_bindings.rb +8 -0
- data/sauce_bindings.gemspec +7 -6
- data/spec/examples/accessibility_spec.rb +32 -0
- data/spec/examples/axe.min.js +1 -0
- data/spec/examples/browser_options_spec.rb +2 -2
- data/spec/examples/{basic_options_spec.rb → common_options_spec.rb} +4 -3
- data/spec/examples/sauce_options_spec.rb +1 -1
- data/spec/integration/accessibility_spec.rb +59 -0
- data/spec/integration/desktop_spec.rb +33 -4
- data/spec/spec_helper.rb +39 -1
- data/spec/unit/capybara_session_spec.rb +10 -20
- data/spec/unit/deprecated_options_spec.rb +479 -456
- data/spec/unit/options_spec.rb +121 -154
- data/spec/unit/session_spec.rb +437 -84
- metadata +56 -33
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
module SauceBindings
|
6
|
+
describe Session do
|
7
|
+
describe 'gets accessibility results' do
|
8
|
+
before { WebMock.allow_net_connect! }
|
9
|
+
|
10
|
+
it 'with nested iframes' do
|
11
|
+
@session = Session.new
|
12
|
+
driver = @session.start
|
13
|
+
|
14
|
+
driver.get('http://watir.com/examples/nested_iframes.html')
|
15
|
+
|
16
|
+
results = @session.accessibility_results
|
17
|
+
|
18
|
+
problems = results['violations'].map { |v| v['nodes'].size }.inject(0, :+)
|
19
|
+
expect(problems).to eq 16
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'with nested frames' do
|
23
|
+
@session = Session.new
|
24
|
+
driver = @session.start
|
25
|
+
|
26
|
+
driver.get('http://watir.com/examples/nested_frames.html')
|
27
|
+
|
28
|
+
results = @session.accessibility_results
|
29
|
+
|
30
|
+
problems = results['violations'].map { |v| v['nodes'].size }.inject(0, :+)
|
31
|
+
expect(problems).to eq 14
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'with nested iframes and frames turned off' do
|
35
|
+
@session = Session.new
|
36
|
+
driver = @session.start
|
37
|
+
|
38
|
+
driver.get('http://watir.com/examples/nested_iframes.html')
|
39
|
+
|
40
|
+
results = @session.accessibility_results(frames: false)
|
41
|
+
|
42
|
+
problems = results['violations'].map { |v| v['nodes'].size }.inject(0, :+)
|
43
|
+
expect(problems).to eq 7
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'with nested frames and frames turned off' do
|
47
|
+
@session = Session.new
|
48
|
+
driver = @session.start
|
49
|
+
|
50
|
+
driver.get('http://watir.com/examples/nested_frames.html')
|
51
|
+
|
52
|
+
results = @session.accessibility_results(frames: false)
|
53
|
+
|
54
|
+
problems = results['violations'].map { |v| v['nodes'].size }.inject(0, :+)
|
55
|
+
expect(problems).to eq 6
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -4,9 +4,9 @@ require 'spec_helper'
|
|
4
4
|
|
5
5
|
module SauceBindings
|
6
6
|
describe Session do
|
7
|
-
|
8
|
-
before { WebMock.allow_net_connect! }
|
7
|
+
before { WebMock.allow_net_connect! }
|
9
8
|
|
9
|
+
describe '#data_center=' do
|
10
10
|
it 'defaults to US West' do
|
11
11
|
@session = Session.new
|
12
12
|
driver = @session.start
|
@@ -17,7 +17,8 @@ module SauceBindings
|
|
17
17
|
|
18
18
|
it 'executes on US East' do
|
19
19
|
options = Options.chrome(platform_name: 'Linux')
|
20
|
-
@session = Session.new(options
|
20
|
+
@session = Session.new(options)
|
21
|
+
@session.data_center = :US_EAST
|
21
22
|
driver = @session.start
|
22
23
|
|
23
24
|
expect(driver).not_to be_nil
|
@@ -25,12 +26,40 @@ module SauceBindings
|
|
25
26
|
end
|
26
27
|
|
27
28
|
it 'executes on EU Central' do
|
28
|
-
@session = Session.new
|
29
|
+
@session = Session.new
|
30
|
+
@session.data_center = :EU_CENTRAL
|
29
31
|
driver = @session.start
|
30
32
|
|
31
33
|
expect(driver).not_to be_nil
|
32
34
|
expect(@session.url).to include('eu-central-1')
|
33
35
|
end
|
36
|
+
|
37
|
+
it 'executes on APAC' do
|
38
|
+
pending 'Adding Data Center to Sauce Whisk'
|
39
|
+
@session = Session.new
|
40
|
+
@session.data_center = :APAC_SOUTHEAST
|
41
|
+
driver = @session.start
|
42
|
+
|
43
|
+
expect(driver).not_to be_nil
|
44
|
+
expect(@session.url).to include('apac-southeast-1')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#stop_network' do
|
49
|
+
it 'stops and starts the network' do
|
50
|
+
@session = Session.new(Options.safari)
|
51
|
+
driver = @session.start
|
52
|
+
|
53
|
+
@session.stop_network
|
54
|
+
driver.get('https://www.saucedemo.com')
|
55
|
+
|
56
|
+
expect(driver.title).to eq 'Failed to open page'
|
57
|
+
|
58
|
+
@session.start_network
|
59
|
+
driver.get('https://www.saucedemo.com')
|
60
|
+
|
61
|
+
expect(driver.title).to eq 'Swag Labs'
|
62
|
+
end
|
34
63
|
end
|
35
64
|
end
|
36
65
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -3,13 +3,51 @@
|
|
3
3
|
require 'sauce_bindings'
|
4
4
|
require 'rspec'
|
5
5
|
require 'webmock/rspec'
|
6
|
+
require 'climate_control'
|
6
7
|
|
7
8
|
RSpec.configure do |config|
|
8
9
|
config.expect_with :rspec do |c|
|
9
10
|
c.syntax = :expect
|
10
11
|
end
|
11
12
|
|
13
|
+
config.before(:suite) do
|
14
|
+
BUILD_ENV = {BUILD_TAG: '', BUILD_NAME: 'TEMP BUILD', BUILD_NUMBER: '11'}.freeze
|
15
|
+
SAUCE_ACCESS = {SAUCE_USERNAME: 'foo', SAUCE_ACCESS_KEY: '123'}.freeze
|
16
|
+
end
|
17
|
+
|
12
18
|
config.after do |example|
|
13
|
-
@session&.stop(!example.exception)
|
19
|
+
@session&.stop(!example.exception) if @session&.session_id != '0'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
DEPRECATION_WARNINGS = %i[options_init timeouts].freeze
|
24
|
+
|
25
|
+
DEPRECATION_WARNINGS.each do |deprecation|
|
26
|
+
RSpec::Matchers.define "have_deprecated_#{deprecation}" do
|
27
|
+
match do |actual|
|
28
|
+
return actual.call if ENV['IGNORE_DEPRECATIONS']
|
29
|
+
|
30
|
+
warning = /\[DEPRECATION\] \[:#{deprecation}/
|
31
|
+
expect {
|
32
|
+
actual.call
|
33
|
+
@stdout_message = File.read $stdout if $stdout.is_a?(File)
|
34
|
+
}.to output(warning).to_stdout_from_any_process
|
35
|
+
end
|
36
|
+
|
37
|
+
failure_message do |_actual|
|
38
|
+
return 'unexpected exception in the custom matcher block' unless @stdout_message
|
39
|
+
|
40
|
+
deprecations_found = @stdout_message[/WARN Watir \[DEPRECATION\] ([^.*\ ]*)/, 1]
|
41
|
+
but_message = if deprecations_found.nil?
|
42
|
+
'no Warnings were found'
|
43
|
+
else
|
44
|
+
"deprecation Warning of #{deprecations_found} was found instead"
|
45
|
+
end
|
46
|
+
"expected Warning message of \"#{deprecation}\" being deprecated, but #{but_message}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def supports_block_expectations?
|
50
|
+
true
|
51
|
+
end
|
14
52
|
end
|
15
53
|
end
|
@@ -14,36 +14,23 @@ module SauceBindings
|
|
14
14
|
{browserName: 'chrome',
|
15
15
|
browserVersion: 'latest',
|
16
16
|
platformName: 'Windows 10',
|
17
|
-
'sauce:options': {
|
17
|
+
'sauce:options': {username: 'foo',
|
18
|
+
accessKey: '123',
|
19
|
+
build: 'TEMP BUILD: 11'}}
|
18
20
|
end
|
19
21
|
|
20
22
|
def expect_request
|
21
|
-
|
22
|
-
capabilities: {firstMatch: [default_capabilities]}}.to_json
|
23
|
-
se4 = {capabilities: {alwaysMatch: default_capabilities}}.to_json
|
24
|
-
|
25
|
-
body = Selenium::WebDriver::VERSION[0] == '3' ? se3 : se4
|
23
|
+
body = {capabilities: {alwaysMatch: default_capabilities}}.to_json
|
26
24
|
|
27
25
|
endpoint = 'https://ondemand.us-west-1.saucelabs.com/wd/hub/session'
|
28
26
|
stub_request(:post, endpoint).with(body: body).to_return(valid_response)
|
29
27
|
end
|
30
28
|
|
31
|
-
before do
|
32
|
-
allow_any_instance_of(Net::HTTP).to receive(:proxy_uri)
|
33
|
-
allow_any_instance_of(Selenium::WebDriver::Remote::Http::Default).to receive(:use_proxy?).and_return(false)
|
34
|
-
allow(ENV).to receive(:[]).with('DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS')
|
35
|
-
allow(ENV).to receive(:[]).with('BUILD_TAG').and_return('')
|
36
|
-
allow(ENV).to receive(:[]).with('BUILD_NAME').and_return('TEMP BUILD')
|
37
|
-
allow(ENV).to receive(:[]).with('BUILD_NUMBER').and_return('11')
|
38
|
-
allow(ENV).to receive(:[]).with('SAUCE_USERNAME').and_return('foo')
|
39
|
-
allow(ENV).to receive(:[]).with('SAUCE_ACCESS_KEY').and_return('123')
|
40
|
-
end
|
41
|
-
|
42
29
|
describe '#new' do
|
43
30
|
it 'registers a Capybara Driver' do
|
44
31
|
CapybaraSession.new
|
45
32
|
|
46
|
-
expect(Capybara.drivers).to include(:sauce)
|
33
|
+
expect(Capybara.drivers.names).to include(:sauce)
|
47
34
|
expect(Capybara.current_driver).to eq :sauce
|
48
35
|
end
|
49
36
|
end
|
@@ -52,8 +39,11 @@ module SauceBindings
|
|
52
39
|
it 'starts the session with Capybara driver' do
|
53
40
|
expect_request
|
54
41
|
|
55
|
-
|
56
|
-
|
42
|
+
ClimateControl.modify(**SAUCE_ACCESS, **BUILD_ENV) do
|
43
|
+
@driver = CapybaraSession.new.start
|
44
|
+
end
|
45
|
+
|
46
|
+
expect(@driver).to eq Capybara.current_session.driver.browser
|
57
47
|
|
58
48
|
Capybara.current_session.driver.instance_variable_set('@browser', nil)
|
59
49
|
end
|