watir 6.14.0 → 6.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +24 -6
  3. data/CHANGES.md +10 -0
  4. data/Gemfile +0 -2
  5. data/README.md +1 -1
  6. data/Rakefile +2 -2
  7. data/lib/watir.rb +2 -3
  8. data/lib/watir/adjacent.rb +2 -2
  9. data/lib/watir/alert.rb +5 -9
  10. data/lib/watir/attribute_helper.rb +2 -3
  11. data/lib/watir/browser.rb +5 -17
  12. data/lib/watir/capabilities.rb +11 -0
  13. data/lib/watir/cell_container.rb +2 -2
  14. data/lib/watir/container.rb +7 -8
  15. data/lib/watir/cookies.rb +2 -12
  16. data/lib/watir/element_collection.rb +2 -2
  17. data/lib/watir/elements/button.rb +2 -11
  18. data/lib/watir/elements/element.rb +43 -25
  19. data/lib/watir/elements/hidden.rb +1 -1
  20. data/lib/watir/elements/iframe.rb +7 -5
  21. data/lib/watir/elements/option.rb +2 -13
  22. data/lib/watir/elements/select.rb +6 -22
  23. data/lib/watir/elements/table.rb +2 -2
  24. data/lib/watir/exception.rb +1 -2
  25. data/lib/watir/generator/base/idl_sorter.rb +1 -1
  26. data/lib/watir/generator/base/spec_extractor.rb +2 -2
  27. data/lib/watir/generator/base/visitor.rb +1 -1
  28. data/lib/watir/generator/html/generator.rb +0 -1
  29. data/lib/watir/generator/html/spec_extractor.rb +1 -1
  30. data/lib/watir/generator/html/visitor.rb +1 -1
  31. data/lib/watir/generator/svg/spec_extractor.rb +1 -1
  32. data/lib/watir/generator/svg/visitor.rb +1 -1
  33. data/lib/watir/js_execution.rb +11 -0
  34. data/lib/watir/js_snippets.rb +1 -1
  35. data/lib/watir/js_snippets/elementObscured.js +14 -0
  36. data/lib/watir/js_snippets/selectedText.js +17 -0
  37. data/lib/watir/legacy_wait.rb +5 -5
  38. data/lib/watir/locators.rb +16 -5
  39. data/lib/watir/locators/anchor/selector_builder.rb +38 -0
  40. data/lib/watir/locators/button/locator.rb +14 -12
  41. data/lib/watir/locators/button/selector_builder.rb +0 -22
  42. data/lib/watir/locators/button/selector_builder/xpath.rb +67 -12
  43. data/lib/watir/locators/button/validator.rb +2 -1
  44. data/lib/watir/locators/cell/selector_builder.rb +0 -14
  45. data/lib/watir/locators/cell/selector_builder/xpath.rb +21 -0
  46. data/lib/watir/locators/element/locator.rb +60 -153
  47. data/lib/watir/locators/element/selector_builder.rb +103 -84
  48. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +66 -0
  49. data/lib/watir/locators/element/selector_builder/xpath.rb +195 -82
  50. data/lib/watir/locators/element/selector_builder/xpath_support.rb +27 -0
  51. data/lib/watir/locators/element/validator.rb +2 -9
  52. data/lib/watir/locators/row/selector_builder.rb +5 -22
  53. data/lib/watir/locators/row/selector_builder/xpath.rb +53 -0
  54. data/lib/watir/locators/text_area/selector_builder.rb +1 -1
  55. data/lib/watir/locators/text_area/selector_builder/xpath.rb +19 -0
  56. data/lib/watir/locators/text_field/locator.rb +11 -8
  57. data/lib/watir/locators/text_field/selector_builder.rb +0 -23
  58. data/lib/watir/locators/text_field/selector_builder/xpath.rb +33 -4
  59. data/lib/watir/locators/text_field/validator.rb +4 -4
  60. data/lib/watir/radio_set.rb +5 -5
  61. data/lib/watir/row_container.rb +2 -2
  62. data/lib/watir/user_editable.rb +2 -2
  63. data/lib/watir/version.rb +1 -1
  64. data/lib/watir/wait.rb +24 -37
  65. data/lib/watir/window.rb +11 -8
  66. data/lib/watirspec/remote_server.rb +3 -1
  67. data/spec/locator_spec_helper.rb +1 -1
  68. data/spec/spec_helper.rb +25 -1
  69. data/spec/unit/anchor_locator_spec.rb +68 -0
  70. data/spec/unit/capabilities_spec.rb +27 -0
  71. data/spec/unit/element_locator_spec.rb +184 -101
  72. data/spec/unit/logger_spec.rb +5 -0
  73. data/spec/watirspec/adjacent_spec.rb +34 -34
  74. data/spec/watirspec/after_hooks_spec.rb +78 -35
  75. data/spec/watirspec/alert_spec.rb +10 -0
  76. data/spec/watirspec/browser_spec.rb +27 -1
  77. data/spec/watirspec/element_hidden_spec.rb +6 -0
  78. data/spec/watirspec/elements/button_spec.rb +5 -11
  79. data/spec/watirspec/elements/buttons_spec.rb +1 -1
  80. data/spec/watirspec/elements/checkbox_spec.rb +2 -15
  81. data/spec/watirspec/elements/date_time_field_spec.rb +6 -1
  82. data/spec/watirspec/elements/dd_spec.rb +0 -17
  83. data/spec/watirspec/elements/del_spec.rb +0 -14
  84. data/spec/watirspec/elements/div_spec.rb +0 -18
  85. data/spec/watirspec/elements/dl_spec.rb +0 -17
  86. data/spec/watirspec/elements/dt_spec.rb +0 -17
  87. data/spec/watirspec/elements/element_spec.rb +177 -17
  88. data/spec/watirspec/elements/elements_spec.rb +7 -6
  89. data/spec/watirspec/elements/em_spec.rb +0 -13
  90. data/spec/watirspec/elements/filefield_spec.rb +0 -11
  91. data/spec/watirspec/elements/form_spec.rb +6 -0
  92. data/spec/watirspec/elements/hn_spec.rb +0 -14
  93. data/spec/watirspec/elements/iframe_spec.rb +15 -0
  94. data/spec/watirspec/elements/ins_spec.rb +0 -14
  95. data/spec/watirspec/elements/labels_spec.rb +1 -1
  96. data/spec/watirspec/elements/li_spec.rb +0 -14
  97. data/spec/watirspec/elements/link_spec.rb +22 -14
  98. data/spec/watirspec/elements/links_spec.rb +13 -0
  99. data/spec/watirspec/elements/list_spec.rb +15 -0
  100. data/spec/watirspec/elements/ol_spec.rb +0 -14
  101. data/spec/watirspec/elements/option_spec.rb +0 -10
  102. data/spec/watirspec/elements/p_spec.rb +0 -14
  103. data/spec/watirspec/elements/pre_spec.rb +0 -14
  104. data/spec/watirspec/elements/radio_spec.rb +0 -14
  105. data/spec/watirspec/elements/select_list_spec.rb +0 -10
  106. data/spec/watirspec/elements/span_spec.rb +4 -15
  107. data/spec/watirspec/elements/strong_spec.rb +4 -15
  108. data/spec/watirspec/elements/table_nesting_spec.rb +1 -1
  109. data/spec/watirspec/elements/table_spec.rb +7 -0
  110. data/spec/watirspec/elements/text_field_spec.rb +10 -2
  111. data/spec/watirspec/elements/text_fields_spec.rb +1 -1
  112. data/spec/watirspec/elements/tr_spec.rb +1 -1
  113. data/spec/watirspec/elements/ul_spec.rb +0 -14
  114. data/spec/watirspec/html/closeable.html +8 -0
  115. data/spec/watirspec/html/forms_with_input_elements.html +28 -23
  116. data/spec/watirspec/html/nested_elements.html +9 -9
  117. data/spec/watirspec/html/obscured.html +34 -0
  118. data/spec/watirspec/html/tables.html +13 -13
  119. data/spec/watirspec/radio_set_spec.rb +5 -0
  120. data/spec/watirspec/selector_builder/button_spec.rb +254 -0
  121. data/spec/watirspec/selector_builder/cell_spec.rb +93 -0
  122. data/spec/watirspec/selector_builder/element_spec.rb +639 -0
  123. data/spec/watirspec/selector_builder/row_spec.rb +150 -0
  124. data/spec/watirspec/selector_builder/text_spec.rb +170 -0
  125. data/spec/watirspec/support/rspec_matchers.rb +6 -1
  126. data/spec/watirspec/user_editable_spec.rb +4 -0
  127. data/spec/watirspec/wait_spec.rb +65 -14
  128. data/spec/watirspec/window_switching_spec.rb +54 -1
  129. data/spec/watirspec_helper.rb +2 -0
  130. data/watir.gemspec +7 -1
  131. metadata +86 -8
  132. data/lib/watir/locators/text_area/locator.rb +0 -13
  133. data/lib/watir/xpath_support.rb +0 -18
@@ -24,6 +24,11 @@ module Watir
24
24
  expect(Watir.logger.level).to eq(1)
25
25
  end
26
26
 
27
+ it 'allows to change level with integer' do
28
+ Watir.logger.level = 3
29
+ expect(Watir.logger.level).to eq(3)
30
+ end
31
+
27
32
  it 'outputs to stdout by default' do
28
33
  expect { Watir.logger.warn('message') }.to output(/WARN Watir message/).to_stdout_from_any_process
29
34
  end
@@ -17,13 +17,13 @@ describe 'Adjacent Elements' do
17
17
  end
18
18
 
19
19
  it 'accepts tag_name argument' do
20
- expect(browser.div(id: 'first_sibling').parent(tag_name: :div).id).to eq 'parent'
21
- expect(browser.div(id: 'first_sibling').parent(tag_name: :div)).to be_a Watir::Div
20
+ expect(browser.div(id: 'first_sibling').parent(tag_name: 'div').id).to eq 'parent'
21
+ expect(browser.div(id: 'first_sibling').parent(tag_name: 'div')).to be_a Watir::Div
22
22
  end
23
23
 
24
24
  it 'accepts custom tag_name argument' do
25
- expect(browser.div(id: 'regular_child').parent(tag_name: :grandelement).id).to eq 'custom_grandparent'
26
- expect(browser.div(id: 'regular_child').parent(tag_name: :grandelement)).to be_a Watir::HTMLElement
25
+ expect(browser.div(id: 'regular_child').parent(tag_name: 'grandelement').id).to eq 'custom_grandparent'
26
+ expect(browser.div(id: 'regular_child').parent(tag_name: 'grandelement')).to be_a Watir::HTMLElement
27
27
  end
28
28
 
29
29
  it 'accepts class_name argument' do
@@ -31,8 +31,8 @@ describe 'Adjacent Elements' do
31
31
  end
32
32
 
33
33
  it 'accepts index and tag_name arguments' do
34
- expect(browser.div(id: 'first_sibling').parent(tag_name: :div, index: 1).id).to eq 'grandparent'
35
- expect(browser.div(id: 'first_sibling').parent(tag_name: :div, index: 1)).to be_a Watir::Div
34
+ expect(browser.div(id: 'first_sibling').parent(tag_name: 'div', index: 1).id).to eq 'grandparent'
35
+ expect(browser.div(id: 'first_sibling').parent(tag_name: 'div', index: 1)).to be_a Watir::Div
36
36
  end
37
37
 
38
38
  it 'does not error when no parent element of an index exists' do
@@ -40,7 +40,7 @@ describe 'Adjacent Elements' do
40
40
  end
41
41
 
42
42
  it 'does not error when no parent element of a tag_name exists' do
43
- expect(browser.div(id: 'first_sibling').parent(tag_name: :table)).to_not exist
43
+ expect(browser.div(id: 'first_sibling').parent(tag_name: 'table')).to_not exist
44
44
  end
45
45
  end
46
46
 
@@ -51,13 +51,13 @@ describe 'Adjacent Elements' do
51
51
  end
52
52
 
53
53
  it 'accepts a tag name argument' do
54
- siblings = browser.div(id: 'second_sibling').siblings(tag_name: :div)
54
+ siblings = browser.div(id: 'second_sibling').siblings(tag_name: 'div')
55
55
  expect(siblings.size).to eq 3
56
56
  expect(siblings.all? { |sib| sib.is_a? Watir::Div }).to eq true
57
57
  end
58
58
 
59
59
  it 'accepts custom tag name argument' do
60
- siblings = browser.div(id: 'regular_child').siblings(tag_name: :childelement)
60
+ siblings = browser.div(id: 'regular_child').siblings(tag_name: 'childelement')
61
61
  expect(siblings.size).to eq 3
62
62
  expect(siblings.all? { |sib| sib.is_a? Watir::HTMLElement }).to eq true
63
63
  end
@@ -83,8 +83,8 @@ describe 'Adjacent Elements' do
83
83
  end
84
84
 
85
85
  it 'accepts tag_name argument' do
86
- expect(browser.div(id: 'first_sibling').following_sibling(tag_name: :div).id).to eq 'second_sibling'
87
- expect(browser.div(id: 'first_sibling').following_sibling(tag_name: :div)).to be_a Watir::Div
86
+ expect(browser.div(id: 'first_sibling').following_sibling(tag_name: 'div').id).to eq 'second_sibling'
87
+ expect(browser.div(id: 'first_sibling').following_sibling(tag_name: 'div')).to be_a Watir::Div
88
88
  end
89
89
 
90
90
  it 'accepts class_name argument' do
@@ -92,16 +92,16 @@ describe 'Adjacent Elements' do
92
92
  end
93
93
 
94
94
  it 'accepts index and tag_name arguments' do
95
- expect(browser.div(id: 'first_sibling').following_sibling(tag_name: :div, index: 1).id).to eq 'third_sibling'
96
- expect(browser.div(id: 'first_sibling').following_sibling(tag_name: :div, index: 1)).to be_a Watir::Div
95
+ expect(browser.div(id: 'first_sibling').following_sibling(tag_name: 'div', index: 1).id).to eq 'third_sibling'
96
+ expect(browser.div(id: 'first_sibling').following_sibling(tag_name: 'div', index: 1)).to be_a Watir::Div
97
97
  end
98
98
 
99
99
  it 'accepts text as Regexp' do
100
- expect(browser.div(id: 'first_sibling').following_sibling(text: /t/).id).to eq 'third_sibling'
100
+ expect(browser.div(id: 'first_sibling').following_sibling(text: /T/).id).to eq 'third_sibling'
101
101
  end
102
102
 
103
103
  it 'accepts text as String' do
104
- expect(browser.div(id: 'first_sibling').following_sibling(text: 'text').id).to eq 'third_sibling'
104
+ expect(browser.div(id: 'first_sibling').following_sibling(text: 'Third').id).to eq 'third_sibling'
105
105
  end
106
106
 
107
107
  it 'does not error when no next sibling of an index exists' do
@@ -109,7 +109,7 @@ describe 'Adjacent Elements' do
109
109
  end
110
110
 
111
111
  it 'does not error when no next sibling of a tag_name exists' do
112
- expect(browser.div(id: 'first_sibling').following_sibling(tag_name: :table)).to_not exist
112
+ expect(browser.div(id: 'first_sibling').following_sibling(tag_name: 'table')).to_not exist
113
113
  end
114
114
  end
115
115
 
@@ -120,8 +120,8 @@ describe 'Adjacent Elements' do
120
120
  end
121
121
 
122
122
  it 'accepts tag_name argument' do
123
- expect(browser.div(id: 'second_sibling').following_siblings(tag_name: :div).size).to eq 1
124
- expect(browser.div(id: 'second_sibling').following_siblings(tag_name: :div).first).to be_a Watir::Div
123
+ expect(browser.div(id: 'second_sibling').following_siblings(tag_name: 'div').size).to eq 1
124
+ expect(browser.div(id: 'second_sibling').following_siblings(tag_name: 'div').first).to be_a Watir::Div
125
125
  end
126
126
 
127
127
  it 'accepts class_name argument for single class' do
@@ -147,8 +147,8 @@ describe 'Adjacent Elements' do
147
147
  end
148
148
 
149
149
  it 'accepts tag_name argument' do
150
- expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: :div).id).to eq 'second_sibling'
151
- expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: :div)).to be_a Watir::Div
150
+ expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: 'div').id).to eq 'second_sibling'
151
+ expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: 'div')).to be_a Watir::Div
152
152
  end
153
153
 
154
154
  it 'accepts class_name argument' do
@@ -156,8 +156,8 @@ describe 'Adjacent Elements' do
156
156
  end
157
157
 
158
158
  it 'accepts index and tag_name arguments' do
159
- expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: :div, index: 1).id).to eq 'first_sibling'
160
- expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: :div, index: 1)).to be_a Watir::Div
159
+ expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: 'div', index: 1).id).to eq 'first_sibling'
160
+ expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: 'div', index: 1)).to be_a Watir::Div
161
161
  end
162
162
 
163
163
  it 'does not error when no next sibling of an index exists' do
@@ -165,7 +165,7 @@ describe 'Adjacent Elements' do
165
165
  end
166
166
 
167
167
  it 'does not error when no next sibling of a tag_name exists' do
168
- expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: :table)).to_not exist
168
+ expect(browser.div(id: 'third_sibling').previous_sibling(tag_name: 'table')).to_not exist
169
169
  end
170
170
  end
171
171
 
@@ -176,8 +176,8 @@ describe 'Adjacent Elements' do
176
176
  end
177
177
 
178
178
  it 'accepts tag_name argument' do
179
- expect(browser.div(id: 'second_sibling').previous_siblings(tag_name: :div).size).to eq 1
180
- expect(browser.div(id: 'second_sibling').previous_siblings(tag_name: :div).first).to be_a Watir::Div
179
+ expect(browser.div(id: 'second_sibling').previous_siblings(tag_name: 'div').size).to eq 1
180
+ expect(browser.div(id: 'second_sibling').previous_siblings(tag_name: 'div').first).to be_a Watir::Div
181
181
  end
182
182
 
183
183
  it 'accepts class_name argument' do
@@ -198,13 +198,13 @@ describe 'Adjacent Elements' do
198
198
  end
199
199
 
200
200
  it 'accepts tag_name argument' do
201
- expect(browser.div(id: 'parent').child(tag_name: :span).id).to eq 'between_siblings1'
202
- expect(browser.div(id: 'parent').child(tag_name: :span)).to be_a Watir::Span
201
+ expect(browser.div(id: 'parent').child(tag_name: 'span').id).to eq 'between_siblings1'
202
+ expect(browser.div(id: 'parent').child(tag_name: 'span')).to be_a Watir::Span
203
203
  end
204
204
 
205
205
  it 'accepts custom tag_name argument' do
206
- expect(browser.element(id: 'custom_parent').child(tag_name: :childelement).id).to eq 'custom_child'
207
- expect(browser.element(id: 'custom_parent').child(tag_name: :childelement)).to be_a Watir::HTMLElement
206
+ expect(browser.element(id: 'custom_parent').child(tag_name: 'childelement').id).to eq 'custom_child'
207
+ expect(browser.element(id: 'custom_parent').child(tag_name: 'childelement')).to be_a Watir::HTMLElement
208
208
  end
209
209
 
210
210
  it 'accepts class_name argument' do
@@ -212,8 +212,8 @@ describe 'Adjacent Elements' do
212
212
  end
213
213
 
214
214
  it 'accepts index and tag_name arguments' do
215
- expect(browser.div(id: 'parent').child(tag_name: :div, index: 1).id).to eq 'second_sibling'
216
- expect(browser.div(id: 'parent').child(tag_name: :div, index: 1)).to be_a Watir::Div
215
+ expect(browser.div(id: 'parent').child(tag_name: 'div', index: 1).id).to eq 'second_sibling'
216
+ expect(browser.div(id: 'parent').child(tag_name: 'div', index: 1)).to be_a Watir::Div
217
217
  end
218
218
 
219
219
  it 'does not error when no next sibling of an index exists' do
@@ -221,7 +221,7 @@ describe 'Adjacent Elements' do
221
221
  end
222
222
 
223
223
  it 'does not error when no next sibling of a tag_name exists' do
224
- expect(browser.div(id: 'parent').child(tag_name: :table)).to_not exist
224
+ expect(browser.div(id: 'parent').child(tag_name: 'table')).to_not exist
225
225
  end
226
226
  end
227
227
 
@@ -232,13 +232,13 @@ describe 'Adjacent Elements' do
232
232
  end
233
233
 
234
234
  it 'accepts tag_name argument' do
235
- children = browser.div(id: 'parent').children(tag_name: :div)
235
+ children = browser.div(id: 'parent').children(tag_name: 'div')
236
236
  expect(children.size).to eq 3
237
237
  expect(children.all? { |child| child.is_a? Watir::Div }).to eq true
238
238
  end
239
239
 
240
240
  it 'accepts custom tag_name argument' do
241
- children = browser.element(id: 'custom_parent').children(tag_name: :childelement)
241
+ children = browser.element(id: 'custom_parent').children(tag_name: 'childelement')
242
242
  expect(children.size).to eq 3
243
243
  expect(children.all? { |child| child.is_a? Watir::HTMLElement }).to eq true
244
244
  end
@@ -11,6 +11,7 @@ describe 'Browser::AfterHooks' do
11
11
  proc = proc { |browser| output << browser.text }
12
12
 
13
13
  begin
14
+ browser.alert.dismiss if browser.alert.exists?
14
15
  browser.after_hooks.add(proc)
15
16
  browser.goto(WatirSpec.url_for('non_control_elements.html'))
16
17
 
@@ -19,6 +20,18 @@ describe 'Browser::AfterHooks' do
19
20
  browser.after_hooks.delete(proc)
20
21
  end
21
22
  end
23
+
24
+ it 'runs the given block on each page load' do
25
+ output = ''
26
+ begin
27
+ browser.after_hooks.add { |browser| output << browser.text }
28
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
29
+
30
+ expect(output).to include('Dubito, ergo cogito, ergo sum')
31
+ ensure
32
+ browser.after_hooks.delete browser.after_hooks[0]
33
+ end
34
+ end
22
35
  end
23
36
 
24
37
  describe '#delete' do
@@ -125,58 +138,88 @@ describe 'Browser::AfterHooks' do
125
138
  end
126
139
 
127
140
  not_compliant_on :safari, :headless do
128
- it 'does not run error checks with alert present' do
129
- browser.goto WatirSpec.url_for('alerts.html')
130
-
131
- @page_after_hook = proc { @yield = browser.title == 'Alerts' }
132
- browser.after_hooks.add @page_after_hook
141
+ bug 'chromedriver 2.43 https://bugs.chromium.org/p/chromedriver/issues/detail?id=2615', :chrome do
142
+ it 'does not run error checks with alert present' do
143
+ browser.goto WatirSpec.url_for('alerts.html')
133
144
 
134
- browser.button(id: 'alert').click
135
- expect(@yield).to be_nil
145
+ @page_after_hook = proc { @yield = browser.title == 'Alerts' }
146
+ browser.after_hooks.add @page_after_hook
136
147
 
137
- browser.alert.ok
138
- expect(@yield).to eq true
139
- end
140
- end
148
+ browser.button(id: 'alert').click
149
+ expect(@yield).to be_nil
141
150
 
142
- not_compliant_on :headless do
143
- it 'does not raise error when running error checks using #after_hooks#without with alert present' do
144
- url = WatirSpec.url_for('alerts.html')
145
- @page_after_hook = proc { browser.url }
146
- browser.after_hooks.add @page_after_hook
147
- browser.goto url
148
- expect { browser.after_hooks.without { browser.button(id: 'alert').click } }.to_not raise_error
149
- browser.alert.ok
151
+ browser.alert.ok
152
+ expect(@yield).to eq true
153
+ end
150
154
  end
151
155
  end
152
156
 
153
157
  not_compliant_on :headless do
154
- it 'does not raise error if no error checks are defined with alert present' do
155
- url = WatirSpec.url_for('alerts.html')
156
- @page_after_hook = proc { browser.url }
157
- browser.after_hooks.add @page_after_hook
158
- browser.goto url
159
- browser.after_hooks.delete @page_after_hook
160
- expect { browser.button(id: 'alert').click }.to_not raise_error
161
- browser.alert.ok
158
+ bug 'chromedriver 2.43 https://bugs.chromium.org/p/chromedriver/issues/detail?id=2615', :chrome do
159
+ it 'does not raise error when running error checks using #after_hooks#without with alert present' do
160
+ url = WatirSpec.url_for('alerts.html')
161
+ @page_after_hook = proc { browser.url }
162
+ browser.after_hooks.add @page_after_hook
163
+ browser.goto url
164
+ expect { browser.after_hooks.without { browser.button(id: 'alert').click } }.to_not raise_error
165
+ browser.alert.ok
166
+ end
162
167
  end
163
168
  end
164
169
 
165
- bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1223277', :firefox do
170
+ bug 'chromedriver 2.43 https://bugs.chromium.org/p/chromedriver/issues/detail?id=2615', :chrome do
166
171
  not_compliant_on :headless do
167
- it 'does not raise error when running error checks on closed window' do
168
- url = WatirSpec.url_for('window_switching.html')
172
+ it 'does not raise error if no error checks are defined with alert present' do
173
+ url = WatirSpec.url_for('alerts.html')
169
174
  @page_after_hook = proc { browser.url }
170
175
  browser.after_hooks.add @page_after_hook
171
176
  browser.goto url
172
- browser.a(id: 'open').click
177
+ browser.after_hooks.delete @page_after_hook
178
+ expect { browser.button(id: 'alert').click }.to_not raise_error
179
+ browser.alert.ok
180
+ end
181
+ end
182
+ end
173
183
 
174
- window = browser.window(title: 'closeable window')
175
- window.use
176
- expect { browser.a(id: 'close').click }.to_not raise_error
177
- browser.original_window.use
184
+ bug 'chromedriver 2.43 https://bugs.chromium.org/p/chromedriver/issues/detail?id=2615', :chrome do
185
+ bug 'https://bugzilla.mozilla.org/show_bug.cgi?id=1223277', :firefox do
186
+ not_compliant_on :headless do
187
+ it 'does not raise error when running error checks on closed window' do
188
+ url = WatirSpec.url_for('window_switching.html')
189
+ @page_after_hook = proc { browser.url }
190
+ browser.after_hooks.add @page_after_hook
191
+ browser.goto url
192
+ browser.a(id: 'open').click
193
+
194
+ window = browser.window(title: 'closeable window')
195
+ window.use
196
+ expect { browser.a(id: 'close').click }.to_not raise_error
197
+ browser.original_window.use
198
+ end
178
199
  end
179
200
  end
180
201
  end
181
202
  end
203
+
204
+ describe '#length' do
205
+ it 'provides the number of after hooks' do
206
+ hook = proc { true }
207
+ begin
208
+ 4.times { browser.after_hooks.add(hook) }
209
+ expect(browser.after_hooks.length).to eq 4
210
+ ensure
211
+ 4.times { browser.after_hooks.delete(hook) }
212
+ end
213
+ end
214
+ end
215
+
216
+ describe '#[]' do
217
+ it 'returns the after hook at the provided index' do
218
+ hook1 = proc { true }
219
+ hook2 = proc { false }
220
+ browser.after_hooks.add(hook1)
221
+ browser.after_hooks.add(hook2)
222
+ expect(browser.after_hooks[1]).to eq hook2
223
+ end
224
+ end
182
225
  end
@@ -10,6 +10,16 @@ not_compliant_on :headless do
10
10
  browser.alert.ok if browser.alert.exists?
11
11
  end
12
12
 
13
+ not_compliant_on :not_relaxed_locate do
14
+ context 'Relaxed Waits' do
15
+ context 'when acting on an alert' do
16
+ it 'raises exception after timing out' do
17
+ expect { browser.alert.text }.to wait_and_raise_unknown_object_exception
18
+ end
19
+ end
20
+ end
21
+ end
22
+
13
23
  context 'alert' do
14
24
  describe '#text' do
15
25
  it 'returns text of alert' do
@@ -381,7 +381,7 @@ describe 'Browser' do
381
381
  browser.span(class: 'footer').click
382
382
  expect(browser.span(class: 'footer').text).to include('Javascript')
383
383
  browser.refresh
384
- browser.span(class: 'footer').wait_until_present
384
+ browser.span(class: 'footer').wait_until(&:present?)
385
385
  expect(browser.span(class: 'footer').text).to_not include('Javascript')
386
386
  end
387
387
  end
@@ -508,6 +508,32 @@ describe 'Browser' do
508
508
  end
509
509
  end
510
510
 
511
+ describe '#wait' do
512
+ # The only way to get engage this method is with page load strategy set to "none"
513
+ # Chrome will be blocking on document ready state because it does not yet support page load strategy
514
+ # This spec is both mocking out the response and demonstrating the necessary settings for it to be meaningful
515
+ not_compliant_on :chrome do
516
+ it 'waits for document ready state to be complete' do
517
+ @original = WatirSpec.implementation.clone
518
+ browser.close
519
+ @opts = WatirSpec.implementation.browser_args.last
520
+
521
+ @opts[:page_load_strategy] = 'none'
522
+ browser = WatirSpec.new_browser
523
+
524
+ start_time = Time.now
525
+ allow(browser).to receive(:ready_state) { Time.now < start_time + 3 ? 'loading' : 'complete' }
526
+ expect(browser.ready_state).to eq 'loading'
527
+ browser.wait(20)
528
+ expect(browser.ready_state).to eq 'complete'
529
+
530
+ browser.close
531
+ WatirSpec.implementation = @original.clone
532
+ $browser = WatirSpec.new_browser
533
+ end
534
+ end
535
+ end
536
+
511
537
  describe '#inspect' do
512
538
  it 'works even if browser is closed' do
513
539
  expect(browser).to receive(:url).and_raise(Errno::ECONNREFUSED)
@@ -69,5 +69,11 @@ describe Watir::Locators::Element::Locator do
69
69
  expect(elements.size).to eq 3
70
70
  end
71
71
  end
72
+
73
+ it 'raises exception when value is not Boolean' do
74
+ element = browser.body.element(visible: 'true')
75
+ msg = 'expected boolean, got "true":String'
76
+ expect { element.exists? }.to raise_exception(TypeError, msg)
77
+ end
72
78
  end
73
79
  end
@@ -94,16 +94,6 @@ describe 'Button' do
94
94
  end
95
95
 
96
96
  # Attribute methods
97
- describe '#class_name' do
98
- it 'returns the class name of the button' do
99
- expect(browser.button(name: 'new_user_image').class_name).to eq 'image'
100
- end
101
-
102
- it 'returns an empty string if the button has no class name' do
103
- expect(browser.button(name: 'new_user_submit').class_name).to eq ''
104
- end
105
- end
106
-
107
97
  describe '#id' do
108
98
  it 'returns the id if the button exists' do
109
99
  expect(browser.button(index: 0).id).to eq 'new_user_submit'
@@ -190,13 +180,17 @@ describe 'Button' do
190
180
  end
191
181
 
192
182
  describe '#text' do
193
- it 'returns the text of the button' do
183
+ it 'returns the text of an input button' do
194
184
  expect(browser.button(index: 0).text).to eq 'Submit'
195
185
  expect(browser.button(index: 1).text).to eq 'Reset'
196
186
  expect(browser.button(index: 2).text).to eq 'Button'
197
187
  expect(browser.button(index: 3).text).to eq 'Preview'
198
188
  end
199
189
 
190
+ it 'returns the text of a button element' do
191
+ expect(browser.button(name: 'new_user_button_2').text).to eq 'Button 2'
192
+ end
193
+
200
194
  it 'raises UnknownObjectException if the element does not exist' do
201
195
  expect { browser.button(id: 'no_such_id').text }.to raise_unknown_object_exception
202
196
  end