watir 7.0.0 → 7.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/chrome.yml +29 -16
- data/.github/workflows/edge.yml +19 -11
- data/.github/workflows/firefox.yml +28 -16
- data/.github/workflows/ie.yml +13 -7
- data/.github/workflows/safari.yml +22 -11
- data/.github/workflows/unit.yml +31 -23
- data/.rubocop.yml +33 -13
- data/.rubocop_todo.yml +7 -26
- data/CHANGES.md +33 -0
- data/Gemfile +6 -1
- data/LICENSE +2 -2
- data/README.md +15 -11
- data/Rakefile +9 -7
- data/lib/watir/adjacent.rb +3 -1
- data/lib/watir/after_hooks.rb +5 -3
- data/lib/watir/alert.rb +2 -0
- data/lib/watir/aliases.rb +2 -0
- data/lib/watir/attribute_helper.rb +4 -2
- data/lib/watir/browser.rb +10 -14
- data/lib/watir/capabilities.rb +53 -33
- data/lib/watir/cell_container.rb +2 -0
- data/lib/watir/container.rb +2 -0
- data/lib/watir/cookies.rb +5 -5
- data/lib/watir/element_collection.rb +3 -1
- data/lib/watir/elements/button.rb +2 -0
- data/lib/watir/elements/cell.rb +2 -0
- data/lib/watir/elements/checkbox.rb +2 -0
- data/lib/watir/elements/date_field.rb +2 -0
- data/lib/watir/elements/date_time_field.rb +2 -0
- data/lib/watir/elements/dlist.rb +3 -1
- data/lib/watir/elements/element.rb +68 -118
- data/lib/watir/elements/file_field.rb +2 -0
- data/lib/watir/elements/font.rb +2 -0
- data/lib/watir/elements/form.rb +2 -0
- data/lib/watir/elements/hidden.rb +2 -0
- data/lib/watir/elements/iframe.rb +2 -0
- data/lib/watir/elements/image.rb +2 -0
- data/lib/watir/elements/input.rb +2 -0
- data/lib/watir/elements/link.rb +2 -0
- data/lib/watir/elements/list.rb +2 -0
- data/lib/watir/elements/option.rb +2 -0
- data/lib/watir/elements/radio.rb +2 -0
- data/lib/watir/elements/row.rb +2 -0
- data/lib/watir/elements/select.rb +2 -0
- data/lib/watir/elements/table.rb +3 -1
- data/lib/watir/elements/table_cell.rb +2 -0
- data/lib/watir/elements/table_row.rb +2 -0
- data/lib/watir/elements/table_section.rb +2 -0
- data/lib/watir/elements/text_area.rb +2 -0
- data/lib/watir/elements/text_field.rb +2 -0
- data/lib/watir/exception.rb +2 -0
- data/lib/watir/extensions/nokogiri.rb +2 -0
- data/lib/watir/generator/base/generator.rb +2 -0
- data/lib/watir/generator/base/idl_sorter.rb +3 -1
- data/lib/watir/generator/base/spec_extractor.rb +6 -4
- data/lib/watir/generator/base/util.rb +2 -0
- data/lib/watir/generator/base/visitor.rb +5 -5
- data/lib/watir/generator/base.rb +2 -1
- data/lib/watir/generator/html/generator.rb +2 -0
- data/lib/watir/generator/html/spec_extractor.rb +2 -0
- data/lib/watir/generator/html/visitor.rb +2 -0
- data/lib/watir/generator/html.rb +2 -0
- data/lib/watir/generator/svg/generator.rb +2 -0
- data/lib/watir/generator/svg/spec_extractor.rb +2 -0
- data/lib/watir/generator/svg/visitor.rb +2 -0
- data/lib/watir/generator/svg.rb +2 -0
- data/lib/watir/generator.rb +2 -0
- data/lib/watir/has_window.rb +3 -1
- data/lib/watir/http_client.rb +2 -0
- data/lib/watir/js_execution.rb +2 -0
- data/lib/watir/js_snippets/isElementInViewport.js +20 -0
- data/lib/watir/js_snippets.rb +2 -0
- data/lib/watir/locators/anchor/selector_builder.rb +5 -0
- data/lib/watir/locators/button/matcher.rb +2 -0
- data/lib/watir/locators/button/selector_builder/xpath.rb +15 -19
- data/lib/watir/locators/button/selector_builder.rb +2 -0
- data/lib/watir/locators/cell/selector_builder/xpath.rb +2 -0
- data/lib/watir/locators/cell/selector_builder.rb +2 -0
- data/lib/watir/locators/element/locator.rb +2 -0
- data/lib/watir/locators/element/matcher.rb +4 -1
- data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +4 -1
- data/lib/watir/locators/element/selector_builder/xpath.rb +16 -15
- data/lib/watir/locators/element/selector_builder/xpath_support.rb +4 -2
- data/lib/watir/locators/element/selector_builder.rb +16 -6
- data/lib/watir/locators/option/matcher.rb +2 -0
- data/lib/watir/locators/option/selector_builder/xpath.rb +2 -0
- data/lib/watir/locators/option/selector_builder.rb +2 -0
- data/lib/watir/locators/row/selector_builder/xpath.rb +2 -0
- data/lib/watir/locators/row/selector_builder.rb +2 -0
- data/lib/watir/locators/text_area/selector_builder/xpath.rb +2 -0
- data/lib/watir/locators/text_area/selector_builder.rb +2 -0
- data/lib/watir/locators/text_field/matcher.rb +2 -4
- data/lib/watir/locators/text_field/selector_builder/xpath.rb +2 -0
- data/lib/watir/locators/text_field/selector_builder.rb +2 -0
- data/lib/watir/locators.rb +2 -0
- data/lib/watir/logger.rb +2 -0
- data/lib/watir/navigation.rb +3 -1
- data/lib/watir/radio_set.rb +2 -0
- data/lib/watir/row_container.rb +2 -0
- data/lib/watir/screenshot.rb +2 -0
- data/lib/watir/scroll.rb +29 -3
- data/lib/watir/search_context.rb +96 -0
- data/lib/watir/shadow_root.rb +60 -0
- data/lib/watir/user_editable.rb +3 -1
- data/lib/watir/version.rb +3 -1
- data/lib/watir/wait/timer.rb +3 -1
- data/lib/watir/wait.rb +5 -5
- data/lib/watir/window.rb +7 -3
- data/lib/watir/window_collection.rb +4 -1
- data/lib/watir.rb +4 -0
- data/lib/watirspec/guards.rb +2 -0
- data/lib/watirspec/implementation.rb +14 -10
- data/lib/watirspec/rake_tasks.rb +4 -4
- data/lib/watirspec/remote_server.rb +5 -3
- data/lib/watirspec/runner.rb +3 -1
- data/lib/watirspec/server/app.rb +2 -0
- data/lib/watirspec/server.rb +2 -0
- data/lib/watirspec.rb +7 -4
- data/spec/locator_spec_helper.rb +2 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/capabilities_spec.rb +561 -550
- data/spec/unit/element_locator_spec.rb +71 -58
- data/spec/unit/match_elements/button_spec.rb +58 -49
- data/spec/unit/match_elements/element_spec.rb +305 -309
- data/spec/unit/match_elements/text_field_spec.rb +78 -73
- data/spec/unit/selector_builder/anchor_spec.rb +41 -33
- data/spec/unit/selector_builder/button_spec.rb +211 -201
- data/spec/unit/selector_builder/cell_spec.rb +50 -42
- data/spec/unit/selector_builder/element_spec.rb +636 -628
- data/spec/unit/selector_builder/row_spec.rb +121 -104
- data/spec/unit/selector_builder/text_field_spec.rb +197 -182
- data/spec/unit/selector_builder/textarea_spec.rb +24 -14
- data/spec/unit/unit_helper.rb +2 -0
- data/spec/unit/wait_spec.rb +77 -71
- data/spec/watirspec/adjacent_spec.rb +251 -247
- data/spec/watirspec/after_hooks_spec.rb +160 -162
- data/spec/watirspec/alert_spec.rb +63 -58
- data/spec/watirspec/browser_spec.rb +411 -407
- data/spec/watirspec/capabilities_spec.rb +566 -0
- data/spec/watirspec/cookies_spec.rb +122 -118
- data/spec/watirspec/drag_and_drop_spec.rb +30 -14
- data/spec/watirspec/element_hidden_spec.rb +68 -60
- data/spec/watirspec/elements/area_spec.rb +51 -47
- data/spec/watirspec/elements/areas_spec.rb +29 -25
- data/spec/watirspec/elements/button_spec.rb +255 -251
- data/spec/watirspec/elements/buttons_spec.rb +38 -34
- data/spec/watirspec/elements/checkbox_spec.rb +50 -36
- data/spec/watirspec/elements/checkboxes_spec.rb +31 -27
- data/spec/watirspec/elements/collections_spec.rb +128 -119
- data/spec/watirspec/elements/date_field_spec.rb +187 -183
- data/spec/watirspec/elements/date_fields_spec.rb +31 -27
- data/spec/watirspec/elements/date_time_field_spec.rb +199 -195
- data/spec/watirspec/elements/date_time_fields_spec.rb +32 -28
- data/spec/watirspec/elements/dd_spec.rb +89 -85
- data/spec/watirspec/elements/dds_spec.rb +29 -25
- data/spec/watirspec/elements/del_spec.rb +108 -104
- data/spec/watirspec/elements/dels_spec.rb +28 -24
- data/spec/watirspec/elements/div_spec.rb +227 -211
- data/spec/watirspec/elements/divs_spec.rb +39 -35
- data/spec/watirspec/elements/dl_spec.rb +112 -110
- data/spec/watirspec/elements/dls_spec.rb +30 -26
- data/spec/watirspec/elements/dt_spec.rb +88 -84
- data/spec/watirspec/elements/dts_spec.rb +29 -25
- data/spec/watirspec/elements/element_spec.rb +815 -715
- data/spec/watirspec/elements/elements_spec.rb +42 -38
- data/spec/watirspec/elements/em_spec.rb +64 -60
- data/spec/watirspec/elements/ems_spec.rb +30 -26
- data/spec/watirspec/elements/filefield_spec.rb +100 -96
- data/spec/watirspec/elements/filefields_spec.rb +30 -26
- data/spec/watirspec/elements/font_spec.rb +22 -18
- data/spec/watirspec/elements/form_spec.rb +53 -49
- data/spec/watirspec/elements/forms_spec.rb +31 -27
- data/spec/watirspec/elements/frame_spec.rb +91 -87
- data/spec/watirspec/elements/frames_spec.rb +29 -25
- data/spec/watirspec/elements/hidden_spec.rb +81 -77
- data/spec/watirspec/elements/hiddens_spec.rb +30 -26
- data/spec/watirspec/elements/hn_spec.rb +61 -57
- data/spec/watirspec/elements/hns_spec.rb +28 -24
- data/spec/watirspec/elements/iframe_spec.rb +197 -191
- data/spec/watirspec/elements/iframes_spec.rb +33 -29
- data/spec/watirspec/elements/image_spec.rb +146 -142
- data/spec/watirspec/elements/images_spec.rb +28 -24
- data/spec/watirspec/elements/input_spec.rb +11 -7
- data/spec/watirspec/elements/ins_spec.rb +108 -104
- data/spec/watirspec/elements/inses_spec.rb +28 -24
- data/spec/watirspec/elements/label_spec.rb +58 -54
- data/spec/watirspec/elements/labels_spec.rb +28 -24
- data/spec/watirspec/elements/li_spec.rb +76 -72
- data/spec/watirspec/elements/link_spec.rb +175 -179
- data/spec/watirspec/elements/links_spec.rb +47 -43
- data/spec/watirspec/elements/lis_spec.rb +29 -25
- data/spec/watirspec/elements/list_spec.rb +46 -42
- data/spec/watirspec/elements/map_spec.rb +59 -55
- data/spec/watirspec/elements/maps_spec.rb +29 -25
- data/spec/watirspec/elements/meta_spec.rb +18 -14
- data/spec/watirspec/elements/metas_spec.rb +28 -24
- data/spec/watirspec/elements/ol_spec.rb +58 -65
- data/spec/watirspec/elements/ols_spec.rb +28 -24
- data/spec/watirspec/elements/option_spec.rb +93 -89
- data/spec/watirspec/elements/p_spec.rb +79 -75
- data/spec/watirspec/elements/pre_spec.rb +77 -73
- data/spec/watirspec/elements/pres_spec.rb +28 -24
- data/spec/watirspec/elements/ps_spec.rb +28 -24
- data/spec/watirspec/elements/radio_spec.rb +253 -249
- data/spec/watirspec/elements/radios_spec.rb +30 -26
- data/spec/watirspec/elements/select_list_spec.rb +539 -522
- data/spec/watirspec/elements/select_lists_spec.rb +34 -30
- data/spec/watirspec/elements/span_spec.rb +114 -110
- data/spec/watirspec/elements/spans_spec.rb +28 -24
- data/spec/watirspec/elements/strong_spec.rb +60 -58
- data/spec/watirspec/elements/strongs_spec.rb +30 -26
- data/spec/watirspec/elements/table_spec.rb +194 -139
- data/spec/watirspec/elements/tables_spec.rb +30 -26
- data/spec/watirspec/elements/tbody_spec.rb +71 -67
- data/spec/watirspec/elements/tbodys_spec.rb +42 -38
- data/spec/watirspec/elements/td_spec.rb +68 -64
- data/spec/watirspec/elements/tds_spec.rb +43 -39
- data/spec/watirspec/elements/text_field_spec.rb +208 -204
- data/spec/watirspec/elements/text_fields_spec.rb +32 -28
- data/spec/watirspec/elements/textarea_spec.rb +22 -18
- data/spec/watirspec/elements/textareas_spec.rb +20 -16
- data/spec/watirspec/elements/tfoot_spec.rb +67 -63
- data/spec/watirspec/elements/tfoots_spec.rb +44 -40
- data/spec/watirspec/elements/thead_spec.rb +67 -63
- data/spec/watirspec/elements/theads_spec.rb +44 -40
- data/spec/watirspec/elements/tr_spec.rb +50 -46
- data/spec/watirspec/elements/trs_spec.rb +44 -40
- data/spec/watirspec/elements/ul_spec.rb +58 -54
- data/spec/watirspec/elements/uls_spec.rb +28 -24
- data/spec/watirspec/html/child_frame.html +29 -0
- data/spec/watirspec/html/class_locator.html +2 -0
- data/spec/watirspec/html/scroll.html +8 -25
- data/spec/watirspec/html/scroll_nested.html +17 -0
- data/spec/watirspec/html/scroll_nested_offscreen.html +18 -0
- data/spec/watirspec/html/shadow_dom.html +28 -0
- data/spec/watirspec/html/sticky_elements.html +10 -0
- data/spec/watirspec/radio_set_spec.rb +271 -267
- data/spec/watirspec/screenshot_spec.rb +22 -18
- data/spec/watirspec/scroll_spec.rb +179 -77
- data/spec/watirspec/shadow_root_spec.rb +106 -0
- data/spec/watirspec/support/rspec_matchers.rb +35 -32
- data/spec/watirspec/user_editable_spec.rb +202 -198
- data/spec/watirspec/wait_spec.rb +291 -295
- data/spec/watirspec/window_switching_spec.rb +426 -428
- data/spec/watirspec_helper.rb +25 -42
- data/support/doctest_helper.rb +2 -0
- data/support/version_differ.rb +2 -0
- data/watir.gemspec +14 -10
- metadata +91 -240
- data/.github/actions/enable-safari/action.yml +0 -11
- data/.github/actions/install-chrome/action.yml +0 -12
- data/.github/actions/setup-linux/action.yml +0 -8
- data/lib/watir-webdriver.rb +0 -2
- data/spec/watirspec/attributes_spec.rb +0 -16
- data/spec/watirspec/elements/table_nesting_spec.rb +0 -49
- data/spec/watirspec/html/hover.html +0 -12
- data/spec/watirspec/special_chars_spec.rb +0 -21
@@ -1,660 +1,671 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'unit_helper'
|
2
4
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
module Watir
|
6
|
+
describe Capabilities do
|
7
|
+
before(:all) { Watir.logger.ignore(:watir_client) }
|
8
|
+
|
9
|
+
def expected_browser(browser)
|
10
|
+
case browser
|
11
|
+
when :ie
|
12
|
+
'internet explorer'
|
13
|
+
when :edge
|
14
|
+
'MicrosoftEdge'
|
15
|
+
else
|
16
|
+
browser.to_s
|
17
|
+
end
|
14
18
|
end
|
15
|
-
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def options_class(browser)
|
22
|
-
Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Options")
|
23
|
-
end
|
20
|
+
def service_class(browser)
|
21
|
+
Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Service")
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
24
|
+
def options_class(browser)
|
25
|
+
Selenium.const_get("Selenium::WebDriver::#{expected_browser_class(browser)}::Options")
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
allow(File).to receive(:executable?).and_return(true)
|
33
|
-
service_class(browser).driver_path = nil
|
34
|
-
end
|
28
|
+
def expected_browser_class(browser)
|
29
|
+
browser == :ie ? 'IE' : browser.capitalize
|
30
|
+
end
|
35
31
|
|
36
|
-
|
32
|
+
def halt_service(browser)
|
33
|
+
allow(Selenium::WebDriver::Platform).to receive(:find_binary).and_return(true)
|
34
|
+
allow(File).to receive(:file?).and_return(true)
|
35
|
+
allow(File).to receive(:executable?).and_return(true)
|
36
|
+
service_class(browser).driver_path = nil
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
# :listener
|
40
|
-
# :service (Built from Hash)
|
41
|
-
# :http_client (Generated or Built from Hash)
|
42
|
-
# :proxy (Built from Hash and added to :options)
|
43
|
-
# :options (Generated or Built from Hash)
|
44
|
-
# :capabilities (incompatible with options)
|
39
|
+
supported_browsers = %i[chrome edge firefox ie safari]
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
41
|
+
# Options:
|
42
|
+
# :listener
|
43
|
+
# :service (Built from Hash)
|
44
|
+
# :http_client (Generated or Built from Hash)
|
45
|
+
# :proxy (Built from Hash and added to :options)
|
46
|
+
# :options (Generated or Built from Hash)
|
47
|
+
# :capabilities (incompatible with options)
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
expect(args.last).not_to include(:service)
|
54
|
-
end
|
49
|
+
supported_browsers.each do |browser_symbol|
|
50
|
+
it 'just browser has client & options not service' do
|
51
|
+
capabilities = described_class.new(browser_symbol)
|
55
52
|
|
56
|
-
|
57
|
-
|
53
|
+
args = capabilities.to_args
|
54
|
+
expect(args.last[:http_client]).to be_a HttpClient
|
55
|
+
expect(args.last[:options]).to be_a options_class(browser_symbol)
|
56
|
+
expect(args.last).not_to include(:service)
|
57
|
+
end
|
58
58
|
|
59
|
-
|
59
|
+
it 'errors with url and service' do
|
60
|
+
expect {
|
61
|
+
described_class.new(browser_symbol,
|
62
|
+
service: instance_double(Selenium::WebDriver::Service),
|
63
|
+
url: 'https://example.com/wd/hub/')
|
64
|
+
}.to raise_exception(ArgumentError, ':url and :service are not both allowed')
|
65
|
+
end
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
expect(args.last).not_to include(:service)
|
64
|
-
end
|
67
|
+
it 'just options has client & options but not capabilities or service' do
|
68
|
+
capabilities = described_class.new(options: options_class(browser_symbol).new)
|
65
69
|
|
66
|
-
|
67
|
-
caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
|
68
|
-
capabilities = Watir::Capabilities.new(capabilities: caps)
|
70
|
+
args = capabilities.to_args
|
69
71
|
|
70
|
-
|
72
|
+
expect(args.last[:http_client]).to be_a HttpClient
|
73
|
+
expect(args.last[:options]).to be_a options_class(browser_symbol)
|
74
|
+
expect(args.last).not_to include(:service)
|
75
|
+
end
|
71
76
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
+
it 'just capabilities has client & capabilities but not service' do
|
78
|
+
caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
|
79
|
+
capabilities = described_class.new(capabilities: caps)
|
80
|
+
args = []
|
81
|
+
expect {
|
82
|
+
args = capabilities.to_args
|
83
|
+
}.to have_deprecated(:capabilities)
|
77
84
|
|
78
|
-
|
79
|
-
|
80
|
-
|
85
|
+
expect(args.last[:http_client]).to be_a HttpClient
|
86
|
+
expect(args.last[:capabilities]).to be_a(Selenium::WebDriver::Remote::Capabilities)
|
87
|
+
expect(args.last[:capabilities].browser_name).to eq expected_browser(browser_symbol)
|
88
|
+
expect(args.last).not_to include(:service)
|
89
|
+
end
|
81
90
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
91
|
+
describe 'service' do
|
92
|
+
it 'uses provided service' do
|
93
|
+
halt_service(browser_symbol)
|
94
|
+
|
95
|
+
service = service_class(browser_symbol).new(port: 1234)
|
96
|
+
capabilities = described_class.new(browser_symbol, service: service)
|
97
|
+
args = capabilities.to_args
|
98
|
+
expect(args.first).to eq browser_symbol
|
99
|
+
actual_service = args.last[:service]
|
100
|
+
expect(actual_service.instance_variable_get(:@port)).to eq 1234
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'builds service from a Hash' do
|
104
|
+
halt_service(browser_symbol)
|
105
|
+
|
106
|
+
service = {port: 1234, path: '/path/to/driver', args: %w[--foo --bar]}
|
107
|
+
capabilities = described_class.new(browser_symbol, service: service)
|
108
|
+
args = capabilities.to_args
|
109
|
+
expect(args.first).to eq browser_symbol
|
110
|
+
actual_service = args.last[:service]
|
111
|
+
expect(actual_service.instance_variable_get(:@port)).to eq 1234
|
112
|
+
expect(actual_service.instance_variable_get(:@executable_path)).to eq '/path/to/driver'
|
113
|
+
expect(actual_service.instance_variable_get(:@extra_args)).to include '--foo', '--bar'
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'is a bad argument to service' do
|
117
|
+
capabilities = described_class.new(browser_symbol, service: 7)
|
118
|
+
|
119
|
+
expect { capabilities.to_args }.to raise_exception(TypeError)
|
120
|
+
end
|
88
121
|
end
|
89
122
|
|
90
|
-
|
91
|
-
|
123
|
+
describe 'http_client' do
|
124
|
+
it 'uses default HTTP Client' do
|
125
|
+
capabilities = described_class.new(browser_symbol)
|
126
|
+
args = capabilities.to_args
|
127
|
+
expect(args.last[:http_client]).to be_a HttpClient
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'accepts an HTTP Client object' do
|
131
|
+
client = Selenium::WebDriver::Remote::Http::Default.new
|
132
|
+
capabilities = described_class.new(browser_symbol, http_client: client)
|
133
|
+
args = capabilities.to_args
|
134
|
+
expect(args.last[:http_client]).to eq client
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'builds an HTTP Client from Hash' do
|
138
|
+
client_opts = {open_timeout: 10, read_timeout: 10}
|
139
|
+
capabilities = described_class.new(browser_symbol, http_client: client_opts)
|
140
|
+
args = capabilities.to_args
|
141
|
+
actual_client = args.last[:http_client]
|
142
|
+
expect(actual_client).to be_a HttpClient
|
143
|
+
expect(actual_client.instance_variable_get(:@read_timeout)).to eq 10
|
144
|
+
expect(actual_client.instance_variable_get(:@open_timeout)).to eq 10
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'raises an exception if :client receives something other than Hash or Client object' do
|
148
|
+
expect {
|
149
|
+
described_class.new(browser_symbol, http_client: 7).to_args
|
150
|
+
}.to raise_exception(TypeError, ':http_client must be a Hash or a Selenium HTTP Client instance')
|
151
|
+
end
|
152
|
+
end
|
92
153
|
|
93
|
-
|
94
|
-
|
154
|
+
it 'uses a listener' do
|
155
|
+
listener = Selenium::WebDriver::Support::AbstractEventListener.new
|
156
|
+
capabilities = described_class.new(browser_symbol, listener: listener)
|
95
157
|
args = capabilities.to_args
|
96
|
-
expect(args.
|
97
|
-
actual_service = args.last[:service]
|
98
|
-
expect(actual_service.instance_variable_get('@port')).to eq 1234
|
99
|
-
expect(actual_service.instance_variable_get('@executable_path')).to eq '/path/to/driver'
|
100
|
-
expect(actual_service.instance_variable_get('@extra_args')).to include '--foo', '--bar'
|
158
|
+
expect(args.last[:listener]).to eq listener
|
101
159
|
end
|
102
160
|
|
103
|
-
it '
|
104
|
-
|
161
|
+
it 'accepts both capabilities and Options' do
|
162
|
+
caps = Selenium::WebDriver::Remote::Capabilities.send(browser_symbol)
|
163
|
+
opts = options_class(browser_symbol).new
|
105
164
|
|
106
|
-
expect {
|
165
|
+
expect {
|
166
|
+
described_class.new(browser_symbol, capabilities: caps, options: opts)
|
167
|
+
}.to raise_exception(ArgumentError, ':capabilities and :options are not both allowed')
|
107
168
|
end
|
108
|
-
end
|
109
169
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
170
|
+
describe 'timeout options' do
|
171
|
+
it 'accepts page load and script timeouts in seconds' do
|
172
|
+
options = {page_load_timeout: 11,
|
173
|
+
script_timeout: 12}
|
174
|
+
capabilities = described_class.new(browser_symbol, options: options)
|
175
|
+
args = capabilities.to_args
|
176
|
+
actual_options = args.last[:options]
|
177
|
+
expect(actual_options.timeouts[:page_load]).to eq 11_000
|
178
|
+
expect(actual_options.timeouts[:script]).to eq 12_000
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'has deprecated timeouts key with page load warning' do
|
182
|
+
options = {timeouts: {page_load: 11}}
|
183
|
+
capabilities = described_class.new(browser_symbol, options: options)
|
184
|
+
expect {
|
185
|
+
capabilities.to_args
|
186
|
+
}.to have_deprecated(:timeouts)
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'has deprecated timeouts key with script warning' do
|
190
|
+
options = {timeouts: {script: 11}}
|
191
|
+
expect {
|
192
|
+
capabilities = described_class.new(browser_symbol, options: options)
|
193
|
+
capabilities.to_args
|
194
|
+
}.to have_deprecated(:timeouts)
|
195
|
+
end
|
196
|
+
|
197
|
+
it 'does not allow implicit wait timeout in timeouts hash' do
|
198
|
+
options = {timeouts: {implicit: 1}}
|
199
|
+
capabilities = described_class.new(browser_symbol, options: options)
|
200
|
+
expect {
|
201
|
+
capabilities.to_args
|
202
|
+
}.to raise_exception(ArgumentError, 'do not set implicit wait, Watir handles waiting automatically')
|
203
|
+
end
|
115
204
|
end
|
116
205
|
|
117
|
-
it '
|
118
|
-
|
119
|
-
capabilities = Watir::Capabilities.new(browser_symbol, http_client: client)
|
206
|
+
it 'unhandled prompt behavior defaults to ignore' do
|
207
|
+
capabilities = described_class.new(browser_symbol)
|
120
208
|
args = capabilities.to_args
|
121
|
-
|
209
|
+
actual_options = args.last[:options]
|
210
|
+
expect(actual_options.unhandled_prompt_behavior).to eq :ignore
|
122
211
|
end
|
123
212
|
|
124
|
-
it '
|
125
|
-
|
126
|
-
capabilities = Watir::Capabilities.new(browser_symbol, http_client: client_opts)
|
213
|
+
it 'unhandled prompt behavior can be overridden' do
|
214
|
+
capabilities = described_class.new(browser_symbol, options: {unhandled_prompt_behavior: :accept_and_notify})
|
127
215
|
args = capabilities.to_args
|
128
|
-
|
129
|
-
expect(
|
130
|
-
expect(actual_client.instance_variable_get('@read_timeout')).to eq 10
|
131
|
-
expect(actual_client.instance_variable_get('@open_timeout')).to eq 10
|
216
|
+
actual_options = args.last[:options]
|
217
|
+
expect(actual_options.unhandled_prompt_behavior).to eq :accept_and_notify
|
132
218
|
end
|
133
219
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
220
|
+
describe 'proxy' do
|
221
|
+
it 'adds Selenium Proxy to empty Options' do
|
222
|
+
proxy = Selenium::WebDriver::Proxy.new(http: '127.0.0.1:8080', ssl: '127.0.0.1:443')
|
223
|
+
capabilities = described_class.new(browser_symbol, proxy: proxy)
|
224
|
+
args = capabilities.to_args
|
225
|
+
proxy = args.last[:options].proxy
|
226
|
+
|
227
|
+
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
228
|
+
expect(proxy.type).to eq(:manual)
|
229
|
+
expect(proxy.http).to eq('127.0.0.1:8080')
|
230
|
+
expect(proxy.ssl).to eq('127.0.0.1:443')
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'builds a Proxy from Hash for Options' do
|
234
|
+
proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
|
235
|
+
capabilities = described_class.new(browser_symbol, proxy: proxy)
|
236
|
+
args = capabilities.to_args
|
237
|
+
proxy = args.last[:options].proxy
|
238
|
+
|
239
|
+
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
240
|
+
expect(proxy.type).to eq(:manual)
|
241
|
+
expect(proxy.http).to eq('127.0.0.1:8080')
|
242
|
+
expect(proxy.ssl).to eq('127.0.0.1:443')
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'builds a Proxy from Hash and adds to Options' do
|
246
|
+
proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
|
247
|
+
options = {unhandled_prompt_behavior: :accept,
|
248
|
+
page_load_strategy: :eager}
|
249
|
+
|
250
|
+
capabilities = described_class.new(browser_symbol, options: options, proxy: proxy)
|
251
|
+
args = capabilities.to_args
|
252
|
+
actual_options = args.last[:options]
|
253
|
+
|
254
|
+
expect(actual_options.proxy).to be_a Selenium::WebDriver::Proxy
|
255
|
+
expect(actual_options.proxy.type).to eq(:manual)
|
256
|
+
expect(actual_options.proxy.http).to eq('127.0.0.1:8080')
|
257
|
+
expect(actual_options.proxy.ssl).to eq('127.0.0.1:443')
|
258
|
+
expect(actual_options.unhandled_prompt_behavior).to eq :accept
|
259
|
+
expect(actual_options.page_load_strategy).to eq :eager
|
260
|
+
end
|
138
261
|
end
|
139
|
-
end
|
140
262
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
args = capabilities.to_args
|
145
|
-
expect(args.last[:listener]).to eq listener
|
146
|
-
end
|
263
|
+
it 'errors on bad proxy key' do
|
264
|
+
proxy = {bad_key: 'foo'}
|
265
|
+
capabilities = described_class.new(browser_symbol, proxy: proxy)
|
147
266
|
|
148
|
-
|
149
|
-
|
150
|
-
opts = options_class(browser_symbol).new
|
267
|
+
expect { capabilities.to_args }.to raise_error(ArgumentError, /unknown option/)
|
268
|
+
end
|
151
269
|
|
152
|
-
|
153
|
-
|
154
|
-
|
270
|
+
it 'errors on bad proxy object' do
|
271
|
+
capabilities = described_class.new(browser_symbol, proxy: 7)
|
272
|
+
expect {
|
273
|
+
capabilities.to_args
|
274
|
+
}.to raise_exception(TypeError, '7 needs to be Selenium Proxy or Hash instance')
|
275
|
+
end
|
155
276
|
end
|
156
277
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
278
|
+
# Options:
|
279
|
+
# :url (Required)
|
280
|
+
# :service (Errors)
|
281
|
+
# :listener
|
282
|
+
# :http_client (Generated or Built from Hash)
|
283
|
+
# :proxy (Built from Hash and added to :options)
|
284
|
+
# :options (Generated or Built from Hash)
|
285
|
+
# :capabilities (incompatible with options)
|
286
|
+
|
287
|
+
describe 'Remote execution' do
|
288
|
+
it 'with just url' do
|
289
|
+
capabilities = described_class.new(url: 'http://example.com')
|
162
290
|
args = capabilities.to_args
|
163
|
-
|
164
|
-
|
165
|
-
expect(actual_options.
|
291
|
+
expect(args.first).to eq :remote
|
292
|
+
actual_options = args.last[:options]
|
293
|
+
expect(actual_options.browser_name).to eq 'chrome'
|
166
294
|
end
|
167
295
|
|
168
|
-
it 'has
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
expect
|
173
|
-
|
174
|
-
|
175
|
-
end
|
296
|
+
it 'just url & browser name has capabilities and client but not service' do
|
297
|
+
capabilities = described_class.new(:firefox,
|
298
|
+
url: 'https://example.com/wd/hub/')
|
299
|
+
args = capabilities.to_args
|
300
|
+
expect(args.first).to eq :remote
|
301
|
+
expect(args.last[:url]).to eq 'https://example.com/wd/hub/'
|
302
|
+
expect(args.last[:http_client]).to be_a HttpClient
|
176
303
|
|
177
|
-
|
178
|
-
|
179
|
-
expect {
|
180
|
-
capabilities = Watir::Capabilities.new(browser_symbol, options: options)
|
181
|
-
capabilities.to_args
|
182
|
-
}.to have_deprecated_timeouts('timeouts has been deprecated, use script_timeout (in seconds) directly instead')
|
304
|
+
expect(args.last[:options]).to be_a Selenium::WebDriver::Firefox::Options
|
305
|
+
expect(args.last).not_to include(:service)
|
183
306
|
end
|
184
307
|
|
185
|
-
it '
|
186
|
-
|
187
|
-
capabilities =
|
188
|
-
|
189
|
-
|
190
|
-
|
308
|
+
it 'accepts a listener' do
|
309
|
+
listener = Selenium::WebDriver::Support::AbstractEventListener.new
|
310
|
+
capabilities = described_class.new(:chrome,
|
311
|
+
url: 'http://example.com/wd/hub/',
|
312
|
+
listener: listener)
|
313
|
+
args = capabilities.to_args
|
314
|
+
expect(args.last[:listener]).to eq listener
|
191
315
|
end
|
192
|
-
end
|
193
316
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
317
|
+
it 'accepts http client object' do
|
318
|
+
client = HttpClient.new
|
319
|
+
capabilities = described_class.new(:chrome,
|
320
|
+
url: 'https://example.com/wd/hub',
|
321
|
+
http_client: client)
|
322
|
+
args = capabilities.to_args
|
323
|
+
expect(args.first).to eq :remote
|
324
|
+
expect(args.last[:http_client]).to eq client
|
325
|
+
actual_options = args.last[:options]
|
326
|
+
expect(actual_options.browser_name).to eq 'chrome'
|
327
|
+
end
|
200
328
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
329
|
+
it 'accepts http client Hash' do
|
330
|
+
capabilities = described_class.new(:chrome,
|
331
|
+
url: 'https://example.com/wd/hub',
|
332
|
+
http_client: {read_timeout: 30})
|
333
|
+
args = capabilities.to_args
|
334
|
+
expect(args.first).to eq :remote
|
335
|
+
expect(args.last[:http_client].instance_variable_get(:@read_timeout)).to eq 30
|
336
|
+
actual_options = args.last[:options]
|
337
|
+
expect(actual_options.browser_name).to eq 'chrome'
|
338
|
+
end
|
207
339
|
|
208
|
-
|
209
|
-
it 'adds Selenium Proxy to empty Options' do
|
340
|
+
it 'accepts proxy object' do
|
210
341
|
proxy = Selenium::WebDriver::Proxy.new(http: '127.0.0.1:8080', ssl: '127.0.0.1:443')
|
211
|
-
capabilities =
|
342
|
+
capabilities = described_class.new(:chrome,
|
343
|
+
url: 'https://example.com/wd/hub',
|
344
|
+
proxy: proxy)
|
212
345
|
args = capabilities.to_args
|
213
|
-
|
214
|
-
|
346
|
+
expect(args.first).to eq :remote
|
347
|
+
proxy = args.last[:options].proxy
|
215
348
|
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
216
349
|
expect(proxy.type).to eq(:manual)
|
217
350
|
expect(proxy.http).to eq('127.0.0.1:8080')
|
218
351
|
expect(proxy.ssl).to eq('127.0.0.1:443')
|
219
352
|
end
|
220
353
|
|
221
|
-
it '
|
354
|
+
it 'accepts proxy Hash' do
|
222
355
|
proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
|
223
|
-
capabilities =
|
356
|
+
capabilities = described_class.new(:chrome,
|
357
|
+
url: 'https://example.com/wd/hub',
|
358
|
+
proxy: proxy)
|
224
359
|
args = capabilities.to_args
|
225
|
-
|
226
|
-
|
360
|
+
expect(args.first).to eq :remote
|
361
|
+
proxy = args.last[:options].proxy
|
227
362
|
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
228
363
|
expect(proxy.type).to eq(:manual)
|
229
364
|
expect(proxy.http).to eq('127.0.0.1:8080')
|
230
365
|
expect(proxy.ssl).to eq('127.0.0.1:443')
|
231
366
|
end
|
232
367
|
|
233
|
-
it '
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
capabilities = Watir::Capabilities.new(browser_symbol, options: options, proxy: proxy)
|
368
|
+
it 'accepts options object' do
|
369
|
+
capabilities = described_class.new(:chrome,
|
370
|
+
url: 'https://example.com/wd/hub',
|
371
|
+
options: Selenium::WebDriver::Chrome::Options.new(args: ['--foo']))
|
239
372
|
args = capabilities.to_args
|
240
|
-
|
241
|
-
|
242
|
-
expect(actual_options.
|
243
|
-
expect(actual_options.
|
244
|
-
expect(actual_options.proxy.http).to eq('127.0.0.1:8080')
|
245
|
-
expect(actual_options.proxy.ssl).to eq('127.0.0.1:443')
|
246
|
-
expect(actual_options.unhandled_prompt_behavior).to eq :accept
|
247
|
-
expect(actual_options.page_load_strategy).to eq :eager
|
373
|
+
expect(args.first).to eq :remote
|
374
|
+
actual_options = args.last[:options]
|
375
|
+
expect(actual_options.browser_name).to eq 'chrome'
|
376
|
+
expect(actual_options.args).to include('--foo')
|
248
377
|
end
|
249
|
-
end
|
250
|
-
|
251
|
-
it 'errors on bad proxy key' do
|
252
|
-
proxy = {bad_key: 'foo'}
|
253
|
-
capabilities = Watir::Capabilities.new(browser_symbol, proxy: proxy)
|
254
|
-
|
255
|
-
expect { capabilities.to_args }.to raise_error(ArgumentError, /unknown option/)
|
256
|
-
end
|
257
378
|
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
# :http_client (Generated or Built from Hash)
|
271
|
-
# :proxy (Built from Hash and added to :options)
|
272
|
-
# :options (Generated or Built from Hash)
|
273
|
-
# :capabilities (incompatible with options)
|
274
|
-
|
275
|
-
describe 'Remote execution' do
|
276
|
-
it 'with just url' do
|
277
|
-
capabilities = Watir::Capabilities.new(url: 'http://example.com')
|
278
|
-
args = capabilities.to_args
|
279
|
-
expect(args.first).to eq :remote
|
280
|
-
actual_options = args.last[:capabilities].first
|
281
|
-
expect(actual_options.browser_name).to eq 'chrome'
|
282
|
-
end
|
283
|
-
|
284
|
-
it 'just url & browser name has capabilities and client but not service' do
|
285
|
-
capabilities = Watir::Capabilities.new(:firefox,
|
286
|
-
url: 'https://example.com/wd/hub/')
|
287
|
-
args = capabilities.to_args
|
288
|
-
expect(args.first).to eq :remote
|
289
|
-
expect(args.last[:url]).to eq 'https://example.com/wd/hub/'
|
290
|
-
expect(args.last[:http_client]).to be_a Watir::HttpClient
|
291
|
-
|
292
|
-
expect(args.last[:capabilities].first).to be_a Selenium::WebDriver::Firefox::Options
|
293
|
-
expect(args.last).not_to include(:service)
|
294
|
-
end
|
295
|
-
|
296
|
-
it 'accepts a listener' do
|
297
|
-
listener = Selenium::WebDriver::Support::AbstractEventListener.new
|
298
|
-
capabilities = Watir::Capabilities.new(:chrome,
|
299
|
-
url: 'http://example.com/wd/hub/',
|
300
|
-
listener: listener)
|
301
|
-
args = capabilities.to_args
|
302
|
-
expect(args.last[:listener]).to eq listener
|
303
|
-
end
|
304
|
-
|
305
|
-
it 'accepts http client object' do
|
306
|
-
client = Watir::HttpClient.new
|
307
|
-
capabilities = Watir::Capabilities.new(:chrome,
|
308
|
-
url: 'https://example.com/wd/hub',
|
309
|
-
http_client: client)
|
310
|
-
args = capabilities.to_args
|
311
|
-
expect(args.first).to eq :remote
|
312
|
-
expect(args.last[:http_client]).to eq client
|
313
|
-
actual_options = args.last[:capabilities].first
|
314
|
-
expect(actual_options.browser_name).to eq 'chrome'
|
315
|
-
end
|
316
|
-
|
317
|
-
it 'accepts http client Hash' do
|
318
|
-
capabilities = Watir::Capabilities.new(:chrome,
|
319
|
-
url: 'https://example.com/wd/hub',
|
320
|
-
http_client: {read_timeout: 30})
|
321
|
-
args = capabilities.to_args
|
322
|
-
expect(args.first).to eq :remote
|
323
|
-
expect(args.last[:http_client].instance_variable_get('@read_timeout')).to eq 30
|
324
|
-
actual_options = args.last[:capabilities].first
|
325
|
-
expect(actual_options.browser_name).to eq 'chrome'
|
326
|
-
end
|
327
|
-
|
328
|
-
it 'accepts proxy object' do
|
329
|
-
proxy = Selenium::WebDriver::Proxy.new(http: '127.0.0.1:8080', ssl: '127.0.0.1:443')
|
330
|
-
capabilities = Watir::Capabilities.new(:chrome,
|
331
|
-
url: 'https://example.com/wd/hub',
|
332
|
-
proxy: proxy)
|
333
|
-
args = capabilities.to_args
|
334
|
-
expect(args.first).to eq :remote
|
335
|
-
proxy = args.last[:capabilities].first.proxy
|
336
|
-
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
337
|
-
expect(proxy.type).to eq(:manual)
|
338
|
-
expect(proxy.http).to eq('127.0.0.1:8080')
|
339
|
-
expect(proxy.ssl).to eq('127.0.0.1:443')
|
340
|
-
end
|
341
|
-
|
342
|
-
it 'accepts proxy Hash' do
|
343
|
-
proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
|
344
|
-
capabilities = Watir::Capabilities.new(:chrome,
|
345
|
-
url: 'https://example.com/wd/hub',
|
346
|
-
proxy: proxy)
|
347
|
-
args = capabilities.to_args
|
348
|
-
expect(args.first).to eq :remote
|
349
|
-
proxy = args.last[:capabilities].first.proxy
|
350
|
-
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
351
|
-
expect(proxy.type).to eq(:manual)
|
352
|
-
expect(proxy.http).to eq('127.0.0.1:8080')
|
353
|
-
expect(proxy.ssl).to eq('127.0.0.1:443')
|
354
|
-
end
|
355
|
-
|
356
|
-
it 'accepts options object' do
|
357
|
-
capabilities = Watir::Capabilities.new(:chrome,
|
358
|
-
url: 'https://example.com/wd/hub',
|
359
|
-
options: Selenium::WebDriver::Chrome::Options.new(args: ['--foo']))
|
360
|
-
args = capabilities.to_args
|
361
|
-
expect(args.first).to eq :remote
|
362
|
-
actual_options = args.last[:capabilities].first
|
363
|
-
expect(actual_options.browser_name).to eq 'chrome'
|
364
|
-
expect(actual_options.args).to include('--foo')
|
365
|
-
end
|
366
|
-
|
367
|
-
it 'accepts options hash' do
|
368
|
-
options = {prefs: {foo: 'bar'}}
|
369
|
-
capabilities = Watir::Capabilities.new(:chrome,
|
370
|
-
url: 'http://example.com',
|
371
|
-
options: options)
|
372
|
-
args = capabilities.to_args
|
373
|
-
expect(args.first).to eq :remote
|
374
|
-
expect(args.last[:url]).to eq 'http://example.com'
|
375
|
-
actual_options = args.last[:capabilities].first
|
376
|
-
expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
|
377
|
-
expect(actual_options.prefs).to eq(foo: 'bar')
|
378
|
-
end
|
379
|
-
|
380
|
-
it 'accepts capabilities object' do
|
381
|
-
caps = Watir::Capabilities.new(:chrome,
|
382
|
-
url: 'https://example.com/wd/hub',
|
383
|
-
capabilities: Selenium::WebDriver::Remote::Capabilities.chrome)
|
384
|
-
args = caps.to_args
|
385
|
-
expect(args.first).to eq :remote
|
386
|
-
actual_capabilities = args.last[:capabilities]
|
387
|
-
expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
|
388
|
-
expect(actual_capabilities.browser_name).to eq 'chrome'
|
389
|
-
end
|
390
|
-
|
391
|
-
it 'accepts http client & capabilities objects' do
|
392
|
-
client = Watir::HttpClient.new
|
393
|
-
caps = Watir::Capabilities.new(:chrome,
|
394
|
-
url: 'https://example.com/wd/hub',
|
395
|
-
capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
|
396
|
-
http_client: client)
|
397
|
-
|
398
|
-
args = caps.to_args
|
399
|
-
expect(args.first).to eq :remote
|
400
|
-
expect(args.last[:http_client]).to eq client
|
401
|
-
actual_capabilities = args.last[:capabilities]
|
402
|
-
expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
|
403
|
-
expect(actual_capabilities.browser_name).to eq 'chrome'
|
404
|
-
end
|
405
|
-
|
406
|
-
it 'accepts http client & proxy & options objects' do
|
407
|
-
client = Watir::HttpClient.new
|
408
|
-
proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
|
409
|
-
options = Selenium::WebDriver::Chrome::Options.new(prefs: {foo: 'bar'})
|
410
|
-
caps = Watir::Capabilities.new(:chrome,
|
411
|
-
url: 'https://example.com/wd/hub',
|
412
|
-
proxy: proxy,
|
413
|
-
options: options,
|
414
|
-
http_client: client)
|
415
|
-
|
416
|
-
args = caps.to_args
|
417
|
-
expect(args.first).to eq :remote
|
418
|
-
expect(args.last[:http_client]).to eq client
|
419
|
-
actual_options = args.last[:capabilities].first
|
420
|
-
expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
|
421
|
-
expect(actual_options.prefs).to eq(foo: 'bar')
|
422
|
-
proxy = args.last[:capabilities].first.proxy
|
423
|
-
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
424
|
-
expect(proxy.type).to eq(:manual)
|
425
|
-
expect(proxy.http).to eq('127.0.0.1:8080')
|
426
|
-
expect(proxy.ssl).to eq('127.0.0.1:443')
|
427
|
-
end
|
379
|
+
it 'accepts options hash' do
|
380
|
+
options = {prefs: {foo: 'bar'}}
|
381
|
+
capabilities = described_class.new(:chrome,
|
382
|
+
url: 'http://example.com',
|
383
|
+
options: options)
|
384
|
+
args = capabilities.to_args
|
385
|
+
expect(args.first).to eq :remote
|
386
|
+
expect(args.last[:url]).to eq 'http://example.com'
|
387
|
+
actual_options = args.last[:options]
|
388
|
+
expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
|
389
|
+
expect(actual_options.prefs).to eq(foo: 'bar')
|
390
|
+
end
|
428
391
|
|
429
|
-
|
430
|
-
|
392
|
+
it 'accepts capabilities object' do
|
393
|
+
caps = described_class.new(:chrome,
|
394
|
+
url: 'https://example.com/wd/hub',
|
395
|
+
capabilities: Selenium::WebDriver::Remote::Capabilities.chrome)
|
396
|
+
args = []
|
397
|
+
expect {
|
398
|
+
args = caps.to_args
|
399
|
+
}.to have_deprecated(:capabilities)
|
431
400
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
}.to raise_exception(ArgumentError, ':capabilities and :options are not both allowed')
|
438
|
-
end
|
401
|
+
expect(args.first).to eq :remote
|
402
|
+
actual_capabilities = args.last[:capabilities]
|
403
|
+
expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
|
404
|
+
expect(actual_capabilities.browser_name).to eq 'chrome'
|
405
|
+
end
|
439
406
|
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
407
|
+
it 'accepts http client & capabilities objects' do
|
408
|
+
client = HttpClient.new
|
409
|
+
caps = described_class.new(:chrome,
|
410
|
+
url: 'https://example.com/wd/hub',
|
411
|
+
capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
|
412
|
+
http_client: client)
|
413
|
+
args = []
|
414
|
+
expect {
|
415
|
+
args = caps.to_args
|
416
|
+
}.to have_deprecated(:capabilities)
|
448
417
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
418
|
+
expect(args.first).to eq :remote
|
419
|
+
expect(args.last[:http_client]).to eq client
|
420
|
+
actual_capabilities = args.last[:capabilities]
|
421
|
+
expect(actual_capabilities).to be_a(Selenium::WebDriver::Remote::Capabilities)
|
422
|
+
expect(actual_capabilities.browser_name).to eq 'chrome'
|
423
|
+
end
|
454
424
|
|
455
|
-
|
456
|
-
|
425
|
+
it 'accepts http client & proxy & options objects' do
|
426
|
+
client = HttpClient.new
|
427
|
+
proxy = {http: '127.0.0.1:8080', ssl: '127.0.0.1:443'}
|
428
|
+
options = Selenium::WebDriver::Chrome::Options.new(prefs: {foo: 'bar'})
|
429
|
+
caps = described_class.new(:chrome,
|
430
|
+
url: 'https://example.com/wd/hub',
|
431
|
+
proxy: proxy,
|
432
|
+
options: options,
|
433
|
+
http_client: client)
|
434
|
+
|
435
|
+
args = caps.to_args
|
436
|
+
expect(args.first).to eq :remote
|
437
|
+
expect(args.last[:http_client]).to eq client
|
438
|
+
actual_options = args.last[:options]
|
439
|
+
expect(actual_options).to be_a(Selenium::WebDriver::Chrome::Options)
|
440
|
+
expect(actual_options.prefs).to eq(foo: 'bar')
|
441
|
+
proxy = args.last[:options].proxy
|
442
|
+
expect(proxy).to be_a Selenium::WebDriver::Proxy
|
443
|
+
expect(proxy.type).to eq(:manual)
|
444
|
+
expect(proxy.http).to eq('127.0.0.1:8080')
|
445
|
+
expect(proxy.ssl).to eq('127.0.0.1:443')
|
446
|
+
end
|
457
447
|
|
458
|
-
|
459
|
-
|
460
|
-
access_key: ENV['SAUCE_ACCESS_KEY']}}
|
461
|
-
other_options = {'other:options': {foo: 'bar'}}
|
448
|
+
it 'raises exception when both options & capabilities defined' do
|
449
|
+
options = {prefs: {foo: 'bar'}}
|
462
450
|
|
463
|
-
|
464
|
-
|
465
|
-
|
451
|
+
expect {
|
452
|
+
described_class.new(:chrome,
|
453
|
+
url: 'https://example.com/wd/hub',
|
454
|
+
capabilities: Selenium::WebDriver::Remote::Capabilities.chrome,
|
455
|
+
options: options)
|
456
|
+
}.to raise_exception(ArgumentError, ':capabilities and :options are not both allowed')
|
457
|
+
end
|
466
458
|
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
459
|
+
it 'allows headless to be set in chrome' do
|
460
|
+
capabilities = described_class.new(:chrome,
|
461
|
+
headless: true,
|
462
|
+
url: 'http://example.com')
|
463
|
+
args = capabilities.to_args
|
464
|
+
actual_options = args.last[:options]
|
465
|
+
expect(actual_options.args).to include '--headless', '--disable-gpu'
|
466
|
+
end
|
473
467
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
expect(args.last[:capabilities].first).to be_a Selenium::WebDriver::Chrome::Options
|
480
|
-
expect(args.last).not_to include(:service)
|
481
|
-
end
|
468
|
+
it 'allows headless to be set in firefox' do
|
469
|
+
capabilities = described_class.new(:firefox,
|
470
|
+
headless: true,
|
471
|
+
url: 'http://example.com')
|
472
|
+
args = capabilities.to_args
|
482
473
|
|
483
|
-
|
484
|
-
|
485
|
-
args = capabilities.to_args
|
486
|
-
actual_options = args.last[:capabilities].first
|
487
|
-
expect(actual_options.args).to include '--headless', '--disable-gpu'
|
488
|
-
end
|
474
|
+
expect(args.last[:options].args).to include '-headless'
|
475
|
+
end
|
489
476
|
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
477
|
+
it 'supports multiple vendor capabilities' do
|
478
|
+
sauce_options = {'sauce:options': {username: ENV.fetch('SAUCE_USERNAME', nil),
|
479
|
+
access_key: ENV.fetch('SAUCE_ACCESS_KEY', nil)}}
|
480
|
+
other_options = {'other:options': {foo: 'bar'}}
|
481
|
+
|
482
|
+
capabilities = described_class.new(:chrome,
|
483
|
+
options: sauce_options.merge(other_options),
|
484
|
+
url: 'https://ondemand.us-west-1.saucelabs.com')
|
485
|
+
|
486
|
+
generated_options = capabilities.to_args.last[:options]
|
487
|
+
expect(generated_options).to be_a(Selenium::WebDriver::Chrome::Options)
|
488
|
+
expect(generated_options.unhandled_prompt_behavior).to eq :ignore
|
489
|
+
actual_options = generated_options.instance_variable_get(:@options)
|
490
|
+
expect(actual_options[:'sauce:options']).to eq sauce_options[:'sauce:options']
|
491
|
+
expect(actual_options[:'other:options']).to eq other_options[:'other:options']
|
492
|
+
end
|
497
493
|
end
|
498
494
|
|
499
|
-
|
500
|
-
options
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
end
|
495
|
+
describe 'chrome' do
|
496
|
+
it 'by default uses chrome, has client, options, but not capabilities' do
|
497
|
+
capabilities = described_class.new
|
498
|
+
args = capabilities.to_args
|
499
|
+
expect(args.last[:http_client]).to be_a HttpClient
|
500
|
+
expect(args.last[:options]).to be_a Selenium::WebDriver::Chrome::Options
|
501
|
+
expect(args.last).not_to include(:service)
|
502
|
+
end
|
508
503
|
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
expect(actual_options.args).to include '--foo', '--bar'
|
516
|
-
end
|
504
|
+
it 'sets headless by creating options' do
|
505
|
+
capabilities = described_class.new(:chrome, headless: true)
|
506
|
+
args = capabilities.to_args
|
507
|
+
actual_options = args.last[:options]
|
508
|
+
expect(actual_options.args).to include '--headless', '--disable-gpu'
|
509
|
+
end
|
517
510
|
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
expect(actual_options.args).to include '--foo', '--bar'
|
527
|
-
end
|
528
|
-
end
|
511
|
+
it 'sets headless in existing options class' do
|
512
|
+
capabilities = described_class.new(:chrome,
|
513
|
+
options: Selenium::WebDriver::Chrome::Options.new,
|
514
|
+
headless: true)
|
515
|
+
args = capabilities.to_args
|
516
|
+
actual_options = args.last[:options]
|
517
|
+
expect(actual_options.args).to include '--headless', '--disable-gpu'
|
518
|
+
end
|
529
519
|
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
520
|
+
it 'sets headless when existing options is a Hash' do
|
521
|
+
options = {args: ['--foo']}
|
522
|
+
capabilities = described_class.new(:chrome,
|
523
|
+
options: options,
|
524
|
+
headless: true)
|
525
|
+
args = capabilities.to_args
|
526
|
+
actual_options = args.last[:options]
|
527
|
+
expect(actual_options.args).to include '--headless', '--disable-gpu', '--foo'
|
528
|
+
end
|
534
529
|
|
535
|
-
|
530
|
+
it 'generates options from Hash' do
|
531
|
+
options = {args: %w[--foo --bar]}
|
532
|
+
capabilities = described_class.new(:chrome, options: options)
|
533
|
+
args = capabilities.to_args
|
534
|
+
actual_options = args.last[:options]
|
535
|
+
expect(actual_options).to be_a Selenium::WebDriver::Chrome::Options
|
536
|
+
expect(actual_options.args).to include '--foo', '--bar'
|
537
|
+
end
|
536
538
|
|
537
|
-
|
538
|
-
|
539
|
-
|
539
|
+
it 'accepts browser and w3c capabilities in options Hash' do
|
540
|
+
opts = {page_load_strategy: 'eager',
|
541
|
+
args: %w[--foo --bar]}
|
542
|
+
capabilities = described_class.new(:chrome,
|
543
|
+
options: opts)
|
544
|
+
args = capabilities.to_args
|
545
|
+
actual_options = args.last[:options]
|
546
|
+
expect(actual_options.page_load_strategy).to eq 'eager'
|
547
|
+
expect(actual_options.args).to include '--foo', '--bar'
|
548
|
+
end
|
540
549
|
end
|
541
550
|
|
542
|
-
|
543
|
-
|
544
|
-
|
551
|
+
describe 'firefox' do
|
552
|
+
it 'puts Profile inside Options as Hash' do
|
553
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
554
|
+
options = {args: ['--foo'], profile: profile}
|
545
555
|
|
546
|
-
|
556
|
+
capabilities = described_class.new(:firefox, options: options)
|
547
557
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
558
|
+
actual_options = capabilities.to_args.last[:options]
|
559
|
+
expect(actual_options.args).to include '--foo'
|
560
|
+
expect(actual_options.profile).to eq profile
|
561
|
+
end
|
552
562
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
563
|
+
it 'sets headless by creating options' do
|
564
|
+
capabilities = described_class.new(:firefox, headless: true)
|
565
|
+
args = capabilities.to_args
|
566
|
+
actual_options = args.last[:options]
|
567
|
+
expect(actual_options.args).to include '-headless'
|
568
|
+
end
|
559
569
|
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
570
|
+
it 'sets headless in existing options class' do
|
571
|
+
capabilities = described_class.new(:firefox,
|
572
|
+
options: Selenium::WebDriver::Firefox::Options.new,
|
573
|
+
headless: true)
|
574
|
+
args = capabilities.to_args
|
575
|
+
actual_options = args.last[:options]
|
576
|
+
expect(actual_options.args).to include '-headless'
|
577
|
+
end
|
568
578
|
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
579
|
+
it 'sets headless when existing options is a Hash' do
|
580
|
+
options = {args: ['-foo']}
|
581
|
+
capabilities = described_class.new(:firefox,
|
582
|
+
options: options,
|
583
|
+
headless: true)
|
584
|
+
args = capabilities.to_args
|
585
|
+
actual_options = args.last[:options]
|
586
|
+
expect(actual_options.args).to include '-headless', '-foo'
|
587
|
+
end
|
578
588
|
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
589
|
+
it 'generates Options instance from Hash' do
|
590
|
+
options = {args: %w[--foo --bar]}
|
591
|
+
capabilities = described_class.new(:firefox, options: options)
|
592
|
+
args = capabilities.to_args
|
593
|
+
actual_options = args.last[:options]
|
594
|
+
expect(actual_options).to be_a Selenium::WebDriver::Firefox::Options
|
595
|
+
expect(actual_options.args).to include '--foo', '--bar'
|
596
|
+
end
|
587
597
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
598
|
+
it 'accepts browser and w3c capabilities in options Hash' do
|
599
|
+
opts = {page_load_strategy: 'eager',
|
600
|
+
args: %w[--foo --bar]}
|
601
|
+
capabilities = described_class.new(:firefox,
|
602
|
+
options: opts)
|
603
|
+
args = capabilities.to_args
|
604
|
+
actual_options = args.last[:options]
|
605
|
+
expect(actual_options.args).to include '--foo', '--bar'
|
606
|
+
expect(actual_options.page_load_strategy).to eq 'eager'
|
607
|
+
end
|
597
608
|
end
|
598
|
-
end
|
599
609
|
|
600
|
-
|
601
|
-
|
602
|
-
|
610
|
+
describe 'safari' do
|
611
|
+
it 'sets Technology Preview' do
|
612
|
+
halt_service(:safari)
|
603
613
|
|
604
|
-
|
614
|
+
described_class.new(:safari, technology_preview: true).to_args
|
605
615
|
|
606
|
-
|
607
|
-
|
616
|
+
expect(Selenium::WebDriver::Safari.technology_preview?).to be true
|
617
|
+
end
|
608
618
|
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
619
|
+
it 'generates options from Hash' do
|
620
|
+
options = {automatic_inspection: true}
|
621
|
+
capabilities = described_class.new(:safari, options: options)
|
622
|
+
args = capabilities.to_args
|
623
|
+
actual_options = args.last[:options]
|
624
|
+
expect(actual_options).to be_a Selenium::WebDriver::Safari::Options
|
625
|
+
expect(actual_options.automatic_inspection).to be true
|
626
|
+
end
|
617
627
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
628
|
+
it 'accepts browser and w3c capabilities in options Hash' do
|
629
|
+
opts = {page_load_strategy: 'eager',
|
630
|
+
automatic_inspection: true}
|
631
|
+
capabilities = described_class.new(:safari,
|
632
|
+
options: opts)
|
633
|
+
args = capabilities.to_args
|
634
|
+
actual_options = args.last[:options]
|
635
|
+
expect(actual_options.automatic_inspection).to be true
|
636
|
+
expect(actual_options.page_load_strategy).to eq 'eager'
|
637
|
+
end
|
627
638
|
end
|
628
|
-
end
|
629
639
|
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
640
|
+
describe 'ie' do
|
641
|
+
it 'generates Options instance from Hash with args' do
|
642
|
+
options = {args: %w[--foo --bar]}
|
643
|
+
capabilities = described_class.new(:ie, options: options)
|
644
|
+
args = capabilities.to_args
|
645
|
+
actual_options = args.last[:options]
|
646
|
+
expect(actual_options).to be_a Selenium::WebDriver::IE::Options
|
647
|
+
expect(actual_options.args).to include '--foo', '--bar'
|
648
|
+
end
|
639
649
|
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
650
|
+
it 'generates Options instance from Hash with valid option' do
|
651
|
+
options = {browser_attach_timeout: true}
|
652
|
+
capabilities = described_class.new(:ie, options: options)
|
653
|
+
args = capabilities.to_args
|
654
|
+
actual_options = args.last[:options]
|
655
|
+
expect(actual_options).to be_a Selenium::WebDriver::IE::Options
|
656
|
+
expect(actual_options.options[:browser_attach_timeout]).to be true
|
657
|
+
end
|
648
658
|
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
659
|
+
it 'accepts browser and w3c capabilities in options Hash' do
|
660
|
+
opts = {page_load_strategy: 'eager',
|
661
|
+
args: ['--foo']}
|
662
|
+
capabilities = described_class.new(:ie,
|
663
|
+
options: opts)
|
664
|
+
args = capabilities.to_args
|
665
|
+
actual_options = args.last[:options]
|
666
|
+
expect(actual_options.args).to include '--foo'
|
667
|
+
expect(actual_options.page_load_strategy).to eq 'eager'
|
668
|
+
end
|
658
669
|
end
|
659
670
|
end
|
660
671
|
end
|