watir 7.2.0 → 7.2.1
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 +1 -1
- data/.github/workflows/edge.yml +1 -1
- data/.github/workflows/firefox.yml +1 -1
- data/.github/workflows/ie.yml +1 -1
- data/.github/workflows/safari.yml +1 -1
- data/.github/workflows/unit.yml +1 -1
- data/.rubocop.yml +25 -12
- data/.rubocop_todo.yml +8 -1
- data/CHANGES.md +6 -1
- data/LICENSE +2 -2
- data/lib/watir/capabilities.rb +1 -1
- data/lib/watir/locators/anchor/selector_builder.rb +3 -0
- data/lib/watir/locators/element/matcher.rb +2 -1
- data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
- data/lib/watir/locators/text_field/matcher.rb +0 -4
- data/lib/watir/version.rb +1 -1
- data/spec/locator_spec_helper.rb +0 -8
- data/spec/unit/capabilities_spec.rb +553 -561
- data/spec/unit/element_locator_spec.rb +89 -78
- data/spec/unit/match_elements/button_spec.rb +69 -62
- data/spec/unit/match_elements/element_spec.rb +303 -309
- data/spec/unit/match_elements/text_field_spec.rb +76 -73
- data/spec/unit/selector_builder/anchor_spec.rb +39 -33
- data/spec/unit/selector_builder/button_spec.rb +209 -202
- data/spec/unit/selector_builder/cell_spec.rb +48 -42
- data/spec/unit/selector_builder/element_spec.rb +634 -627
- data/spec/unit/selector_builder/row_spec.rb +119 -113
- data/spec/unit/selector_builder/text_field_spec.rb +195 -188
- data/spec/unit/selector_builder/textarea_spec.rb +22 -14
- data/spec/unit/wait_spec.rb +85 -81
- data/spec/watirspec/adjacent_spec.rb +249 -247
- data/spec/watirspec/after_hooks_spec.rb +161 -159
- data/spec/watirspec/alert_spec.rb +61 -58
- data/spec/watirspec/browser_spec.rb +409 -409
- data/spec/watirspec/capabilities_spec.rb +89 -99
- data/spec/watirspec/cookies_spec.rb +120 -118
- data/spec/watirspec/drag_and_drop_spec.rb +26 -24
- data/spec/watirspec/element_hidden_spec.rb +66 -60
- data/spec/watirspec/elements/area_spec.rb +49 -47
- data/spec/watirspec/elements/areas_spec.rb +27 -25
- data/spec/watirspec/elements/button_spec.rb +253 -251
- data/spec/watirspec/elements/buttons_spec.rb +36 -34
- data/spec/watirspec/elements/checkbox_spec.rb +48 -36
- data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
- data/spec/watirspec/elements/collections_spec.rb +126 -119
- data/spec/watirspec/elements/date_field_spec.rb +185 -183
- data/spec/watirspec/elements/date_fields_spec.rb +29 -27
- data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
- data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
- data/spec/watirspec/elements/dd_spec.rb +87 -85
- data/spec/watirspec/elements/dds_spec.rb +27 -25
- data/spec/watirspec/elements/del_spec.rb +106 -104
- data/spec/watirspec/elements/dels_spec.rb +26 -24
- data/spec/watirspec/elements/div_spec.rb +225 -221
- data/spec/watirspec/elements/divs_spec.rb +37 -35
- data/spec/watirspec/elements/dl_spec.rb +110 -108
- data/spec/watirspec/elements/dls_spec.rb +28 -26
- data/spec/watirspec/elements/dt_spec.rb +86 -84
- data/spec/watirspec/elements/dts_spec.rb +27 -25
- data/spec/watirspec/elements/element_spec.rb +794 -775
- data/spec/watirspec/elements/elements_spec.rb +40 -38
- data/spec/watirspec/elements/em_spec.rb +62 -60
- data/spec/watirspec/elements/ems_spec.rb +28 -26
- data/spec/watirspec/elements/filefield_spec.rb +116 -114
- data/spec/watirspec/elements/filefields_spec.rb +28 -26
- data/spec/watirspec/elements/font_spec.rb +20 -18
- data/spec/watirspec/elements/form_spec.rb +51 -49
- data/spec/watirspec/elements/forms_spec.rb +29 -27
- data/spec/watirspec/elements/frame_spec.rb +89 -87
- data/spec/watirspec/elements/frames_spec.rb +27 -25
- data/spec/watirspec/elements/hidden_spec.rb +81 -79
- data/spec/watirspec/elements/hiddens_spec.rb +28 -26
- data/spec/watirspec/elements/hn_spec.rb +59 -57
- data/spec/watirspec/elements/hns_spec.rb +26 -24
- data/spec/watirspec/elements/iframe_spec.rb +195 -191
- data/spec/watirspec/elements/iframes_spec.rb +31 -29
- data/spec/watirspec/elements/image_spec.rb +148 -146
- data/spec/watirspec/elements/images_spec.rb +26 -24
- data/spec/watirspec/elements/input_spec.rb +9 -7
- data/spec/watirspec/elements/ins_spec.rb +106 -104
- data/spec/watirspec/elements/inses_spec.rb +26 -24
- data/spec/watirspec/elements/label_spec.rb +56 -54
- data/spec/watirspec/elements/labels_spec.rb +26 -24
- data/spec/watirspec/elements/li_spec.rb +76 -74
- data/spec/watirspec/elements/link_spec.rb +173 -177
- data/spec/watirspec/elements/links_spec.rb +45 -43
- data/spec/watirspec/elements/lis_spec.rb +27 -25
- data/spec/watirspec/elements/list_spec.rb +44 -42
- data/spec/watirspec/elements/map_spec.rb +57 -55
- data/spec/watirspec/elements/maps_spec.rb +27 -25
- data/spec/watirspec/elements/meta_spec.rb +16 -14
- data/spec/watirspec/elements/metas_spec.rb +26 -24
- data/spec/watirspec/elements/ol_spec.rb +56 -65
- data/spec/watirspec/elements/ols_spec.rb +26 -24
- data/spec/watirspec/elements/option_spec.rb +91 -89
- data/spec/watirspec/elements/p_spec.rb +81 -79
- data/spec/watirspec/elements/pre_spec.rb +77 -75
- data/spec/watirspec/elements/pres_spec.rb +26 -24
- data/spec/watirspec/elements/ps_spec.rb +26 -24
- data/spec/watirspec/elements/radio_spec.rb +251 -249
- data/spec/watirspec/elements/radios_spec.rb +28 -26
- data/spec/watirspec/elements/select_list_spec.rb +537 -526
- data/spec/watirspec/elements/select_lists_spec.rb +32 -30
- data/spec/watirspec/elements/span_spec.rb +112 -110
- data/spec/watirspec/elements/spans_spec.rb +26 -24
- data/spec/watirspec/elements/strong_spec.rb +58 -58
- data/spec/watirspec/elements/strongs_spec.rb +28 -26
- data/spec/watirspec/elements/table_spec.rb +192 -139
- data/spec/watirspec/elements/tables_spec.rb +28 -26
- data/spec/watirspec/elements/tbody_spec.rb +74 -72
- data/spec/watirspec/elements/tbodys_spec.rb +40 -38
- data/spec/watirspec/elements/td_spec.rb +66 -64
- data/spec/watirspec/elements/tds_spec.rb +41 -39
- data/spec/watirspec/elements/text_field_spec.rb +206 -204
- data/spec/watirspec/elements/text_fields_spec.rb +30 -28
- data/spec/watirspec/elements/textarea_spec.rb +20 -18
- data/spec/watirspec/elements/textareas_spec.rb +18 -16
- data/spec/watirspec/elements/tfoot_spec.rb +65 -63
- data/spec/watirspec/elements/tfoots_spec.rb +42 -40
- data/spec/watirspec/elements/thead_spec.rb +65 -63
- data/spec/watirspec/elements/theads_spec.rb +42 -40
- data/spec/watirspec/elements/tr_spec.rb +48 -46
- data/spec/watirspec/elements/trs_spec.rb +42 -40
- data/spec/watirspec/elements/ul_spec.rb +56 -54
- data/spec/watirspec/elements/uls_spec.rb +26 -24
- data/spec/watirspec/radio_set_spec.rb +269 -267
- data/spec/watirspec/screenshot_spec.rb +20 -18
- data/spec/watirspec/scroll_spec.rb +152 -148
- data/spec/watirspec/shadow_root_spec.rb +86 -83
- data/spec/watirspec/user_editable_spec.rb +200 -198
- data/spec/watirspec/wait_spec.rb +289 -295
- data/spec/watirspec/window_switching_spec.rb +422 -434
- data/spec/watirspec_helper.rb +1 -23
- data/watir.gemspec +5 -4
- metadata +44 -33
- data/spec/watirspec/attributes_spec.rb +0 -18
- data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
- data/spec/watirspec/special_chars_spec.rb +0 -23
@@ -2,166 +2,168 @@
|
|
2
2
|
|
3
3
|
require 'watirspec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
module Watir
|
6
|
+
describe Cookies do
|
7
|
+
after { browser.cookies.clear }
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
it 'gets any cookies set' do
|
14
|
-
browser.goto set_cookie_url
|
15
|
-
|
16
|
-
verify_cookies_count 1
|
17
|
-
|
18
|
-
cookie = browser.cookies.to_a.first
|
19
|
-
expect(cookie[:name]).to eq 'monster'
|
20
|
-
expect(cookie[:value]).to eq '1'
|
21
|
-
end
|
9
|
+
it 'gets an empty list of cookies' do
|
10
|
+
browser.goto WatirSpec.url_for 'index.html'
|
11
|
+
expect(browser.cookies.to_a).to eq []
|
12
|
+
end
|
22
13
|
|
23
|
-
|
24
|
-
before do
|
14
|
+
it 'gets any cookies set' do
|
25
15
|
browser.goto set_cookie_url
|
16
|
+
|
26
17
|
verify_cookies_count 1
|
27
|
-
end
|
28
18
|
|
29
|
-
|
30
|
-
cookie
|
31
|
-
expect(cookie[:
|
32
|
-
expect(cookie[:value]).to eq('1')
|
19
|
+
cookie = browser.cookies.to_a.first
|
20
|
+
expect(cookie[:name]).to eq 'monster'
|
21
|
+
expect(cookie[:value]).to eq '1'
|
33
22
|
end
|
34
23
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
24
|
+
describe '#[]' do
|
25
|
+
before do
|
26
|
+
browser.goto set_cookie_url
|
27
|
+
verify_cookies_count 1
|
28
|
+
end
|
40
29
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
30
|
+
it 'returns cookie by symbol name' do
|
31
|
+
cookie = browser.cookies[:monster]
|
32
|
+
expect(cookie[:name]).to eq('monster')
|
33
|
+
expect(cookie[:value]).to eq('1')
|
34
|
+
end
|
45
35
|
|
46
|
-
|
47
|
-
|
48
|
-
|
36
|
+
it 'returns cookie by string name' do
|
37
|
+
cookie = browser.cookies['monster']
|
38
|
+
expect(cookie[:name]).to eq('monster')
|
39
|
+
expect(cookie[:value]).to eq('1')
|
40
|
+
end
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
42
|
+
it 'returns nil if there is no cookie with such name' do
|
43
|
+
expect(browser.cookies[:non_monster]).to be_nil
|
44
|
+
end
|
45
|
+
end
|
53
46
|
|
54
|
-
|
55
|
-
|
47
|
+
it 'adds a cookie without options' do
|
48
|
+
browser.goto WatirSpec.url_for 'index.html'
|
49
|
+
verify_cookies_count 0
|
56
50
|
|
57
|
-
|
51
|
+
browser.cookies.add 'foo', 'bar'
|
52
|
+
verify_cookies_count 1
|
53
|
+
end
|
58
54
|
|
59
|
-
|
55
|
+
it 'adds a cookie with a string expires value' do
|
56
|
+
browser.goto WatirSpec.url_for 'index.html'
|
60
57
|
|
61
|
-
|
62
|
-
expect(cookie[:expires]).to be_kind_of(Time)
|
63
|
-
end
|
58
|
+
expire_time = ::Time.now + 10_000
|
64
59
|
|
65
|
-
|
66
|
-
except: {browser: :ie, reason: 'path contains two slashes'} do
|
67
|
-
browser.goto WatirSpec.url_for 'index.html'
|
60
|
+
browser.cookies.add 'foo', 'bar', expires: expire_time.to_s
|
68
61
|
|
69
|
-
|
70
|
-
|
62
|
+
cookie = browser.cookies[:foo]
|
63
|
+
expect(cookie[:expires]).to be_a(::Time)
|
64
|
+
end
|
71
65
|
|
72
|
-
|
66
|
+
it 'adds a cookie with path',
|
67
|
+
except: {browser: :ie, reason: 'path contains two slashes'} do
|
68
|
+
browser.goto WatirSpec.url_for 'index.html'
|
73
69
|
|
74
|
-
|
75
|
-
|
70
|
+
options = {path: '/set_cookie'}
|
71
|
+
browser.cookies.add 'path', 'b', options
|
76
72
|
|
77
|
-
|
78
|
-
expect(cookie[:value]).to eq 'b'
|
79
|
-
expect(cookie[:path]).to eq '/set_cookie'
|
80
|
-
end
|
73
|
+
expect(browser.cookies.to_a).to be_empty
|
81
74
|
|
82
|
-
|
83
|
-
|
75
|
+
browser.goto set_cookie_url
|
76
|
+
cookie = browser.cookies.to_a.find { |e| e[:name] == 'path' }
|
84
77
|
|
85
|
-
|
86
|
-
|
78
|
+
expect(cookie[:name]).to eq 'path'
|
79
|
+
expect(cookie[:value]).to eq 'b'
|
80
|
+
expect(cookie[:path]).to eq '/set_cookie'
|
81
|
+
end
|
87
82
|
|
88
|
-
|
89
|
-
|
83
|
+
it 'adds a cookie with expiration' do
|
84
|
+
browser.goto WatirSpec.url_for 'index.html'
|
90
85
|
|
91
|
-
|
92
|
-
|
86
|
+
expires = ::Time.now + 10_000
|
87
|
+
options = {expires: expires}
|
93
88
|
|
94
|
-
|
95
|
-
|
89
|
+
browser.cookies.add 'expiration', 'b', options
|
90
|
+
cookie = browser.cookies.to_a.first
|
96
91
|
|
97
|
-
|
98
|
-
|
99
|
-
except: [{browser: :firefox,
|
100
|
-
reason: 'https://github.com/mozilla/geckodriver/issues/1840'},
|
101
|
-
{browser: %i[chrome edge], platform: :windows}] do
|
102
|
-
browser.goto WatirSpec.url_for 'index.html'
|
92
|
+
expect(cookie[:name]).to eq 'expiration'
|
93
|
+
expect(cookie[:value]).to eq 'b'
|
103
94
|
|
104
|
-
|
95
|
+
expect((cookie[:expires]).to_i).to be_within(2).of(expires.to_i)
|
96
|
+
end
|
105
97
|
|
106
|
-
|
107
|
-
cookie
|
108
|
-
|
109
|
-
|
98
|
+
# Pending resolution of https://github.com/w3c/webdriver/issues/1571
|
99
|
+
it 'adding cookie with security does not raise exception but can not be retrieved',
|
100
|
+
except: [{browser: :firefox,
|
101
|
+
reason: 'https://github.com/mozilla/geckodriver/issues/1840'},
|
102
|
+
{browser: %i[chrome edge], platform: :windows}] do
|
103
|
+
browser.goto WatirSpec.url_for 'index.html'
|
110
104
|
|
111
|
-
|
112
|
-
browser.goto set_cookie_url
|
113
|
-
verify_cookies_count 1
|
105
|
+
options = {secure: true}
|
114
106
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
it 'clears all cookies' do
|
120
|
-
browser.goto set_cookie_url
|
121
|
-
browser.cookies.add 'foo', 'bar'
|
122
|
-
verify_cookies_count 2
|
107
|
+
browser.cookies.add 'secure', 'b', options
|
108
|
+
cookie = browser.cookies.to_a.find { |e| e[:name] == 'secure' }
|
109
|
+
expect(cookie).to be_nil
|
110
|
+
end
|
123
111
|
|
124
|
-
|
125
|
-
|
126
|
-
|
112
|
+
it 'removes a cookie' do
|
113
|
+
browser.goto set_cookie_url
|
114
|
+
verify_cookies_count 1
|
127
115
|
|
128
|
-
|
129
|
-
|
116
|
+
browser.cookies.delete 'monster'
|
117
|
+
verify_cookies_count 0
|
118
|
+
end
|
130
119
|
|
131
|
-
|
120
|
+
it 'clears all cookies' do
|
132
121
|
browser.goto set_cookie_url
|
133
|
-
browser.cookies.
|
122
|
+
browser.cookies.add 'foo', 'bar'
|
123
|
+
verify_cookies_count 2
|
124
|
+
|
125
|
+
browser.cookies.clear
|
126
|
+
verify_cookies_count 0
|
134
127
|
end
|
135
128
|
|
136
|
-
|
137
|
-
|
138
|
-
|
129
|
+
context 'when using file' do
|
130
|
+
let(:file) { "#{Dir.tmpdir}/cookies" }
|
131
|
+
|
132
|
+
before do
|
133
|
+
browser.goto set_cookie_url
|
134
|
+
browser.cookies.save file
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#save' do
|
138
|
+
it 'saves cookies to file' do
|
139
|
+
expect(File.read(file)).to eq(browser.cookies.to_a.to_yaml)
|
140
|
+
end
|
139
141
|
end
|
140
|
-
end
|
141
142
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
143
|
+
describe '#load', except: {browser: :ie} do
|
144
|
+
it 'loads cookies from file' do
|
145
|
+
browser.cookies.clear
|
146
|
+
browser.cookies.load file
|
147
|
+
expected = browser.cookies.to_a
|
148
|
+
actual = YAML.safe_load(File.read(file), permitted_classes: [::Symbol])
|
148
149
|
|
149
|
-
|
150
|
-
|
150
|
+
expected.each { |cookie| cookie.delete(:expires) }
|
151
|
+
actual.each { |cookie| cookie.delete(:expires) }
|
151
152
|
|
152
|
-
|
153
|
+
expect(actual).to eq(expected)
|
154
|
+
end
|
153
155
|
end
|
154
156
|
end
|
155
|
-
end
|
156
157
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
158
|
+
def set_cookie_url
|
159
|
+
# add timestamp to url to avoid caching in IE8
|
160
|
+
WatirSpec.url_for('set_cookie/index.html') + "?t=#{::Time.now.to_i + ::Time.now.usec}"
|
161
|
+
end
|
161
162
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
def verify_cookies_count(expected_size)
|
164
|
+
cookies = browser.cookies.to_a
|
165
|
+
msg = "expected #{expected_size} cookies, got #{cookies.size}: #{cookies.inspect}"
|
166
|
+
expect(cookies.size).to eq(expected_size), msg
|
167
|
+
end
|
166
168
|
end
|
167
169
|
end
|
@@ -2,35 +2,37 @@
|
|
2
2
|
|
3
3
|
require 'watirspec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
module Watir
|
6
|
+
describe Element do
|
7
|
+
describe 'using drag and drop', except: {browser: :ie} do
|
8
|
+
before { browser.goto WatirSpec.url_for('drag_and_drop.html') }
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
let(:draggable) { browser.div id: 'draggable' }
|
11
|
+
let(:droppable) { browser.div id: 'droppable' }
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
it 'can drag and drop an element onto another' do
|
14
|
+
expect(droppable.text).to include 'Drop here'
|
15
|
+
draggable.drag_and_drop_on droppable
|
16
|
+
expect(droppable.text).to include 'Dropped!'
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
it 'can drag and drop an element onto another with specified scroll position' do
|
20
|
+
expect(droppable.text).to include 'Drop here'
|
21
|
+
draggable.drag_and_drop_on droppable, scroll_to: :center
|
22
|
+
expect(droppable.text).to include 'Dropped!'
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
it 'can drag an element by the given offset' do
|
26
|
+
expect(droppable.text).to include 'Drop here'
|
27
|
+
draggable.drag_and_drop_by 200, 50
|
28
|
+
expect(droppable.text).to include 'Dropped!'
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
it 'can drag an element by the given offset with specified scroll position' do
|
32
|
+
expect(droppable.text).to include 'Drop here'
|
33
|
+
draggable.drag_and_drop_by 200, 50, scroll_to: :center
|
34
|
+
expect(droppable.text).to include 'Dropped!'
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
@@ -2,79 +2,85 @@
|
|
2
2
|
|
3
3
|
require 'watirspec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module Watir
|
6
|
+
module Locators
|
7
|
+
class Element
|
8
|
+
describe Locator do
|
9
|
+
describe 'Visible Elements' do
|
10
|
+
before do
|
11
|
+
browser.goto(WatirSpec.url_for('wait.html'))
|
12
|
+
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
14
|
+
context 'when true' do
|
15
|
+
it 'finds single element' do
|
16
|
+
element = browser.body.element(visible: true)
|
17
|
+
expect(element.id).to eq 'foo'
|
18
|
+
end
|
16
19
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
20
|
+
it 'handles tag_name and index' do
|
21
|
+
element = browser.div(visible: true, index: 1)
|
22
|
+
expect(element.id).to eq 'buttons'
|
23
|
+
end
|
21
24
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
it 'handles :tag_name and a single regexp attribute' do
|
26
|
+
element = browser.div(visible: true, id: /ons/)
|
27
|
+
expect(element.id).to eq 'buttons'
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
30
|
+
it 'handles :xpath' do
|
31
|
+
element = browser.element(visible: true, xpath: './/div[@id="foo"]')
|
32
|
+
expect(element.id).to eq 'foo'
|
33
|
+
end
|
31
34
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
35
|
+
it 'handles :css' do
|
36
|
+
element = browser.element(visible: true, css: 'div#foo')
|
37
|
+
expect(element.id).to eq 'foo'
|
38
|
+
end
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
it 'handles in collections' do
|
41
|
+
elements = browser.divs(visible: true)
|
42
|
+
expect(elements.size).to eq 3
|
43
|
+
end
|
44
|
+
end
|
42
45
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
context 'when false' do
|
47
|
+
it 'finds single element' do
|
48
|
+
element = browser.body.element(visible: false)
|
49
|
+
expect(element.id).to eq 'bar'
|
50
|
+
end
|
48
51
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
it 'handles tag_name and index' do
|
53
|
+
element = browser.div(visible: false, index: 1)
|
54
|
+
expect(element.id).to eq 'also_hidden'
|
55
|
+
end
|
53
56
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
57
|
+
it 'handles :tag_name and a single regexp attribute' do
|
58
|
+
element = browser.div(visible: false, id: /_/)
|
59
|
+
expect(element.id).to eq 'also_hidden'
|
60
|
+
end
|
58
61
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
62
|
+
it 'handles :xpath' do
|
63
|
+
element = browser.element(visible: false, xpath: './/div[@id="bar"]')
|
64
|
+
expect(element.id).to eq 'bar'
|
65
|
+
end
|
63
66
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
67
|
+
it 'handles :css' do
|
68
|
+
element = browser.element(visible: false, css: 'div#bar')
|
69
|
+
expect(element.id).to eq 'bar'
|
70
|
+
end
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
72
|
+
it 'handles in collections' do
|
73
|
+
elements = browser.divs(visible: false)
|
74
|
+
expect(elements.size).to eq 3
|
75
|
+
end
|
76
|
+
end
|
74
77
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
+
it 'raises exception when value is not Boolean' do
|
79
|
+
msg = 'expected one of [TrueClass, FalseClass], got "true":String'
|
80
|
+
expect { browser.body.element(visible: 'true') }.to raise_exception(TypeError, msg)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
78
84
|
end
|
79
85
|
end
|
80
86
|
end
|
@@ -2,66 +2,68 @@
|
|
2
2
|
|
3
3
|
require 'watirspec_helper'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
module Watir
|
6
|
+
describe Area do
|
7
|
+
before do
|
8
|
+
browser.goto(WatirSpec.url_for('images.html'))
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
# Exists method
|
12
|
+
describe '#exist?' do
|
13
|
+
it 'returns true if the area exists' do
|
14
|
+
expect(browser.area(id: 'NCE')).to exist
|
15
|
+
expect(browser.area(id: /NCE/)).to exist
|
16
|
+
expect(browser.area(title: 'Tables')).to exist
|
17
|
+
expect(browser.area(title: /Tables/)).to exist
|
18
|
+
expect(browser.area(href: 'tables.html')).to exist
|
19
|
+
expect(browser.area(href: /tables/)).to exist
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
expect(browser.area(index: 0)).to exist
|
22
|
+
expect(browser.area(xpath: "//area[@id='NCE']")).to exist
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
it 'returns the first area if given no args' do
|
26
|
+
expect(browser.area).to exist
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
29
|
+
it "returns false if the area doesn't exist" do
|
30
|
+
expect(browser.area(id: 'no_such_id')).not_to exist
|
31
|
+
expect(browser.area(id: /no_such_id/)).not_to exist
|
32
|
+
expect(browser.area(title: 'no_such_title')).not_to exist
|
33
|
+
expect(browser.area(title: /no_such_title/)).not_to exist
|
33
34
|
|
34
|
-
|
35
|
-
|
35
|
+
expect(browser.area(href: 'no-tables.html')).not_to exist
|
36
|
+
expect(browser.area(href: /no-tables/)).not_to exist
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
expect(browser.area(index: 1337)).not_to exist
|
39
|
+
expect(browser.area(xpath: "//area[@id='no_such_id']")).not_to exist
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
42
|
+
it "raises TypeError when 'what' argument is invalid" do
|
43
|
+
expect { browser.area(id: 3.14).exists? }.to raise_error(TypeError)
|
44
|
+
end
|
43
45
|
end
|
44
|
-
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
# Attribute methods
|
48
|
+
describe '#id' do
|
49
|
+
it 'returns the id attribute' do
|
50
|
+
expect(browser.area(index: 0).id).to eq 'NCE'
|
51
|
+
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
it "returns an empty string if the element exists and the attribute doesn't" do
|
54
|
+
expect(browser.area(index: 2).id).to eq ''
|
55
|
+
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
57
|
+
it "raises UnknownObjectException if the area doesn't exist" do
|
58
|
+
expect { browser.area(id: 'no_such_id').id }.to raise_unknown_object_exception
|
59
|
+
expect { browser.area(index: 1337).id }.to raise_unknown_object_exception
|
60
|
+
end
|
59
61
|
end
|
60
|
-
end
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
describe '#respond_to?' do
|
64
|
+
it 'returns true for all attribute methods' do
|
65
|
+
expect(browser.area(index: 0)).to respond_to(:id)
|
66
|
+
end
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|