watir 6.18.0 → 7.0.0.beta3
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/.github/actions/install-chrome/action.yml +1 -0
- data/.github/actions/setup-linux/action.yml +8 -0
- data/.github/workflows/tests.yml +104 -0
- data/.rubocop.yml +2 -7
- data/CHANGES.md +51 -0
- data/README.md +2 -5
- data/Rakefile +1 -1
- data/lib/watir.rb +3 -45
- data/lib/watir/alert.rb +3 -8
- data/lib/watir/browser.rb +18 -4
- data/lib/watir/capabilities.rb +106 -106
- data/lib/watir/cell_container.rb +4 -4
- data/lib/watir/container.rb +4 -26
- data/lib/watir/elements/checkbox.rb +4 -4
- data/lib/watir/elements/date_field.rb +4 -4
- data/lib/watir/elements/date_time_field.rb +4 -4
- data/lib/watir/elements/element.rb +44 -52
- data/lib/watir/elements/file_field.rb +4 -4
- data/lib/watir/elements/font.rb +5 -4
- data/lib/watir/elements/hidden.rb +4 -4
- data/lib/watir/elements/html_elements.rb +444 -445
- data/lib/watir/elements/iframe.rb +4 -5
- data/lib/watir/elements/radio.rb +6 -6
- data/lib/watir/elements/select.rb +60 -103
- data/lib/watir/elements/svg_elements.rb +96 -96
- data/lib/watir/elements/text_field.rb +4 -4
- data/lib/watir/generator/base/generator.rb +4 -4
- data/lib/watir/generator/base/visitor.rb +0 -29
- data/lib/watir/generator/html/generator.rb +2 -1
- data/lib/watir/has_window.rb +6 -4
- data/lib/watir/http_client.rb +9 -0
- data/lib/watir/locators.rb +5 -5
- data/lib/watir/locators/button/matcher.rb +0 -23
- data/lib/watir/locators/button/selector_builder/xpath.rb +4 -15
- data/lib/watir/locators/element/matcher.rb +4 -19
- data/lib/watir/locators/element/selector_builder.rb +2 -40
- data/lib/watir/locators/element/selector_builder/xpath.rb +34 -41
- data/lib/watir/locators/option/matcher.rb +24 -0
- data/lib/watir/locators/option/selector_builder.rb +8 -0
- data/lib/watir/locators/option/selector_builder/xpath.rb +37 -0
- data/lib/watir/logger.rb +3 -74
- data/lib/watir/radio_set.rb +3 -2
- data/lib/watir/row_container.rb +4 -4
- data/lib/watir/screenshot.rb +2 -8
- data/lib/watir/user_editable.rb +10 -3
- data/lib/watir/version.rb +1 -1
- data/lib/watir/wait.rb +4 -74
- data/lib/watir/window.rb +21 -26
- data/lib/watir/window_collection.rb +21 -47
- data/lib/watirspec.rb +4 -2
- data/lib/watirspec/guards.rb +1 -1
- data/lib/watirspec/implementation.rb +4 -0
- data/lib/watirspec/runner.rb +1 -1
- data/lib/watirspec/server.rb +1 -1
- data/spec/spec_helper.rb +1 -16
- data/spec/unit/capabilities_spec.rb +560 -21
- data/spec/unit/match_elements/button_spec.rb +0 -13
- data/spec/unit/match_elements/element_spec.rb +49 -47
- data/spec/unit/match_elements/text_field_spec.rb +6 -6
- data/spec/unit/selector_builder/element_spec.rb +6 -23
- data/spec/unit/selector_builder/text_field_spec.rb +6 -7
- data/spec/watirspec/after_hooks_spec.rb +22 -45
- data/spec/watirspec/alert_spec.rb +4 -21
- data/spec/watirspec/browser_spec.rb +186 -207
- data/spec/watirspec/cookies_spec.rb +47 -52
- data/spec/watirspec/drag_and_drop_spec.rb +5 -7
- data/spec/watirspec/elements/area_spec.rb +1 -5
- data/spec/watirspec/elements/button_spec.rb +4 -18
- data/spec/watirspec/elements/checkbox_spec.rb +10 -24
- data/spec/watirspec/elements/date_field_spec.rb +13 -16
- data/spec/watirspec/elements/date_time_field_spec.rb +14 -13
- data/spec/watirspec/elements/dd_spec.rb +3 -4
- data/spec/watirspec/elements/del_spec.rb +10 -12
- data/spec/watirspec/elements/div_spec.rb +45 -84
- data/spec/watirspec/elements/divs_spec.rb +2 -2
- data/spec/watirspec/elements/dl_spec.rb +4 -12
- data/spec/watirspec/elements/element_spec.rb +190 -170
- data/spec/watirspec/elements/elements_spec.rb +8 -9
- data/spec/watirspec/elements/filefield_spec.rb +5 -7
- data/spec/watirspec/elements/form_spec.rb +3 -5
- data/spec/watirspec/elements/forms_spec.rb +3 -5
- data/spec/watirspec/elements/frame_spec.rb +17 -22
- data/spec/watirspec/elements/iframe_spec.rb +21 -27
- data/spec/watirspec/elements/ins_spec.rb +10 -12
- data/spec/watirspec/elements/link_spec.rb +24 -26
- data/spec/watirspec/elements/links_spec.rb +8 -9
- data/spec/watirspec/elements/radio_spec.rb +11 -14
- data/spec/watirspec/elements/select_list_spec.rb +253 -223
- data/spec/watirspec/elements/span_spec.rb +12 -14
- data/spec/watirspec/elements/spans_spec.rb +1 -1
- data/spec/watirspec/elements/strong_spec.rb +1 -1
- data/spec/watirspec/elements/table_nesting_spec.rb +31 -34
- data/spec/watirspec/elements/table_spec.rb +11 -13
- data/spec/watirspec/elements/tbody_spec.rb +10 -12
- data/spec/watirspec/elements/td_spec.rb +4 -6
- data/spec/watirspec/elements/text_field_spec.rb +10 -12
- data/spec/watirspec/elements/tr_spec.rb +5 -7
- data/spec/watirspec/html/non_control_elements.html +8 -3
- data/spec/watirspec/html/special_chars.html +3 -0
- data/spec/watirspec/special_chars_spec.rb +10 -0
- data/spec/watirspec/support/rspec_matchers.rb +4 -20
- data/spec/watirspec/user_editable_spec.rb +26 -28
- data/spec/watirspec/wait_spec.rb +255 -258
- data/spec/watirspec/window_switching_spec.rb +212 -245
- data/spec/watirspec_helper.rb +42 -34
- data/watir.gemspec +3 -4
- metadata +16 -37
- data/.github/workflows/linux.yml +0 -61
- data/.github/workflows/mac.yml +0 -55
- data/.github/workflows/unit.yml +0 -31
- data/.github/workflows/windows.yml +0 -39
- data/lib/watir/legacy_wait.rb +0 -123
- data/spec/implementation_spec.rb +0 -24
- data/spec/unit/container_spec.rb +0 -35
- data/spec/unit/logger_spec.rb +0 -81
- data/spec/watirspec/legacy_wait_spec.rb +0 -216
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ebf40b52023085fd593f26f448268e0f00c51dbaf80fc3af9801d9d8c9d7703b
|
|
4
|
+
data.tar.gz: f42ee61445dc9ab61a6d236597bd67c84a2fdd837a5af0cc2236ae1eb6e19467
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61cd3f3f3cf9f3d3739ed006de8b41ad4cf60336953b518e9c993e0fafb09c7dd0d7903bbf2099d562987b91ff1aa4b351108b78767ea98b65e6eb53de78f451
|
|
7
|
+
data.tar.gz: '09017e544063c107aa91865759b4f61366476178b9c55f6b64f6bc81958eb6236d44621baff328ab4587d752a3e99be169ce9cf4be11443354d48dc019d6b04a'
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
name: All Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
- push
|
|
5
|
+
- pull_request
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
documentation-test:
|
|
9
|
+
name: Yard Doctest
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v2
|
|
13
|
+
- uses: ruby/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby-version: 2.6
|
|
16
|
+
- run: bundle install
|
|
17
|
+
- uses: ./.github/actions/install-chrome
|
|
18
|
+
- uses: ./.github/actions/setup-linux
|
|
19
|
+
- run: |
|
|
20
|
+
bundle exec rake yard:doctest
|
|
21
|
+
|
|
22
|
+
unit-test:
|
|
23
|
+
name: Unit Tests
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
strategy:
|
|
26
|
+
fail-fast: false
|
|
27
|
+
matrix:
|
|
28
|
+
ruby: ['2.5', '2.6', '2.7', '3.0']
|
|
29
|
+
steps:
|
|
30
|
+
- uses: actions/checkout@v2
|
|
31
|
+
- uses: ruby/setup-ruby@v1
|
|
32
|
+
with:
|
|
33
|
+
ruby-version: ${{ matrix.ruby }}
|
|
34
|
+
- run: bundle install
|
|
35
|
+
- uses: ./.github/actions/install-chrome
|
|
36
|
+
- uses: ./.github/actions/setup-linux
|
|
37
|
+
- run: |
|
|
38
|
+
bundle exec rake spec:unit
|
|
39
|
+
env:
|
|
40
|
+
DISPLAY: :99
|
|
41
|
+
|
|
42
|
+
linter-test:
|
|
43
|
+
name: Rubocop Tests
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
steps:
|
|
46
|
+
- uses: actions/checkout@v2
|
|
47
|
+
- uses: ruby/setup-ruby@v1
|
|
48
|
+
with:
|
|
49
|
+
ruby-version: 2.6
|
|
50
|
+
- run: bundle install
|
|
51
|
+
- run: bundle exec rubocop
|
|
52
|
+
|
|
53
|
+
local-tests:
|
|
54
|
+
name: Local Tests
|
|
55
|
+
runs-on: ${{ matrix.os }}
|
|
56
|
+
strategy:
|
|
57
|
+
fail-fast: false
|
|
58
|
+
matrix:
|
|
59
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
60
|
+
ruby: [ 2.6, 3.0 ]
|
|
61
|
+
task: [ chrome, firefox, edge ]
|
|
62
|
+
include:
|
|
63
|
+
- os: 'macos-latest'
|
|
64
|
+
ruby: 2.6
|
|
65
|
+
task: 'safari'
|
|
66
|
+
- os: 'macos-latest'
|
|
67
|
+
ruby: 3.0
|
|
68
|
+
task: 'safari'
|
|
69
|
+
- os: 'windows-latest'
|
|
70
|
+
ruby: 2.6
|
|
71
|
+
task: 'ie'
|
|
72
|
+
- os: 'windows-latest'
|
|
73
|
+
ruby: 3.0
|
|
74
|
+
task: 'ie'
|
|
75
|
+
exclude:
|
|
76
|
+
- os: 'ubuntu-latest'
|
|
77
|
+
task: 'edge'
|
|
78
|
+
steps:
|
|
79
|
+
- uses: actions/checkout@v2
|
|
80
|
+
- uses: ./.github/actions/install-chrome
|
|
81
|
+
if: |
|
|
82
|
+
matrix.task == 'chrome' &&
|
|
83
|
+
matrix.os == 'ubuntu-latest'
|
|
84
|
+
- uses: ./.github/actions/setup-linux
|
|
85
|
+
if: matrix.os == 'ubuntu-latest'
|
|
86
|
+
- uses: browser-actions/setup-firefox@latest
|
|
87
|
+
with:
|
|
88
|
+
firefox-version: '86.0'
|
|
89
|
+
if: matrix.task == 'firefox'
|
|
90
|
+
- uses: ./.github/actions/enable-safari
|
|
91
|
+
if: matrix.task == 'safari'
|
|
92
|
+
- run: |
|
|
93
|
+
echo "COVERAGE=true" >> $GITHUB_ENV
|
|
94
|
+
if: |
|
|
95
|
+
matrix.os == 'ubuntu-latest' ||
|
|
96
|
+
matrix.os == 'macos-latest'
|
|
97
|
+
- uses: ruby/setup-ruby@v1
|
|
98
|
+
with:
|
|
99
|
+
ruby-version: ${{ matrix.ruby }}
|
|
100
|
+
- run: bundle install
|
|
101
|
+
- run: |
|
|
102
|
+
bundle exec rake spec:${{ matrix.task }}
|
|
103
|
+
env:
|
|
104
|
+
DISPLAY: :99
|
data/.rubocop.yml
CHANGED
|
@@ -19,17 +19,12 @@ Lint/UnifiedInteger:
|
|
|
19
19
|
|
|
20
20
|
# Default: 17
|
|
21
21
|
Metrics/AbcSize:
|
|
22
|
-
Max:
|
|
22
|
+
Max: 22
|
|
23
23
|
Exclude:
|
|
24
|
-
- 'lib/watir/capabilities.rb'
|
|
25
24
|
- 'lib/watir/locators/element/selector_builder.rb'
|
|
26
|
-
- 'lib/watir/locators/element/selector_builder
|
|
27
|
-
- 'lib/watir/locators/element/selector_builder/xpath.rb'
|
|
28
|
-
- 'lib/watir/locators/element/locator.rb'
|
|
25
|
+
- 'lib/watir/locators/element/selector_builder/*.rb'
|
|
29
26
|
- 'lib/watir/generator/base/generator.rb'
|
|
30
|
-
- 'lib/watir/generator/base/visitor.rb'
|
|
31
27
|
- 'spec/locator_spec_helper.rb'
|
|
32
|
-
- 'spec/watirspec_helper.rb'
|
|
33
28
|
|
|
34
29
|
Metrics/BlockLength:
|
|
35
30
|
Exclude:
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,54 @@
|
|
|
1
|
+
### 7.0.0.beta3 (2021-05-05)
|
|
2
|
+
|
|
3
|
+
* Fix Bug preventing proper use of vendor extension capabilities
|
|
4
|
+
* Changed how timeouts are supported in Watir Capabilities (#932)
|
|
5
|
+
* Changed the default Alert Behavior not to automatically get dismissed when an exception happens (#931)
|
|
6
|
+
|
|
7
|
+
### 7.0.0.beta2 (2021-03-28)
|
|
8
|
+
|
|
9
|
+
* Replace Watir Logger implementation with Selenium Logger subclass
|
|
10
|
+
* Change Watir Guards to use Selenium's new Guards. Tests run as pending when guarded.
|
|
11
|
+
* Implement `#set` as standard interface for each Input Element (#405)
|
|
12
|
+
* Implement `Element#set` to take correct `#set` behavior based on evaluated element (#664)
|
|
13
|
+
* Optimize Performance for Select Lists (#846)
|
|
14
|
+
* Allow user to set values on Select List exclusively by `:label`, `:text`, or `:value` (#846)
|
|
15
|
+
* Allow user to check if option selected in Select List by `:label`, `:text`, or `:value` (#929)
|
|
16
|
+
* Implement `Window#restore!` to return to original Window and close all others (#923)
|
|
17
|
+
* Minor performance improvement for iterating over windows (#923)
|
|
18
|
+
* Implement `Browser#closed?`; same as `Browser#exists?` without the Windows checks (#923)
|
|
19
|
+
* Update methods that use Selenium's Actions class to scroll element into view before acting (#847)
|
|
20
|
+
* Fix bug for `:text` locator with `Regexp` value based on whitespace (#924)
|
|
21
|
+
* Remove executing after hooks when changing frames (#888)
|
|
22
|
+
|
|
23
|
+
### 7.0.0.beta1 (2021-03-18)
|
|
24
|
+
|
|
25
|
+
* Requires Selenium 4
|
|
26
|
+
* Supports Ruby 3
|
|
27
|
+
* Add support for Microsoft Edge Chromium
|
|
28
|
+
* Remove support for all deprecated functionality
|
|
29
|
+
|
|
30
|
+
### 6.19.1 (2021-03-17)
|
|
31
|
+
|
|
32
|
+
* Fix bug preventing using Selenium 4
|
|
33
|
+
* Fix bug preventing non-xml characters in attributes (#787)
|
|
34
|
+
|
|
35
|
+
### 6.19.0 (2021-03-12)
|
|
36
|
+
|
|
37
|
+
* Create custom Watir HTTP Client
|
|
38
|
+
* Require minimum of Selenium 3.142.7
|
|
39
|
+
* Add support for starting browser with :http_client and :service hashes
|
|
40
|
+
* Allow inferring desired browser from Capabilities or Options if browser not specified
|
|
41
|
+
* Deprecate WindowCollection#to_a method
|
|
42
|
+
* Deprecate starting browser with both Capabilities and Options
|
|
43
|
+
* Deprecate starting browser with both URL and Service
|
|
44
|
+
* Deprecate using :desired_capabilities
|
|
45
|
+
* Deprecate starting browser service keywords in top level Hash
|
|
46
|
+
* Deprecate using :remote to start a browser; browser name must be specified
|
|
47
|
+
* Deprecate sending unknown keywords into the top level
|
|
48
|
+
* Fix bug preventing Safari Options from being recognized
|
|
49
|
+
* Fix bug preventing options provided without :remote keyword from being properly recognized (#812, #870)
|
|
50
|
+
* Fix bug preventing :headless from being recognized when :options specified (#692)
|
|
51
|
+
|
|
1
52
|
### 6.18.0 (2021-02-26)
|
|
2
53
|
|
|
3
54
|
* Implement `WindowCollection` to manage multiple `Window` objects
|
data/README.md
CHANGED
|
@@ -3,12 +3,9 @@
|
|
|
3
3
|
Watir Powered By Selenium!
|
|
4
4
|
|
|
5
5
|
[](http://badge.fury.io/rb/watir)
|
|
6
|
-
[](https://github.com/watir/watir/actions?query=workflow%3A%22Mac+Tests%22)
|
|
8
|
-
[](https://github.com/watir/watir/actions?query=workflow%3A%22Windows+Tests%22)
|
|
9
|
-
[](https://github.com/watir/watir/actions?query=workflow%3A%22Linux+Tests%22)
|
|
6
|
+
[](https://github.com/watir/watir/actions/workflows/tests.yml)
|
|
10
7
|
[](https://codeclimate.com/github/watir/watir)
|
|
11
|
-
[](https://coveralls.io/github/watir/watir?branch=
|
|
8
|
+
[](https://coveralls.io/github/watir/watir?branch=main)
|
|
12
9
|
|
|
13
10
|
## Using Watir
|
|
14
11
|
|
data/Rakefile
CHANGED
|
@@ -25,7 +25,7 @@ end
|
|
|
25
25
|
|
|
26
26
|
{
|
|
27
27
|
html: 'https://www.w3.org/TR/html52/single-page.html',
|
|
28
|
-
svg: '
|
|
28
|
+
svg: 'https://www.w3.org/TR/2018/CR-SVG2-20180807/single-page.html'
|
|
29
29
|
}.each do |type, spec_uri|
|
|
30
30
|
namespace type do
|
|
31
31
|
spec_path = "support/#{type}.html"
|
data/lib/watir.rb
CHANGED
|
@@ -2,7 +2,6 @@ require 'selenium-webdriver'
|
|
|
2
2
|
require 'time'
|
|
3
3
|
|
|
4
4
|
require 'watir/scroll'
|
|
5
|
-
require 'watir/legacy_wait'
|
|
6
5
|
require 'watir/wait'
|
|
7
6
|
require 'watir/exception'
|
|
8
7
|
require 'watir/window'
|
|
@@ -14,59 +13,18 @@ require 'watir/alert'
|
|
|
14
13
|
require 'watir/js_snippets'
|
|
15
14
|
require 'watir/container'
|
|
16
15
|
require 'watir/cookies'
|
|
16
|
+
require 'watir/http_client'
|
|
17
17
|
require 'watir/capabilities'
|
|
18
18
|
require 'watir/navigation'
|
|
19
19
|
require 'watir/browser'
|
|
20
20
|
require 'watir/screenshot'
|
|
21
21
|
require 'watir/after_hooks'
|
|
22
22
|
require 'watir/logger'
|
|
23
|
+
require 'watir/version'
|
|
23
24
|
|
|
24
25
|
module Watir
|
|
25
|
-
@relaxed_locate = true
|
|
26
|
-
|
|
27
26
|
class << self
|
|
28
|
-
attr_writer :
|
|
29
|
-
|
|
30
|
-
#
|
|
31
|
-
# Whether or not Watir should wait for an element to be found or present
|
|
32
|
-
# before taking an action.
|
|
33
|
-
# Defaults to true.
|
|
34
|
-
#
|
|
35
|
-
|
|
36
|
-
def relaxed_locate?
|
|
37
|
-
@relaxed_locate
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
#
|
|
41
|
-
# Whether or not Watir should re-locate a stale Element on use.
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
def always_locate?
|
|
45
|
-
always_locate_message
|
|
46
|
-
true
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def always_locate_message
|
|
50
|
-
msg = 'Watir#always_locate'
|
|
51
|
-
repl_msg = 'Element#stale? or Element#wait_until(&:stale?) if needed for flow control'
|
|
52
|
-
Watir.logger.deprecate msg, repl_msg, ids: [:always_locate]
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
#
|
|
56
|
-
# Whether or not Watir should prefer CSS when translating the Watir selector to Selenium.
|
|
57
|
-
#
|
|
58
|
-
|
|
59
|
-
def prefer_css?
|
|
60
|
-
prefer_css_message
|
|
61
|
-
false
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def prefer_css_message
|
|
65
|
-
msg = 'Watir#prefer_css'
|
|
66
|
-
repl_msg = 'watir_css gem - https://github.com/watir/watir_css'
|
|
67
|
-
|
|
68
|
-
Watir.logger.deprecate msg, repl_msg, ids: [:prefer_css]
|
|
69
|
-
end
|
|
27
|
+
attr_writer :default_timeout
|
|
70
28
|
|
|
71
29
|
#
|
|
72
30
|
# Default wait time for wait methods.
|
data/lib/watir/alert.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
module Watir
|
|
2
2
|
class Alert
|
|
3
|
-
include EventuallyPresent
|
|
4
3
|
include Waitable
|
|
5
4
|
include Exception
|
|
6
5
|
|
|
@@ -104,13 +103,9 @@ module Watir
|
|
|
104
103
|
end
|
|
105
104
|
|
|
106
105
|
def wait_for_exists
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
wait_until(message: 'waiting for alert', &:exists?)
|
|
111
|
-
rescue Wait::TimeoutError
|
|
112
|
-
raise UnknownObjectException, 'unable to locate alert'
|
|
113
|
-
end
|
|
106
|
+
wait_until(message: 'waiting for alert', &:exists?)
|
|
107
|
+
rescue Wait::TimeoutError
|
|
108
|
+
raise UnknownObjectException, 'unable to locate alert'
|
|
114
109
|
end
|
|
115
110
|
end # Alert
|
|
116
111
|
end # Watir
|
data/lib/watir/browser.rb
CHANGED
|
@@ -55,16 +55,21 @@ module Watir
|
|
|
55
55
|
@default_context = true
|
|
56
56
|
end
|
|
57
57
|
|
|
58
|
+
# rubocop:disable Metrics/AbcSize
|
|
59
|
+
# TODO: w3c default behavior does not like checking if alert exists
|
|
58
60
|
def inspect
|
|
59
61
|
if alert.exists?
|
|
60
62
|
format('#<%s:0x%x alert=true>', self.class, hash * 2)
|
|
61
63
|
else
|
|
62
64
|
format('#<%s:0x%x url=%s title=%s>', self.class, hash * 2, url.inspect, title.inspect)
|
|
63
65
|
end
|
|
66
|
+
rescue Selenium::WebDriver::Error::NoSuchWindowError
|
|
67
|
+
format('#<%s:0x%x closed=%s>', self.class, hash * 2, closed?)
|
|
64
68
|
rescue Errno::ECONNREFUSED
|
|
65
69
|
format('#<%s:0x%x closed=true>', self.class, hash * 2)
|
|
66
70
|
end
|
|
67
71
|
alias selector_string inspect
|
|
72
|
+
# rubocop:enable Metrics/AbcSize
|
|
68
73
|
|
|
69
74
|
#
|
|
70
75
|
# Returns URL of current page.
|
|
@@ -101,13 +106,23 @@ module Watir
|
|
|
101
106
|
#
|
|
102
107
|
|
|
103
108
|
def close
|
|
104
|
-
return if
|
|
109
|
+
return if closed?
|
|
105
110
|
|
|
106
111
|
@driver.quit
|
|
107
112
|
@closed = true
|
|
108
113
|
end
|
|
109
114
|
alias quit close
|
|
110
115
|
|
|
116
|
+
#
|
|
117
|
+
# Returns true if browser is closed and false otherwise.
|
|
118
|
+
#
|
|
119
|
+
# @return [Boolean]
|
|
120
|
+
#
|
|
121
|
+
|
|
122
|
+
def closed?
|
|
123
|
+
@closed
|
|
124
|
+
end
|
|
125
|
+
|
|
111
126
|
#
|
|
112
127
|
# Handles cookies.
|
|
113
128
|
#
|
|
@@ -252,12 +267,12 @@ module Watir
|
|
|
252
267
|
#
|
|
253
268
|
|
|
254
269
|
def exist?
|
|
255
|
-
|
|
270
|
+
!closed? && window.present?
|
|
256
271
|
end
|
|
257
272
|
alias exists? exist?
|
|
258
273
|
|
|
259
274
|
def locate
|
|
260
|
-
raise Error, 'browser was closed' if
|
|
275
|
+
raise Error, 'browser was closed' if closed?
|
|
261
276
|
|
|
262
277
|
ensure_context
|
|
263
278
|
end
|
|
@@ -267,7 +282,6 @@ module Watir
|
|
|
267
282
|
|
|
268
283
|
driver.switch_to.default_content
|
|
269
284
|
@default_context = true
|
|
270
|
-
after_hooks.run
|
|
271
285
|
end
|
|
272
286
|
|
|
273
287
|
def browser
|
data/lib/watir/capabilities.rb
CHANGED
|
@@ -2,19 +2,23 @@ module Watir
|
|
|
2
2
|
class Capabilities
|
|
3
3
|
attr_reader :options
|
|
4
4
|
|
|
5
|
-
def initialize(browser, options = {})
|
|
5
|
+
def initialize(browser = nil, options = {})
|
|
6
|
+
if browser.is_a?(Hash)
|
|
7
|
+
options = browser
|
|
8
|
+
browser = nil
|
|
9
|
+
end
|
|
10
|
+
|
|
6
11
|
@options = options.dup
|
|
7
12
|
Watir.logger.info "Creating Browser instance of #{browser} with user provided options: #{@options.inspect}"
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@selenium_opts = {}
|
|
13
|
+
|
|
14
|
+
if @options.key?(:capabilities) && @options.key?(:options)
|
|
15
|
+
raise(ArgumentError, ':capabilities and :options are not both allowed')
|
|
16
|
+
end
|
|
17
|
+
raise(ArgumentError, ':url and :service are not both allowed') if @options.key?(:service) && @options.key?(:url)
|
|
18
|
+
|
|
19
|
+
@browser = browser.nil? && infer_browser || browser
|
|
20
|
+
|
|
21
|
+
@selenium_browser = @options.key?(:url) ? :remote : @browser
|
|
18
22
|
end
|
|
19
23
|
|
|
20
24
|
def to_args
|
|
@@ -24,129 +28,125 @@ module Watir
|
|
|
24
28
|
private
|
|
25
29
|
|
|
26
30
|
def process_arguments
|
|
27
|
-
|
|
28
|
-
if
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
selenium_opts = {}
|
|
32
|
+
selenium_opts[:listener] = @options.delete(:listener) if @options.key?(:listener)
|
|
33
|
+
|
|
34
|
+
if @options.key?(:url)
|
|
35
|
+
selenium_opts[:url] = @options.delete(:url)
|
|
36
|
+
else
|
|
37
|
+
service = process_service
|
|
38
|
+
selenium_opts[:service] = service if service
|
|
32
39
|
end
|
|
33
40
|
|
|
34
|
-
|
|
41
|
+
selenium_opts[:http_client] = process_http_client
|
|
42
|
+
selenium_opts[:capabilities] = @options.delete(:capabilities) || process_browser_options
|
|
43
|
+
|
|
44
|
+
Watir.logger.info "Creating Browser instance with Watir processed options: #{selenium_opts.inspect}"
|
|
45
|
+
selenium_opts
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def process_http_client
|
|
49
|
+
http_client = @options.delete(:http_client) || Watir::HttpClient.new
|
|
50
|
+
|
|
51
|
+
case http_client
|
|
52
|
+
when Hash
|
|
53
|
+
Watir::HttpClient.new(**http_client)
|
|
54
|
+
when Watir::HttpClient
|
|
55
|
+
http_client
|
|
56
|
+
when Selenium::WebDriver::Remote::Http::Common
|
|
57
|
+
Watir.logger.warn 'Check out the new Watir::HttpClient and let us know if there are missing features you need',
|
|
58
|
+
id: [:watir_client]
|
|
59
|
+
http_client
|
|
60
|
+
else
|
|
61
|
+
raise TypeError, ':http_client must be a Hash or a Selenium HTTP Client instance'
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def process_browser_options
|
|
66
|
+
browser_options = @options.delete(:options).dup || {}
|
|
67
|
+
vendor_caps = process_vendor_capabilities(browser_options)
|
|
35
68
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
69
|
+
options = if browser_options.is_a? Selenium::WebDriver::Options
|
|
70
|
+
browser_options
|
|
71
|
+
else
|
|
72
|
+
convert_timeouts(browser_options)
|
|
73
|
+
Selenium::WebDriver::Options.send(@browser, **browser_options)
|
|
74
|
+
end
|
|
39
75
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
76
|
+
options.unhandled_prompt_behavior ||= :ignore
|
|
77
|
+
browser_specific_options(options)
|
|
78
|
+
raise ArgumentError, "#{@options} are unrecognized arguments for Browser constructor" unless @options.empty?
|
|
43
79
|
|
|
44
|
-
|
|
80
|
+
vendor_caps << options
|
|
45
81
|
end
|
|
46
82
|
|
|
47
|
-
def
|
|
48
|
-
|
|
49
|
-
open_timeout = @options.delete(:open_timeout)
|
|
50
|
-
read_timeout = @options.delete(:read_timeout)
|
|
83
|
+
def process_vendor_capabilities(opts)
|
|
84
|
+
return [] unless opts.is_a? Hash
|
|
51
85
|
|
|
52
|
-
|
|
86
|
+
vendor = opts.select { |key, _val| key.to_s.include?(':') && opts.delete(key) }
|
|
87
|
+
vendor.map { |k, v| Selenium::WebDriver::Remote::Capabilities.new(k => v) }
|
|
88
|
+
end
|
|
53
89
|
|
|
54
|
-
|
|
55
|
-
|
|
90
|
+
def convert_timeouts(browser_options)
|
|
91
|
+
browser_options[:timeouts] ||= {}
|
|
92
|
+
browser_options[:timeouts].keys.each do |key|
|
|
93
|
+
raise(ArgumentError, 'do not set implicit wait, Watir handles waiting automatically') if key.to_s == 'implicit'
|
|
56
94
|
|
|
57
|
-
|
|
58
|
-
|
|
95
|
+
Watir.logger.deprecate('using timeouts directly in options',
|
|
96
|
+
":#{key}_timeout",
|
|
97
|
+
id: 'timeouts')
|
|
98
|
+
end
|
|
99
|
+
if browser_options.key?(:page_load_timeout)
|
|
100
|
+
browser_options[:timeouts][:page_load] = browser_options.delete(:page_load_timeout) * 1000
|
|
59
101
|
end
|
|
60
102
|
|
|
61
|
-
|
|
103
|
+
return unless browser_options.key?(:script_timeout)
|
|
62
104
|
|
|
63
|
-
|
|
64
|
-
http_client.open_timeout = open_timeout if open_timeout
|
|
65
|
-
http_client.read_timeout = read_timeout if read_timeout
|
|
66
|
-
@selenium_opts[:http_client] = http_client
|
|
105
|
+
browser_options[:timeouts][:script] = browser_options.delete(:script_timeout) * 1000
|
|
67
106
|
end
|
|
68
107
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
# rubocop:disable Metrics/CyclomaticComplexity::
|
|
73
|
-
def process_browser_options
|
|
74
|
-
browser_options = @options.delete(:options) || {}
|
|
75
|
-
|
|
76
|
-
case @selenium_browser
|
|
77
|
-
when :chrome
|
|
78
|
-
if @options.key?(:args) || @options.key?(:switches)
|
|
79
|
-
browser_options ||= {}
|
|
80
|
-
browser_options[:args] = (@options.delete(:args) || @options.delete(:switches)).dup
|
|
81
|
-
end
|
|
108
|
+
def browser_specific_options(options)
|
|
109
|
+
case @browser
|
|
110
|
+
when :chrome, :edge, :microsoftedge
|
|
82
111
|
if @options.delete(:headless)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
112
|
+
options.args << '--headless'
|
|
113
|
+
options.args << '--disable-gpu'
|
|
114
|
+
options.args << '--no-sandbox'
|
|
86
115
|
end
|
|
87
|
-
@selenium_opts[:options] = browser_options if browser_options.is_a? Selenium::WebDriver::Chrome::Options
|
|
88
|
-
@selenium_opts[:options] ||= Selenium::WebDriver::Chrome::Options.new(**browser_options)
|
|
89
116
|
when :firefox
|
|
90
|
-
|
|
91
|
-
if browser_options.is_a? Selenium::WebDriver::Firefox::Options
|
|
92
|
-
@selenium_opts[:options] = browser_options
|
|
93
|
-
if profile
|
|
94
|
-
msg = 'Initializing Browser with both :profile and :option', ':profile as a key inside :option'
|
|
95
|
-
Watir.logger.deprecate msg, ids: [:firefox_profile]
|
|
96
|
-
end
|
|
97
|
-
end
|
|
98
|
-
if @options.delete(:headless)
|
|
99
|
-
browser_options ||= {}
|
|
100
|
-
browser_options[:args] ||= []
|
|
101
|
-
browser_options[:args] += ['--headless']
|
|
102
|
-
end
|
|
103
|
-
@selenium_opts[:options] ||= Selenium::WebDriver::Firefox::Options.new(**browser_options)
|
|
104
|
-
@selenium_opts[:options].profile = profile if profile
|
|
117
|
+
options.headless! if @options.delete(:headless)
|
|
105
118
|
when :safari
|
|
106
119
|
Selenium::WebDriver::Safari.technology_preview! if @options.delete(:technology_preview)
|
|
107
|
-
when :remote
|
|
108
|
-
if @browser == :chrome && @options.delete(:headless)
|
|
109
|
-
args = @options.delete(:args) || @options.delete(:switches) || []
|
|
110
|
-
@options['chromeOptions'] = {'args' => args + ['--headless', '--disable-gpu']}
|
|
111
|
-
end
|
|
112
|
-
if @browser == :firefox && @options.delete(:headless)
|
|
113
|
-
args = @options.delete(:args) || @options.delete(:switches) || []
|
|
114
|
-
@options[Selenium::WebDriver::Firefox::Options::KEY] = {'args' => args + ['--headless']}
|
|
115
|
-
end
|
|
116
|
-
if @browser == :safari && @options.delete(:technology_preview)
|
|
117
|
-
@options['safari.options'] = {'technologyPreview' => true}
|
|
118
|
-
end
|
|
119
|
-
when :ie
|
|
120
|
-
if @options.key?(:args)
|
|
121
|
-
browser_options ||= {}
|
|
122
|
-
browser_options[:args] = @options.delete(:args).dup
|
|
123
|
-
end
|
|
124
|
-
unless browser_options.is_a? Selenium::WebDriver::IE::Options
|
|
125
|
-
ie_caps = browser_options.select { |k| Selenium::WebDriver::IE::Options::CAPABILITIES.include?(k) }
|
|
126
|
-
browser_options = Selenium::WebDriver::IE::Options.new(**browser_options)
|
|
127
|
-
ie_caps.each { |k, v| browser_options.add_option(k, v) }
|
|
128
|
-
end
|
|
129
|
-
@selenium_opts[:options] = browser_options
|
|
130
120
|
end
|
|
131
121
|
end
|
|
132
122
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
# rubocop:enable Metrics/CyclomaticComplexity::
|
|
123
|
+
def process_service
|
|
124
|
+
service = @options.delete(:service)
|
|
136
125
|
|
|
137
|
-
|
|
138
|
-
|
|
126
|
+
case service
|
|
127
|
+
when nil
|
|
128
|
+
nil
|
|
129
|
+
when Hash
|
|
130
|
+
return if service.empty?
|
|
139
131
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
ids: [:use_capabilities]
|
|
144
|
-
@selenium_opts.merge!(@options)
|
|
132
|
+
Selenium::WebDriver::Service.send(@browser, **service)
|
|
133
|
+
when Selenium::WebDriver::Service
|
|
134
|
+
service
|
|
145
135
|
else
|
|
146
|
-
|
|
136
|
+
raise TypeError, "#{service} needs to be Selenium Service or Hash instance"
|
|
147
137
|
end
|
|
138
|
+
end
|
|
148
139
|
|
|
149
|
-
|
|
140
|
+
def infer_browser
|
|
141
|
+
if @options.key?(:browser)
|
|
142
|
+
@options.delete(:browser)
|
|
143
|
+
elsif @options.key?(:capabilities)
|
|
144
|
+
@options[:capabilities].browser_name.tr(' ', '_').downcase.to_sym
|
|
145
|
+
elsif @options.key?(:options)
|
|
146
|
+
@options[:options].class.to_s.split('::')[-2].downcase.to_sym
|
|
147
|
+
else
|
|
148
|
+
:chrome
|
|
149
|
+
end
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
end
|