watir 7.2.0 → 7.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/chrome.yml +1 -1
  3. data/.github/workflows/edge.yml +1 -1
  4. data/.github/workflows/firefox.yml +1 -1
  5. data/.github/workflows/ie.yml +1 -1
  6. data/.github/workflows/safari.yml +1 -1
  7. data/.github/workflows/unit.yml +1 -1
  8. data/.rubocop.yml +25 -12
  9. data/.rubocop_todo.yml +8 -1
  10. data/CHANGES.md +6 -1
  11. data/LICENSE +2 -2
  12. data/lib/watir/capabilities.rb +1 -1
  13. data/lib/watir/locators/anchor/selector_builder.rb +3 -0
  14. data/lib/watir/locators/element/matcher.rb +2 -1
  15. data/lib/watir/locators/element/selector_builder/regexp_disassembler.rb +2 -1
  16. data/lib/watir/locators/text_field/matcher.rb +0 -4
  17. data/lib/watir/version.rb +1 -1
  18. data/spec/locator_spec_helper.rb +0 -8
  19. data/spec/unit/capabilities_spec.rb +553 -561
  20. data/spec/unit/element_locator_spec.rb +89 -78
  21. data/spec/unit/match_elements/button_spec.rb +69 -62
  22. data/spec/unit/match_elements/element_spec.rb +303 -309
  23. data/spec/unit/match_elements/text_field_spec.rb +76 -73
  24. data/spec/unit/selector_builder/anchor_spec.rb +39 -33
  25. data/spec/unit/selector_builder/button_spec.rb +209 -202
  26. data/spec/unit/selector_builder/cell_spec.rb +48 -42
  27. data/spec/unit/selector_builder/element_spec.rb +634 -627
  28. data/spec/unit/selector_builder/row_spec.rb +119 -113
  29. data/spec/unit/selector_builder/text_field_spec.rb +195 -188
  30. data/spec/unit/selector_builder/textarea_spec.rb +22 -14
  31. data/spec/unit/wait_spec.rb +85 -81
  32. data/spec/watirspec/adjacent_spec.rb +249 -247
  33. data/spec/watirspec/after_hooks_spec.rb +161 -159
  34. data/spec/watirspec/alert_spec.rb +61 -58
  35. data/spec/watirspec/browser_spec.rb +409 -409
  36. data/spec/watirspec/capabilities_spec.rb +89 -99
  37. data/spec/watirspec/cookies_spec.rb +120 -118
  38. data/spec/watirspec/drag_and_drop_spec.rb +26 -24
  39. data/spec/watirspec/element_hidden_spec.rb +66 -60
  40. data/spec/watirspec/elements/area_spec.rb +49 -47
  41. data/spec/watirspec/elements/areas_spec.rb +27 -25
  42. data/spec/watirspec/elements/button_spec.rb +253 -251
  43. data/spec/watirspec/elements/buttons_spec.rb +36 -34
  44. data/spec/watirspec/elements/checkbox_spec.rb +48 -36
  45. data/spec/watirspec/elements/checkboxes_spec.rb +29 -27
  46. data/spec/watirspec/elements/collections_spec.rb +126 -119
  47. data/spec/watirspec/elements/date_field_spec.rb +185 -183
  48. data/spec/watirspec/elements/date_fields_spec.rb +29 -27
  49. data/spec/watirspec/elements/date_time_field_spec.rb +197 -195
  50. data/spec/watirspec/elements/date_time_fields_spec.rb +30 -28
  51. data/spec/watirspec/elements/dd_spec.rb +87 -85
  52. data/spec/watirspec/elements/dds_spec.rb +27 -25
  53. data/spec/watirspec/elements/del_spec.rb +106 -104
  54. data/spec/watirspec/elements/dels_spec.rb +26 -24
  55. data/spec/watirspec/elements/div_spec.rb +225 -221
  56. data/spec/watirspec/elements/divs_spec.rb +37 -35
  57. data/spec/watirspec/elements/dl_spec.rb +110 -108
  58. data/spec/watirspec/elements/dls_spec.rb +28 -26
  59. data/spec/watirspec/elements/dt_spec.rb +86 -84
  60. data/spec/watirspec/elements/dts_spec.rb +27 -25
  61. data/spec/watirspec/elements/element_spec.rb +794 -775
  62. data/spec/watirspec/elements/elements_spec.rb +40 -38
  63. data/spec/watirspec/elements/em_spec.rb +62 -60
  64. data/spec/watirspec/elements/ems_spec.rb +28 -26
  65. data/spec/watirspec/elements/filefield_spec.rb +116 -114
  66. data/spec/watirspec/elements/filefields_spec.rb +28 -26
  67. data/spec/watirspec/elements/font_spec.rb +20 -18
  68. data/spec/watirspec/elements/form_spec.rb +51 -49
  69. data/spec/watirspec/elements/forms_spec.rb +29 -27
  70. data/spec/watirspec/elements/frame_spec.rb +89 -87
  71. data/spec/watirspec/elements/frames_spec.rb +27 -25
  72. data/spec/watirspec/elements/hidden_spec.rb +81 -79
  73. data/spec/watirspec/elements/hiddens_spec.rb +28 -26
  74. data/spec/watirspec/elements/hn_spec.rb +59 -57
  75. data/spec/watirspec/elements/hns_spec.rb +26 -24
  76. data/spec/watirspec/elements/iframe_spec.rb +195 -191
  77. data/spec/watirspec/elements/iframes_spec.rb +31 -29
  78. data/spec/watirspec/elements/image_spec.rb +148 -146
  79. data/spec/watirspec/elements/images_spec.rb +26 -24
  80. data/spec/watirspec/elements/input_spec.rb +9 -7
  81. data/spec/watirspec/elements/ins_spec.rb +106 -104
  82. data/spec/watirspec/elements/inses_spec.rb +26 -24
  83. data/spec/watirspec/elements/label_spec.rb +56 -54
  84. data/spec/watirspec/elements/labels_spec.rb +26 -24
  85. data/spec/watirspec/elements/li_spec.rb +76 -74
  86. data/spec/watirspec/elements/link_spec.rb +173 -177
  87. data/spec/watirspec/elements/links_spec.rb +45 -43
  88. data/spec/watirspec/elements/lis_spec.rb +27 -25
  89. data/spec/watirspec/elements/list_spec.rb +44 -42
  90. data/spec/watirspec/elements/map_spec.rb +57 -55
  91. data/spec/watirspec/elements/maps_spec.rb +27 -25
  92. data/spec/watirspec/elements/meta_spec.rb +16 -14
  93. data/spec/watirspec/elements/metas_spec.rb +26 -24
  94. data/spec/watirspec/elements/ol_spec.rb +56 -65
  95. data/spec/watirspec/elements/ols_spec.rb +26 -24
  96. data/spec/watirspec/elements/option_spec.rb +91 -89
  97. data/spec/watirspec/elements/p_spec.rb +81 -79
  98. data/spec/watirspec/elements/pre_spec.rb +77 -75
  99. data/spec/watirspec/elements/pres_spec.rb +26 -24
  100. data/spec/watirspec/elements/ps_spec.rb +26 -24
  101. data/spec/watirspec/elements/radio_spec.rb +251 -249
  102. data/spec/watirspec/elements/radios_spec.rb +28 -26
  103. data/spec/watirspec/elements/select_list_spec.rb +537 -526
  104. data/spec/watirspec/elements/select_lists_spec.rb +32 -30
  105. data/spec/watirspec/elements/span_spec.rb +112 -110
  106. data/spec/watirspec/elements/spans_spec.rb +26 -24
  107. data/spec/watirspec/elements/strong_spec.rb +58 -58
  108. data/spec/watirspec/elements/strongs_spec.rb +28 -26
  109. data/spec/watirspec/elements/table_spec.rb +192 -139
  110. data/spec/watirspec/elements/tables_spec.rb +28 -26
  111. data/spec/watirspec/elements/tbody_spec.rb +74 -72
  112. data/spec/watirspec/elements/tbodys_spec.rb +40 -38
  113. data/spec/watirspec/elements/td_spec.rb +66 -64
  114. data/spec/watirspec/elements/tds_spec.rb +41 -39
  115. data/spec/watirspec/elements/text_field_spec.rb +206 -204
  116. data/spec/watirspec/elements/text_fields_spec.rb +30 -28
  117. data/spec/watirspec/elements/textarea_spec.rb +20 -18
  118. data/spec/watirspec/elements/textareas_spec.rb +18 -16
  119. data/spec/watirspec/elements/tfoot_spec.rb +65 -63
  120. data/spec/watirspec/elements/tfoots_spec.rb +42 -40
  121. data/spec/watirspec/elements/thead_spec.rb +65 -63
  122. data/spec/watirspec/elements/theads_spec.rb +42 -40
  123. data/spec/watirspec/elements/tr_spec.rb +48 -46
  124. data/spec/watirspec/elements/trs_spec.rb +42 -40
  125. data/spec/watirspec/elements/ul_spec.rb +56 -54
  126. data/spec/watirspec/elements/uls_spec.rb +26 -24
  127. data/spec/watirspec/radio_set_spec.rb +269 -267
  128. data/spec/watirspec/screenshot_spec.rb +20 -18
  129. data/spec/watirspec/scroll_spec.rb +152 -148
  130. data/spec/watirspec/shadow_root_spec.rb +86 -83
  131. data/spec/watirspec/user_editable_spec.rb +200 -198
  132. data/spec/watirspec/wait_spec.rb +289 -295
  133. data/spec/watirspec/window_switching_spec.rb +422 -434
  134. data/spec/watirspec_helper.rb +1 -23
  135. data/watir.gemspec +5 -4
  136. metadata +44 -33
  137. data/spec/watirspec/attributes_spec.rb +0 -18
  138. data/spec/watirspec/elements/table_nesting_spec.rb +0 -51
  139. data/spec/watirspec/special_chars_spec.rb +0 -23
@@ -2,1049 +2,1068 @@
2
2
 
3
3
  require 'watirspec_helper'
4
4
 
5
- describe 'Element' do
6
- before :each do
7
- @c = Selenium::WebDriver::Platform.mac? ? :command : :control
8
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
9
- end
10
-
11
- describe '.new' do
12
- it "finds elements matching the conditions when given a hash of :how => 'what' arguments" do
13
- expect(browser.checkbox(name: 'new_user_interests', title: 'Dancing is fun!').value).to eq 'dancing'
14
- expect(browser.text_field(class_name: 'name', index: 1).id).to eq 'new_user_last_name'
5
+ module Watir
6
+ describe Element do
7
+ before do
8
+ @c = Selenium::WebDriver::Platform.mac? ? :command : :control
9
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
15
10
  end
16
11
 
17
- it "raises UnknownObjectException when given a hash of :how => 'what' arguments (non-existing object)" do
18
- expect { browser.text_field(index: 100, name: 'foo').id }.to raise_unknown_object_exception
19
- end
12
+ describe '.new' do
13
+ it "finds elements matching the conditions when given a hash of :how => 'what' arguments" do
14
+ expect(browser.checkbox(name: 'new_user_interests', title: 'Dancing is fun!').value).to eq 'dancing'
15
+ expect(browser.text_field(class_name: 'name', index: 1).id).to eq 'new_user_last_name'
16
+ end
20
17
 
21
- it 'raises ArgumentError if given the wrong number of arguments' do
22
- container = double('container').as_null_object
23
- expect { Watir::Element.new(container, 1, 2, 3, 4) }.to raise_error(ArgumentError)
24
- expect { Watir::Element.new(container, 'foo') }.to raise_error(ArgumentError)
18
+ it "raises UnknownObjectException when given a hash of :how => 'what' arguments (non-existing object)" do
19
+ expect { browser.text_field(index: 100, name: 'foo').id }.to raise_unknown_object_exception
20
+ end
21
+
22
+ it 'raises ArgumentError if given the wrong number of arguments' do
23
+ expect { described_class.new(browser.wd, 'foo') }.to raise_error(ArgumentError)
24
+ end
25
25
  end
26
- end
27
26
 
28
- describe '#element_call' do
29
- it 'handles exceptions when taking an action on a stale element' do
30
- browser.goto WatirSpec.url_for('removed_element.html')
27
+ describe '#element_call' do
28
+ it 'handles exceptions when taking an action on a stale element' do
29
+ browser.goto WatirSpec.url_for('removed_element.html')
31
30
 
32
- element = browser.div(id: 'text').locate
31
+ element = browser.div(id: 'text').locate
33
32
 
34
- browser.refresh
33
+ browser.refresh
35
34
 
36
- expect(element).to be_stale
37
- expect { element.text }.to_not raise_error
38
- end
35
+ expect(element).to be_stale
36
+ expect { element.text }.not_to raise_error
37
+ end
39
38
 
40
- it 'relocates stale element when taking an action on it' do
41
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
42
- element = browser.text_field(id: 'new_user_first_name').locate
43
- browser.refresh
44
- expect { element.click }.not_to raise_exception
39
+ it 'relocates stale element when taking an action on it' do
40
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
41
+ element = browser.text_field(id: 'new_user_first_name').locate
42
+ browser.refresh
43
+ expect { element.click }.not_to raise_exception
44
+ end
45
45
  end
46
- end
47
46
 
48
- describe '#eq and #eql?' do
49
- before { browser.goto WatirSpec.url_for('definition_lists.html') }
47
+ describe '#eq and #eql?' do
48
+ before { browser.goto WatirSpec.url_for('definition_lists.html') }
50
49
 
51
- it 'returns true if the two elements point to the same DOM element' do
52
- a = browser.dl(id: 'experience-list')
53
- b = browser.dl
50
+ it 'returns true if the two elements point to the same DOM element' do
51
+ a = browser.dl(id: 'experience-list')
52
+ b = browser.dl
54
53
 
55
- expect(a).to eq b
56
- expect(a).to eql(b)
57
- end
54
+ expect(a).to eq b
55
+ expect(a).to eql(b)
56
+ end
58
57
 
59
- it 'returns false if the two elements are not the same' do
60
- a = browser.dls[0]
61
- b = browser.dls[1]
58
+ it 'returns false if the two elements are not the same' do
59
+ a = browser.dls[0]
60
+ b = browser.dls[1]
62
61
 
63
- expect(a).to_not eq b
64
- expect(a).to_not eql(b)
65
- end
62
+ expect(a).not_to eq b
63
+ expect(a).not_to eql(b)
64
+ end
66
65
 
67
- it 'returns false if the other object is not an Element' do
68
- expect(browser.dl).to_not eq 1
66
+ it 'returns false if the other object is not an Element' do
67
+ expect(browser.dl).not_to eq 1
68
+ end
69
69
  end
70
- end
71
70
 
72
- describe 'data-* attributes' do
73
- before { browser.goto WatirSpec.url_for('data_attributes.html') }
71
+ describe 'data-* attributes' do
72
+ before { browser.goto WatirSpec.url_for('data_attributes.html') }
74
73
 
75
- it 'finds elements by a data-* attribute' do
76
- expect(browser.p(data_type: 'ruby-library')).to exist
77
- end
74
+ it 'finds elements by a data-* attribute' do
75
+ expect(browser.p(data_type: 'ruby-library')).to exist
76
+ end
78
77
 
79
- it 'returns the value of a data-* attribute' do
80
- expect(browser.p.data_type).to eq 'ruby-library'
78
+ it 'returns the value of a data-* attribute' do
79
+ expect(browser.p.data_type).to eq 'ruby-library'
80
+ end
81
81
  end
82
- end
83
82
 
84
- describe 'aria-* attributes' do
85
- before { browser.goto WatirSpec.url_for('aria_attributes.html') }
83
+ describe 'aria-* attributes' do
84
+ before { browser.goto WatirSpec.url_for('aria_attributes.html') }
86
85
 
87
- it 'finds elements by a aria-* attribute' do
88
- expect(browser.p(aria_label: 'ruby-library')).to exist
89
- end
86
+ it 'finds elements by a aria-* attribute' do
87
+ expect(browser.p(aria_label: 'ruby-library')).to exist
88
+ end
90
89
 
91
- it 'returns the value of a aria-* attribute' do
92
- expect(browser.p.aria_label).to eq 'ruby-library'
90
+ it 'returns the value of a aria-* attribute' do
91
+ expect(browser.p.aria_label).to eq 'ruby-library'
92
+ end
93
93
  end
94
- end
95
94
 
96
- describe 'visible text' do
97
- it 'finds elements by visible text' do
98
- browser.goto WatirSpec.url_for('non_control_elements.html')
95
+ describe 'visible text' do
96
+ it 'finds elements by visible text' do
97
+ browser.goto WatirSpec.url_for('non_control_elements.html')
99
98
 
100
- expect(browser.element(visible_text: 'all visible')).to exist
101
- expect(browser.element(visible_text: /all visible/)).to exist
102
- expect(browser.element(visible_text: /some visible/)).to exist
103
- expect(browser.element(visible_text: 'Link 2', class: 'external')).to exist
104
- expect(browser.element(visible_text: /Link 2/, class: 'external')).to exist
105
- end
99
+ expect(browser.element(visible_text: 'all visible')).to exist
100
+ expect(browser.element(visible_text: /all visible/)).to exist
101
+ expect(browser.element(visible_text: /some visible/)).to exist
102
+ expect(browser.element(visible_text: 'Link 2', class: 'external')).to exist
103
+ expect(browser.element(visible_text: /Link 2/, class: 'external')).to exist
104
+ end
106
105
 
107
- it 'finds elements by visible text in spite of hidden text',
108
- except: {browser: :safari, reason: 'Safari is not filtering out hidden text'} do
109
- browser.goto WatirSpec.url_for('non_control_elements.html')
106
+ it 'finds elements by visible text in spite of hidden text',
107
+ except: {browser: :safari, reason: 'Safari is not filtering out hidden text'} do
108
+ browser.goto WatirSpec.url_for('non_control_elements.html')
110
109
 
111
- expect(browser.element(visible_text: 'some visible')).to exist
112
- expect(browser.element(visible_text: 'none visible')).not_to exist
113
- expect(browser.element(visible_text: /none visible/)).not_to exist
114
- end
110
+ expect(browser.element(visible_text: 'some visible')).to exist
111
+ expect(browser.element(visible_text: 'none visible')).not_to exist
112
+ expect(browser.element(visible_text: /none visible/)).not_to exist
113
+ end
115
114
 
116
- it 'raises exception unless value is a String or a RegExp' do
117
- browser.goto WatirSpec.url_for('non_control_elements.html')
118
- msg = /expected one of \[String, Regexp\], got 7:Integer/
119
- expect { browser.element(visible_text: 7).exists? }.to raise_exception(TypeError, msg)
120
- end
115
+ it 'raises exception unless value is a String or a RegExp' do
116
+ browser.goto WatirSpec.url_for('non_control_elements.html')
117
+ msg = /expected one of \[String, Regexp\], got 7:Integer/
118
+ expect { browser.element(visible_text: 7).exists? }.to raise_exception(TypeError, msg)
119
+ end
121
120
 
122
- it 'raises exception unless key is valid' do
123
- browser.goto WatirSpec.url_for('non_control_elements.html')
124
- msg = /Unable to build XPath using 7:Integer/
125
- expect { browser.element(7 => /foo/).exists? }.to raise_exception(Watir::Exception::Error, msg)
121
+ it 'raises exception unless key is valid' do
122
+ browser.goto WatirSpec.url_for('non_control_elements.html')
123
+ msg = /Unable to build XPath using 7:Integer/
124
+ expect { browser.element(7 => /foo/).exists? }.to raise_exception(Watir::Exception::Error, msg)
125
+ end
126
126
  end
127
- end
128
127
 
129
- describe 'finding with unknown tag name' do
130
- it 'finds an element without arguments' do
131
- expect(browser.element).to exist
132
- end
128
+ describe 'finding with unknown tag name' do
129
+ it 'finds an element without arguments' do
130
+ expect(browser.element).to exist
131
+ end
133
132
 
134
- it 'finds an element by xpath' do
135
- expect(browser.element(xpath: "//*[@for='new_user_first_name']")).to exist
136
- end
133
+ it 'finds an element by xpath' do
134
+ expect(browser.element(xpath: "//*[@for='new_user_first_name']")).to exist
135
+ end
137
136
 
138
- it 'finds an element by arbitrary attribute' do
139
- expect(browser.element(title: 'no title')).to exist
140
- end
137
+ it 'finds an element by arbitrary attribute' do
138
+ expect(browser.element(title: 'no title')).to exist
139
+ end
141
140
 
142
- it 'finds several elements by xpath' do
143
- expect(browser.elements(xpath: '//a').length).to eq 1
144
- end
141
+ it 'finds several elements by xpath' do
142
+ expect(browser.elements(xpath: '//a').length).to eq 1
143
+ end
145
144
 
146
- it 'finds several elements by arbitrary attribute' do
147
- expect(browser.elements(id: /^new_user/).length).to eq 33
148
- end
145
+ it 'finds several elements by arbitrary attribute' do
146
+ expect(browser.elements(id: /^new_user/).length).to eq 33
147
+ end
149
148
 
150
- it "finds an element from an element's subtree" do
151
- expect(browser.fieldset.element(id: 'first_label')).to exist
152
- expect(browser.field_set.element(id: 'first_label')).to exist
153
- end
149
+ it "finds an element from an element's subtree" do
150
+ expect(browser.fieldset.element(id: 'first_label')).to exist
151
+ expect(browser.field_set.element(id: 'first_label')).to exist
152
+ end
154
153
 
155
- it "finds several elements from an element's subtree" do
156
- expect(browser.fieldset.elements(xpath: './/label').length).to eq 23
154
+ it "finds several elements from an element's subtree" do
155
+ expect(browser.fieldset.elements(xpath: './/label').length).to eq 23
156
+ end
157
157
  end
158
- end
159
158
 
160
- describe '#to_subtype' do
161
- it 'returns a CheckBox instance' do
162
- e = browser.input(xpath: "//input[@type='checkbox']").to_subtype
163
- expect(e).to be_kind_of(Watir::CheckBox)
164
- end
159
+ describe '#to_subtype' do
160
+ it 'returns a CheckBox instance' do
161
+ e = browser.input(xpath: "//input[@type='checkbox']").to_subtype
162
+ expect(e).to be_a(Watir::CheckBox)
163
+ end
165
164
 
166
- it 'returns a Radio instance' do
167
- e = browser.input(xpath: "//input[@type='radio']").to_subtype
168
- expect(e).to be_kind_of(Watir::Radio)
169
- end
165
+ it 'returns a Radio instance' do
166
+ e = browser.input(xpath: "//input[@type='radio']").to_subtype
167
+ expect(e).to be_a(Watir::Radio)
168
+ end
170
169
 
171
- it 'returns a Button instance' do
172
- es = [
173
- browser.input(xpath: "//input[@type='button']").to_subtype,
174
- browser.input(xpath: "//input[@type='submit']").to_subtype,
175
- browser.input(xpath: "//input[@type='reset']").to_subtype,
176
- browser.input(xpath: "//input[@type='image']").to_subtype
177
- ]
170
+ it 'returns a Button instance' do
171
+ es = [
172
+ browser.input(xpath: "//input[@type='button']").to_subtype,
173
+ browser.input(xpath: "//input[@type='submit']").to_subtype,
174
+ browser.input(xpath: "//input[@type='reset']").to_subtype,
175
+ browser.input(xpath: "//input[@type='image']").to_subtype
176
+ ]
178
177
 
179
- es.all? { |e| expect(e).to be_kind_of(Watir::Button) }
180
- end
178
+ es.all? { |e| expect(e).to be_a(Watir::Button) }
179
+ end
181
180
 
182
- it 'returns a TextField instance' do
183
- e = browser.input(xpath: "//input[@type='text']").to_subtype
184
- expect(e).to be_kind_of(Watir::TextField)
185
- end
181
+ it 'returns a TextField instance' do
182
+ e = browser.input(xpath: "//input[@type='text']").to_subtype
183
+ expect(e).to be_a(Watir::TextField)
184
+ end
186
185
 
187
- it 'returns a FileField instance' do
188
- e = browser.input(xpath: "//input[@type='file']").to_subtype
189
- expect(e).to be_kind_of(Watir::FileField)
190
- end
186
+ it 'returns a FileField instance' do
187
+ e = browser.input(xpath: "//input[@type='file']").to_subtype
188
+ expect(e).to be_a(Watir::FileField)
189
+ end
191
190
 
192
- it 'returns a Div instance' do
193
- el = browser.element(xpath: "//*[@id='messages']").to_subtype
194
- expect(el).to be_kind_of(Watir::Div)
191
+ it 'returns a Div instance' do
192
+ el = browser.element(xpath: "//*[@id='messages']").to_subtype
193
+ expect(el).to be_a(Watir::Div)
194
+ end
195
195
  end
196
- end
197
196
 
198
- describe '#focus' do
199
- it 'fires the onfocus event for the given element' do
200
- tf = browser.text_field(id: 'new_user_occupation')
201
- expect(tf.value).to eq 'Developer'
202
- tf.focus
203
- expect(browser.div(id: 'onfocus_test').text).to eq 'changed by onfocus event'
197
+ describe '#focus' do
198
+ it 'fires the onfocus event for the given element' do
199
+ tf = browser.text_field(id: 'new_user_occupation')
200
+ expect(tf.value).to eq 'Developer'
201
+ tf.focus
202
+ expect(browser.div(id: 'onfocus_test').text).to eq 'changed by onfocus event'
203
+ end
204
204
  end
205
- end
206
205
 
207
- describe '#focused?',
208
- except: {browser: :firefox,
209
- driver: :remote_driver,
210
- reason: 'https://github.com/SeleniumHQ/selenium/issues/2555'} do
211
- it 'knows if the element is focused' do
212
- expect(browser.element(id: 'new_user_first_name')).to be_focused
213
- expect(browser.element(id: 'new_user_last_name')).to_not be_focused
206
+ describe '#focused?',
207
+ except: {browser: :firefox,
208
+ driver: :remote_driver,
209
+ reason: 'https://github.com/SeleniumHQ/selenium/issues/2555'} do
210
+ it 'knows if the element is focused' do
211
+ expect(browser.element(id: 'new_user_first_name')).to be_focused
212
+ expect(browser.element(id: 'new_user_last_name')).not_to be_focused
213
+ end
214
214
  end
215
- end
216
215
 
217
- describe '#fire_event' do
218
- it 'should fire the given event' do
219
- expect(browser.div(id: 'onfocus_test').text).to be_empty
220
- browser.text_field(id: 'new_user_occupation').fire_event('onfocus')
221
- expect(browser.div(id: 'onfocus_test').text).to eq 'changed by onfocus event'
216
+ describe '#fire_event' do
217
+ it 'fires the given event' do
218
+ expect(browser.div(id: 'onfocus_test').text).to be_empty
219
+ browser.text_field(id: 'new_user_occupation').fire_event('onfocus')
220
+ expect(browser.div(id: 'onfocus_test').text).to eq 'changed by onfocus event'
221
+ end
222
222
  end
223
- end
224
-
225
- describe '#cache=' do
226
- it 'bypasses selector location' do
227
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
228
223
 
229
- wd = browser.div.wd
230
- element = Watir::Element.new(browser, id: 'not_valid')
231
- element.cache = wd
224
+ describe '#cache=' do
225
+ it 'bypasses selector location' do
226
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
232
227
 
233
- expect(element).to exist
234
- end
228
+ wd = browser.div.wd
229
+ element = described_class.new(browser, id: 'not_valid')
230
+ element.cache = wd
235
231
 
236
- it 'can be cleared' do
237
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
232
+ expect(element).to exist
233
+ end
238
234
 
239
- wd = browser.div.wd
240
- element = Watir::Element.new(browser, id: 'not_valid')
241
- element.cache = wd
235
+ it 'can be cleared' do
236
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
242
237
 
243
- browser.refresh
244
- expect(element).to_not exist
245
- end
246
- end
238
+ wd = browser.div.wd
239
+ element = described_class.new(browser, id: 'not_valid')
240
+ element.cache = wd
247
241
 
248
- describe '#exists?' do
249
- before do
250
- browser.goto WatirSpec.url_for('removed_element.html')
242
+ browser.refresh
243
+ expect(element).not_to exist
244
+ end
251
245
  end
252
246
 
253
- it 'element from a collection is re-looked up after it becomes stale',
254
- except: {browser: :ie, reason: 'throwing NoSuchElement instead'} do
255
- element = browser.divs(id: 'text').first.locate
256
-
257
- browser.refresh
258
-
259
- expect(element).to be_stale
260
- expect(element).to exist
261
- end
247
+ describe '#exists?' do
248
+ before do
249
+ browser.goto WatirSpec.url_for('removed_element.html')
250
+ end
262
251
 
263
- it 'element from a selenium element throws an exception when relocated',
264
- except: {browser: :ie, reason: 'throwing NoSuchElement instead'} do
265
- div = browser.div.locate
266
- element = browser.element(element: div.wd)
252
+ it 'element from a collection is re-looked up after it becomes stale',
253
+ except: {browser: :ie, reason: 'throwing NoSuchElement instead'} do
254
+ element = browser.divs(id: 'text').first.locate
267
255
 
268
- browser.refresh
269
- expect(element).to be_stale
256
+ browser.refresh
270
257
 
271
- msg = 'Can not relocate a Watir element initialized by a Selenium element'
272
- expect { element.exists? }.to raise_exception(Watir::Exception::LocatorException, msg)
273
- end
258
+ expect(element).to be_stale
259
+ expect(element).to exist
260
+ end
274
261
 
275
- it 'element from a selenium element with other locators throws an exception' do
276
- div = browser.div.locate
277
- element = browser.element(element: div.wd, id: 'foo')
262
+ it 'element from a selenium element throws an exception when relocated',
263
+ except: {browser: :ie, reason: 'throwing NoSuchElement instead'} do
264
+ div = browser.div.locate
265
+ element = browser.element(element: div.wd)
278
266
 
279
- browser.refresh
267
+ browser.refresh
268
+ expect(element).to be_stale
280
269
 
281
- msg = 'Can not relocate a Watir element initialized by a Selenium element'
282
- expect { element.exists? }.to raise_exception(Watir::Exception::LocatorException, msg)
283
- end
270
+ msg = 'Can not relocate a Watir element initialized by a Selenium element'
271
+ expect { element.exists? }.to raise_exception(Watir::Exception::LocatorException, msg)
272
+ end
284
273
 
285
- it 'returns false when tag name does not match id' do
286
- watir_element = browser.span(id: 'text')
287
- expect(watir_element).to_not exist
288
- end
289
- end
274
+ it 'element from a selenium element with other locators throws an exception' do
275
+ div = browser.div.locate
276
+ element = browser.element(element: div.wd, id: 'foo')
290
277
 
291
- describe '#present?' do
292
- before do
293
- browser.goto(WatirSpec.url_for('wait.html'))
294
- end
278
+ browser.refresh
295
279
 
296
- it 'returns true if the element exists and is visible' do
297
- expect(browser.div(id: 'foo')).to be_present
298
- end
280
+ msg = 'Can not relocate a Watir element initialized by a Selenium element'
281
+ expect { element.exists? }.to raise_exception(Watir::Exception::LocatorException, msg)
282
+ end
299
283
 
300
- it 'returns false if the element exists but is not visible' do
301
- expect(browser.div(id: 'bar')).to_not be_present
284
+ it 'returns false when tag name does not match id' do
285
+ watir_element = browser.span(id: 'text')
286
+ expect(watir_element).not_to exist
287
+ end
302
288
  end
303
289
 
304
- it 'returns false if the element does not exist' do
305
- expect(browser.div(id: 'should-not-exist')).to_not be_present
306
- end
290
+ describe '#present?' do
291
+ before do
292
+ browser.goto(WatirSpec.url_for('wait.html'))
293
+ end
307
294
 
308
- it 'handles staleness' do
309
- element = browser.div(id: 'foo').locate
295
+ it 'returns true if the element exists and is visible' do
296
+ expect(browser.div(id: 'foo')).to be_present
297
+ end
310
298
 
311
- allow(element).to receive(:stale?).and_return(true)
299
+ it 'returns false if the element exists but is not visible' do
300
+ expect(browser.div(id: 'bar')).not_to be_present
301
+ end
312
302
 
313
- expect(element).to be_present
314
- end
315
- end
303
+ it 'returns false if the element does not exist' do
304
+ expect(browser.div(id: 'should-not-exist')).not_to be_present
305
+ end
316
306
 
317
- describe '#enabled?' do
318
- before do
319
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
320
- end
307
+ it 'handles staleness' do
308
+ element = browser.div(id: 'foo').locate
321
309
 
322
- it 'returns true if the element is enabled' do
323
- expect(browser.button(name: 'new_user_submit')).to be_enabled
324
- end
310
+ allow(element).to receive(:stale?).and_return(true)
325
311
 
326
- it 'returns false if the element is disabled' do
327
- expect(browser.button(name: 'new_user_submit_disabled')).to_not be_enabled
312
+ expect(element).to be_present
313
+ end
328
314
  end
329
315
 
330
- it "raises UnknownObjectException if the element doesn't exist" do
331
- expect { browser.button(name: 'no_such_name').enabled? }.to raise_unknown_object_exception
332
- end
333
- end
316
+ describe '#enabled?' do
317
+ before do
318
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
319
+ end
334
320
 
335
- describe '#stale?' do
336
- it 'returns true if the element is stale' do
337
- element = browser.button(name: 'new_user_submit_disabled').locate
321
+ it 'returns true if the element is enabled' do
322
+ expect(browser.button(name: 'new_user_submit')).to be_enabled
323
+ end
338
324
 
339
- browser.refresh
325
+ it 'returns false if the element is disabled' do
326
+ expect(browser.button(name: 'new_user_submit_disabled')).not_to be_enabled
327
+ end
340
328
 
341
- expect(element).to be_stale
329
+ it "raises UnknownObjectException if the element doesn't exist" do
330
+ expect { browser.button(name: 'no_such_name').enabled? }.to raise_unknown_object_exception
331
+ end
342
332
  end
343
333
 
344
- it 'returns true the second time if the element is stale',
345
- except: {browser: :ie, reason: 'throwing NoSuchElement instead'} do
346
- element = browser.div.locate
334
+ describe '#stale?' do
335
+ it 'returns true if the element is stale' do
336
+ element = browser.button(name: 'new_user_submit_disabled').locate
347
337
 
348
- browser.refresh
338
+ browser.refresh
349
339
 
350
- expect(element).to be_stale
351
- expect(element).to be_stale
352
- end
340
+ expect(element).to be_stale
341
+ end
353
342
 
354
- it 'returns false if the element is not stale' do
355
- element = browser.button(name: 'new_user_submit_disabled').locate
343
+ it 'returns true the second time if the element is stale',
344
+ except: {browser: :ie, reason: 'throwing NoSuchElement instead'} do
345
+ element = browser.div.locate
356
346
 
357
- expect(element).to_not be_stale
358
- end
359
- end
347
+ browser.refresh
360
348
 
361
- describe '#exist?' do
362
- context ':class locator' do
363
- before do
364
- browser.goto(WatirSpec.url_for('class_locator.html'))
349
+ expect(element).to be_stale
350
+ expect(element).to be_stale
365
351
  end
366
352
 
367
- it 'matches when the element has a single class' do
368
- e = browser.div(class: 'a')
369
- expect(e).to exist
370
- expect(e.class_name).to eq 'a'
371
- end
353
+ it 'returns false if the element is not stale' do
354
+ element = browser.button(name: 'new_user_submit_disabled').locate
372
355
 
373
- it 'matches when the element has several classes' do
374
- e = browser.div(class: 'b')
375
- expect(e).to exist
376
- expect(e.class_name).to eq 'a b c'
377
- end
378
-
379
- it 'does not match only part of the class name' do
380
- expect(browser.div(class: 'bc')).to_not exist
356
+ expect(element).not_to be_stale
381
357
  end
358
+ end
382
359
 
383
- it 'matches part of the class name when given a regexp' do
384
- expect(browser.div(class: /c/)).to exist
385
- end
360
+ describe '#exist?' do
361
+ context 'when using :class locator' do
362
+ before do
363
+ browser.goto(WatirSpec.url_for('class_locator.html'))
364
+ end
386
365
 
387
- context 'with multiple classes' do
388
366
  it 'matches when the element has a single class' do
389
- e = browser.div(class: ['a'])
367
+ e = browser.div(class: 'a')
390
368
  expect(e).to exist
391
369
  expect(e.class_name).to eq 'a'
392
370
  end
393
371
 
394
- it 'matches a non-ordered subset' do
395
- e = browser.div(class: %w[c a])
372
+ it 'matches when the element has several classes' do
373
+ e = browser.div(class: 'b')
396
374
  expect(e).to exist
397
375
  expect(e.class_name).to eq 'a b c'
398
376
  end
399
377
 
400
- it 'matches one with a negation' do
401
- e = browser.div(class: ['!a'])
402
- expect(e).to exist
403
- expect(e.class_name).to eq 'abc'
378
+ it 'does not match only part of the class name' do
379
+ expect(browser.div(class: 'bc')).not_to exist
404
380
  end
405
381
 
406
- it 'matches multiple with a negation' do
407
- e = browser.div(class: ['a', '!c', 'b'])
408
- expect(e).to exist
409
- expect(e.class_name).to eq 'a b'
382
+ it 'matches part of the class name when given a regexp' do
383
+ expect(browser.div(class: /c/)).to exist
410
384
  end
411
385
 
412
- it 'matches with any whitespace' do
413
- e = browser.div(class: %w[newline tabbed])
414
- expect(e).to exist
415
- expect(e.class_name).to eq "first\nnewline\ttabbed last"
386
+ context 'with multiple classes' do
387
+ it 'matches when the element has a single class' do
388
+ e = browser.div(class: ['a'])
389
+ expect(e).to exist
390
+ expect(e.class_name).to eq 'a'
391
+ end
392
+
393
+ it 'matches a non-ordered subset' do
394
+ e = browser.div(class: %w[c a])
395
+ expect(e).to exist
396
+ expect(e.class_name).to eq 'a b c'
397
+ end
398
+
399
+ it 'matches one with a negation' do
400
+ e = browser.div(class: ['!a'])
401
+ expect(e).to exist
402
+ expect(e.class_name).to eq 'abc'
403
+ end
404
+
405
+ it 'matches multiple with a negation' do
406
+ e = browser.div(class: ['a', '!c', 'b'])
407
+ expect(e).to exist
408
+ expect(e.class_name).to eq 'a b'
409
+ end
410
+
411
+ it 'matches with any whitespace' do
412
+ e = browser.div(class: %w[newline tabbed])
413
+ expect(e).to exist
414
+ expect(e.class_name).to eq "first\nnewline\ttabbed last"
415
+ end
416
416
  end
417
417
  end
418
- end
419
418
 
420
- context 'attribute presence' do
421
- before { browser.goto WatirSpec.url_for('data_attributes.html') }
419
+ context 'when using attribute presence' do
420
+ before { browser.goto WatirSpec.url_for('data_attributes.html') }
421
+
422
+ it 'finds element by attribute presence' do
423
+ expect(browser.p(data_type: true)).to exist
424
+ expect(browser.p(class: true)).not_to exist
425
+ end
422
426
 
423
- it 'finds element by attribute presence' do
424
- expect(browser.p(data_type: true)).to exist
425
- expect(browser.p(class: true)).not_to exist
427
+ it 'finds element by attribute absence' do
428
+ expect(browser.p(data_type: false)).not_to exist
429
+ expect(browser.p(class: false)).to exist
430
+ end
426
431
  end
427
432
 
428
- it 'finds element by attribute absence' do
429
- expect(browser.p(data_type: false)).not_to exist
430
- expect(browser.p(class: false)).to exist
433
+ context 'when using :index locator' do
434
+ before { browser.goto WatirSpec.url_for('data_attributes.html') }
435
+
436
+ it 'finds the first element by index: 0' do
437
+ expect(browser.element(index: 0).tag_name).to eq 'html'
438
+ end
439
+
440
+ it 'finds the second element by index: 1' do
441
+ expect(browser.element(index: 1).tag_name).to eq 'head'
442
+ end
443
+
444
+ it 'finds the last element by index: -1' do
445
+ expect(browser.element(index: -1).tag_name).to eq 'div'
446
+ end
431
447
  end
432
- end
433
448
 
434
- context ':index locator' do
435
- before { browser.goto WatirSpec.url_for('data_attributes.html') }
449
+ it "doesn't raise when called on nested elements" do
450
+ expect(browser.div(id: 'no_such_div').link(id: 'no_such_id')).not_to exist
451
+ end
436
452
 
437
- it 'finds the first element by index: 0' do
438
- expect(browser.element(index: 0).tag_name).to eq 'html'
453
+ it "doesn't raise when selector has with :xpath has :index" do
454
+ expect(browser.div(xpath: '//div', index: 1)).to exist
439
455
  end
440
456
 
441
- it 'finds the second element by index: 1' do
442
- expect(browser.element(index: 1).tag_name).to eq 'head'
457
+ it "doesn't raise when selector has with :css has :index" do
458
+ expect(browser.div(css: 'div', index: 1)).to exist
443
459
  end
444
460
 
445
- it 'finds the last element by index: -1' do
446
- expect(browser.element(index: -1).tag_name).to eq 'div'
461
+ it 'finds element by Selenium name locator' do
462
+ expect(browser.element(name: 'new_user_first_name')).to exist
463
+ expect(browser.element(name: /new_user_first_name/)).to exist
447
464
  end
448
- end
449
465
 
450
- it "doesn't raise when called on nested elements" do
451
- expect(browser.div(id: 'no_such_div').link(id: 'no_such_id')).to_not exist
466
+ it 'returns false when tag name does not match id' do
467
+ watir_element = browser.span(id: 'text')
468
+ expect(watir_element).not_to exist
469
+ end
452
470
  end
453
471
 
454
- it "doesn't raise when selector has with :xpath has :index" do
455
- expect(browser.div(xpath: '//div', index: 1)).to exist
456
- end
472
+ describe '#send_keys' do
473
+ before do
474
+ browser.goto(WatirSpec.url_for('keylogger.html'))
475
+ end
457
476
 
458
- it "doesn't raise when selector has with :css has :index" do
459
- expect(browser.div(css: 'div', index: 1)).to exist
460
- end
477
+ let(:receiver) { browser.text_field(id: 'receiver') }
478
+ let(:events) { browser.element(id: 'output').ps.size }
461
479
 
462
- it 'finds element by Selenium name locator' do
463
- expect(browser.element(name: 'new_user_first_name')).to exist
464
- expect(browser.element(name: /new_user_first_name/)).to exist
465
- end
480
+ it 'sends keystrokes to the element' do
481
+ receiver.send_keys 'hello world'
482
+ expect(receiver.value).to eq 'hello world'
483
+ expect(events).to eq 11
484
+ end
466
485
 
467
- it 'returns false when tag name does not match id' do
468
- watir_element = browser.span(id: 'text')
469
- expect(watir_element).to_not exist
470
- end
471
- end
486
+ it 'accepts arbitrary list of arguments' do
487
+ receiver.send_keys 'hello', 'world'
488
+ expect(receiver.value).to eq 'helloworld'
489
+ expect(events).to eq 10
490
+ end
472
491
 
473
- describe '#send_keys' do
474
- before(:each) do
475
- browser.goto(WatirSpec.url_for('keylogger.html'))
476
- end
492
+ context 'with key combinations',
493
+ except: [{browser: :firefox, reason: 'https://github.com/mozilla/geckodriver/issues/245'},
494
+ {browser: :safari}] do
495
+ it 'performs from array' do
496
+ receiver.send_keys 'foo'
497
+ receiver.send_keys [@c, 'a']
498
+ receiver.send_keys :backspace
499
+ expect(receiver.value).to be_empty
500
+ expect(events).to eq 6
501
+ end
477
502
 
478
- let(:receiver) { browser.text_field(id: 'receiver') }
479
- let(:events) { browser.element(id: 'output').ps.size }
503
+ it 'performs from multiple arrays' do
504
+ receiver.send_keys 'foo'
505
+ receiver.send_keys [@c, 'a'], [@c, 'x']
506
+ expect(receiver.value).to be_empty
507
+ expect(events).to eq 7
508
+ end
480
509
 
481
- it 'sends keystrokes to the element' do
482
- receiver.send_keys 'hello world'
483
- expect(receiver.value).to eq 'hello world'
484
- expect(events).to eq 11
510
+ it 'supports combination of strings and arrays' do
511
+ receiver.send_keys 'foo', [@c, 'a'], :backspace
512
+ expect(receiver.value).to be_empty
513
+ expect(events).to eq 6
514
+ end
515
+ end
485
516
  end
486
517
 
487
- it 'accepts arbitrary list of arguments' do
488
- receiver.send_keys 'hello', 'world'
489
- expect(receiver.value).to eq 'helloworld'
490
- expect(events).to eq 10
518
+ describe '#click' do
519
+ it 'accepts modifiers', except: {browser: :ie} do
520
+ browser.a.click(@c)
521
+ expect { browser.windows.wait_until(size: 2) }.not_to raise_exception
522
+ ensure
523
+ browser.windows.restore!
524
+ end
491
525
  end
492
526
 
493
- context 'with key combinations',
494
- except: [{browser: :firefox, reason: 'https://github.com/mozilla/geckodriver/issues/245'},
495
- {browser: :safari}] do
496
- it 'performs from array' do
497
- receiver.send_keys 'foo'
498
- receiver.send_keys [@c, 'a']
499
- receiver.send_keys :backspace
500
- expect(receiver.value).to be_empty
501
- expect(events).to eq 6
527
+ describe '#set' do
528
+ it 'clicks an element by default that does not define #set' do
529
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
530
+ browser.element(id: 'best_language').set
531
+ expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
502
532
  end
503
533
 
504
- it 'performs from multiple arrays' do
505
- receiver.send_keys 'foo'
506
- receiver.send_keys [@c, 'a'], [@c, 'x']
507
- expect(receiver.value).to be_empty
508
- expect(events).to eq 7
534
+ it 'clicks an element that does not define #set with provided modifiers', except: {browser: :ie} do
535
+ browser.a.set(@c)
536
+ browser.wait_until { |b| b.windows.size > 1 }
537
+ expect(browser.windows.size).to eq 2
538
+ ensure
539
+ browser.windows.restore!
509
540
  end
510
541
 
511
- it 'supports combination of strings and arrays' do
512
- receiver.send_keys 'foo', [@c, 'a'], :backspace
513
- expect(receiver.value).to be_empty
514
- expect(events).to eq 6
542
+ it 'does not click an element that does not define #set when passed false' do
543
+ browser.goto(WatirSpec.url_for('non_control_elements.html'))
544
+ browser.element(id: 'best_language').set(false)
545
+ expect(browser.div(id: 'best_language').text).not_to eq 'Ruby!'
515
546
  end
516
- end
517
- end
518
547
 
519
- describe '#click' do
520
- it 'accepts modifiers', except: {browser: :ie} do
521
- browser.a.click(@c)
522
- expect { browser.windows.wait_until(size: 2) }.to_not raise_exception
523
- ensure
524
- browser.windows.restore!
525
- end
526
- end
548
+ it 'clicks a Button' do
549
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
550
+ browser.button(id: 'delete_user_submit').set
551
+ browser.wait_until { |b| !b.url.include? 'forms_with_input_elements.html' }
552
+ expect(browser.text).to include('Semantic table')
553
+ end
527
554
 
528
- describe '#set' do
529
- it 'clicks an element by default that does not define #set' do
530
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
531
- browser.element(id: 'best_language').set
532
- expect(browser.div(id: 'best_language').text).to eq 'Ruby!'
533
- end
555
+ it 'sends keys to text element' do
556
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
557
+ browser.element(id: 'new_user_email').set('Bye Cruel World')
558
+ expect(browser.text_field(id: 'new_user_email').value).to eq 'Bye Cruel World'
559
+ end
534
560
 
535
- it 'clicks an element that does not define #set with provided modifiers', except: {browser: :ie} do
536
- browser.a.set(@c)
537
- browser.wait_until { |b| b.windows.size > 1 }
538
- expect(browser.windows.size).to eq 2
539
- ensure
540
- browser.windows.restore!
541
- end
561
+ it 'sends keys to text area' do
562
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
563
+ browser.element(id: 'delete_user_comment').set('Hello Cruel World')
564
+ expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
565
+ end
542
566
 
543
- it 'does not click an element that does not define #set when passed false' do
544
- browser.goto(WatirSpec.url_for('non_control_elements.html'))
545
- browser.element(id: 'best_language').set(false)
546
- expect(browser.div(id: 'best_language').text).not_to eq 'Ruby!'
547
- end
567
+ it 'checks a checkbox' do
568
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
569
+ browser.element(id: 'new_user_interests_cars').set
570
+ expect(browser.checkbox(id: 'new_user_interests_cars')).to be_set
571
+ end
548
572
 
549
- it 'clicks a Button' do
550
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
551
- browser.button(id: 'delete_user_submit').set
552
- browser.wait_until { |b| !b.url.include? 'forms_with_input_elements.html' }
553
- expect(browser.text).to include('Semantic table')
554
- end
573
+ it 'unchecks a checkbox' do
574
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
575
+ browser.element(id: 'new_user_interests_books').set(false)
576
+ expect(browser.checkbox(id: 'new_user_interests_books')).not_to be_set
577
+ end
555
578
 
556
- it 'sends keys to text element' do
557
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
558
- browser.element(id: 'new_user_email').set('Bye Cruel World')
559
- expect(browser.text_field(id: 'new_user_email').value).to eq 'Bye Cruel World'
560
- end
579
+ it 'clicks a Radio' do
580
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
581
+ browser.radio(id: 'new_user_newsletter_no').set
582
+ expect(browser.radio(id: 'new_user_newsletter_no')).to be_set
583
+ expect(messages.size).to eq 1
584
+ end
561
585
 
562
- it 'sends keys to text area' do
563
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
564
- browser.element(id: 'delete_user_comment').set('Hello Cruel World')
565
- expect(browser.textarea(id: 'delete_user_comment').value).to eq 'Hello Cruel World'
566
- end
586
+ it 'does not click a Radio when false or already clicked' do
587
+ browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
588
+ browser.element(id: 'new_user_newsletter_no').set(false)
589
+ browser.element(id: 'new_user_newsletter_yes').set(true)
590
+ expect(messages.size).to eq 0
591
+ end
567
592
 
568
- it 'checks a checkbox' do
569
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
570
- browser.element(id: 'new_user_interests_cars').set
571
- expect(browser.checkbox(id: 'new_user_interests_cars')).to be_set
572
- end
593
+ it 'uploads a file' do
594
+ browser.element(name: 'new_user_portrait').set __FILE__
573
595
 
574
- it 'unchecks a checkbox' do
575
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
576
- browser.element(id: 'new_user_interests_books').set(false)
577
- expect(browser.checkbox(id: 'new_user_interests_books')).to_not be_set
578
- end
596
+ expect(browser.file_field(name: 'new_user_portrait').value).to include(File.basename(__FILE__))
597
+ end
579
598
 
580
- it 'clicks a Radio' do
581
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
582
- browser.radio(id: 'new_user_newsletter_no').set
583
- expect(browser.radio(id: 'new_user_newsletter_no')).to be_set
584
- expect(messages.size).to eq 1
585
- end
599
+ it 'selects an option' do
600
+ browser.select_list(name: 'new_user_languages').clear
601
+ browser.element(name: 'new_user_languages').set('2')
602
+ expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN]
603
+ end
586
604
 
587
- it 'does not click a Radio when false or already clicked' do
588
- browser.goto(WatirSpec.url_for('forms_with_input_elements.html'))
589
- browser.element(id: 'new_user_newsletter_no').set(false)
590
- browser.element(id: 'new_user_newsletter_yes').set(true)
591
- expect(messages.size).to eq 0
605
+ it 'sends keys to content editable element' do
606
+ browser.element(id: 'contenteditable').set('Bar')
607
+ expect(browser.div(id: 'contenteditable').text).to eq 'Bar'
608
+ end
592
609
  end
593
610
 
594
- it 'uploads a file' do
595
- browser.element(name: 'new_user_portrait').set __FILE__
611
+ describe '#flash' do
612
+ let(:h2) { browser.h2(text: 'Add user') }
613
+ let(:h1) { browser.h1(text: 'User administration') }
596
614
 
597
- expect(browser.file_field(name: 'new_user_portrait').value).to include(File.basename(__FILE__))
598
- end
615
+ it 'returns the element on which it was called' do
616
+ expect(h2.flash).to eq h2
617
+ end
599
618
 
600
- it 'selects an option' do
601
- browser.select_list(name: 'new_user_languages').clear
602
- browser.element(name: 'new_user_languages').set('2')
603
- expect(browser.select_list(name: 'new_user_languages').selected_options.map(&:text)).to eq %w[EN]
604
- end
619
+ it 'keeps the element background color after flashing' do
620
+ expect(h2.style('background-color')).to eq h2.flash(:rainbow).style('background-color')
621
+ expect(h1.style('background-color')).to eq h1.flash.style('background-color')
622
+ end
605
623
 
606
- it 'sends keys to content editable element' do
607
- browser.element(id: 'contenteditable').set('Bar')
608
- expect(browser.div(id: 'contenteditable').text).to eq 'Bar'
624
+ it 'responds to preset symbols like :fast and :slow' do
625
+ expect(h1.flash(:rainbow)).to eq h1
626
+ expect(h2.flash(:slow)).to eq h2
627
+ expect(h1.flash(:fast)).to eq h1
628
+ expect(h2.flash(:long)).to eq h2
629
+ end
609
630
  end
610
- end
611
631
 
612
- describe '#flash' do
613
- let(:h2) { browser.h2(text: 'Add user') }
614
- let(:h1) { browser.h1(text: 'User administration') }
615
-
616
- it 'returns the element on which it was called' do
617
- expect(h2.flash).to eq h2
618
- end
632
+ describe '#hover' do
633
+ def element_color(element)
634
+ case element.style('color')
635
+ when 'rgba(0, 0, 255, 1)'
636
+ :blue
637
+ when 'rgba(255, 165, 0, 1)', 'rgb(255, 165, 0)'
638
+ :orange
639
+ else
640
+ raise rgba
641
+ end
642
+ end
619
643
 
620
- it 'should keep the element background color after flashing' do
621
- expect(h2.style('background-color')).to eq h2.flash(:rainbow).style('background-color')
622
- expect(h1.style('background-color')).to eq h1.flash.style('background-color')
623
- end
644
+ it 'allows scrolling to top', except: {browser: :ie} do
645
+ browser.goto(WatirSpec.url_for('scroll.html'))
646
+ element = browser.div(id: 'center')
624
647
 
625
- it 'should respond to preset symbols like :fast and :slow' do
626
- expect(h1.flash(:rainbow)).to eq h1
627
- expect(h2.flash(:slow)).to eq h2
628
- expect(h1.flash(:fast)).to eq h1
629
- expect(h2.flash(:long)).to eq h2
630
- end
631
- end
648
+ element.hover(scroll_to: :top)
649
+ expect(element_color(element)).to eq :orange
632
650
 
633
- describe '#hover' do
634
- def element_color(element)
635
- case element.style('color')
636
- when 'rgba(0, 0, 255, 1)'
637
- :blue
638
- when 'rgba(255, 165, 0, 1)', 'rgb(255, 165, 0)'
639
- :orange
640
- else
641
- raise rgba
651
+ element_top = browser.execute_script('return arguments[0].getBoundingClientRect().top', element)
652
+ expect(element_top).to be_within(1).of(0)
642
653
  end
643
- end
644
654
 
645
- it 'allows scrolling to top', except: {browser: :ie,
646
- reason: 'needs require_window_focus'} do
647
- browser.goto(WatirSpec.url_for('scroll.html'))
648
- element = browser.div(id: 'center')
655
+ it 'scrolls to center by default', except: {browser: :ie} do
656
+ browser.goto(WatirSpec.url_for('scroll.html'))
657
+ element = browser.div(id: 'center')
649
658
 
650
- element.hover(scroll_to: :top)
651
- expect(element_color(element)).to eq :orange
659
+ element.hover
660
+ expect(element_color(element)).to eq :orange
652
661
 
653
- element_top = browser.execute_script('return arguments[0].getBoundingClientRect().top', element)
654
- expect(element_top).to be_within(1).of(0)
655
- end
662
+ element_rect = browser.execute_script('return arguments[0].getBoundingClientRect()', element)
656
663
 
657
- it 'scrolls to center by default', except: {browser: :ie,
658
- reason: 'needs require_window_focus'} do
659
- browser.goto(WatirSpec.url_for('scroll.html'))
660
- element = browser.div(id: 'center')
664
+ expect(element_rect['top']).to eq(element_rect['bottom'] - element_rect['height'])
665
+ end
661
666
 
662
- element.hover
663
- expect(element_color(element)).to eq :orange
667
+ it 'allows scrolling to bottom', except: {browser: :ie} do
668
+ browser.goto(WatirSpec.url_for('scroll.html'))
669
+ element = browser.div(id: 'center')
664
670
 
665
- element_rect = browser.execute_script('return arguments[0].getBoundingClientRect()', element)
671
+ element.hover(scroll_to: :bottom)
672
+ expect(element_color(element)).to eq :orange
666
673
 
667
- expect(element_rect['top']).to eq(element_rect['bottom'] - element_rect['height'])
668
- end
674
+ element_bottom = browser.execute_script('return arguments[0].getBoundingClientRect().bottom', element)
675
+ window_height = browser.execute_script('return window.innerHeight')
669
676
 
670
- it 'allows scrolling to bottom', except: {browser: :ie,
671
- reason: 'needs require_window_focus'} do
672
- browser.goto(WatirSpec.url_for('scroll.html'))
673
- element = browser.div(id: 'center')
677
+ expect(element_bottom).to be_within(1).of(window_height)
678
+ end
674
679
 
675
- element.hover(scroll_to: :bottom)
676
- expect(element_color(element)).to eq :orange
680
+ it 'allows not scrolling', except: {browser: %i[chrome edge],
681
+ reason: 'https://bugs.chromium.org/p/chromedriver/issues/detail?id=3955'} do
682
+ browser.goto(WatirSpec.url_for('scroll.html'))
683
+ element = browser.div(id: 'center')
677
684
 
678
- element_bottom = browser.execute_script('return arguments[0].getBoundingClientRect().bottom', element)
679
- window_height = browser.execute_script('return window.innerHeight')
685
+ browser.execute_script('return window.pageYOffset;')
686
+ browser.execute_script('return window.innerHeight;')
680
687
 
681
- expect(element_bottom).to be_within(1).of(window_height)
688
+ expect {
689
+ element.hover(scroll_to: nil)
690
+ }.to raise_exception Selenium::WebDriver::Error::MoveTargetOutOfBoundsError
691
+ end
682
692
  end
683
693
 
684
- it 'allows not scrolling', except: {browser: %i[chrome edge],
685
- reason: 'https://bugs.chromium.org/p/chromedriver/issues/detail?id=3955'} do
686
- browser.goto(WatirSpec.url_for('scroll.html'))
687
- element = browser.div(id: 'center')
694
+ describe '#inspect' do
695
+ before { browser.goto(WatirSpec.url_for('nested_iframes.html')) }
688
696
 
689
- browser.execute_script('return window.pageYOffset;')
690
- browser.execute_script('return window.innerHeight;')
697
+ it 'does displays specified element type' do
698
+ expect(browser.div.inspect).to include('Watir::Div')
699
+ end
691
700
 
692
- expect { element.hover(scroll_to: nil) }.to raise_exception Selenium::WebDriver::Error::MoveTargetOutOfBoundsError
693
- end
694
- end
701
+ it 'does not display element type if not specified' do
702
+ element = browser.element(index: 4)
703
+ expect(element.inspect).to include('Watir::HTMLElement')
704
+ end
695
705
 
696
- describe '#inspect' do
697
- before(:each) { browser.goto(WatirSpec.url_for('nested_iframes.html')) }
706
+ it 'displays keyword if specified' do
707
+ element = browser.h3
708
+ element.keyword = 'foo'
709
+ expect(element.inspect).to include('keyword: foo')
710
+ end
698
711
 
699
- it 'does displays specified element type' do
700
- expect(browser.div.inspect).to include('Watir::Div')
701
- end
712
+ it 'does not display keyword if not specified' do
713
+ element = browser.h3
714
+ expect(element.inspect).not_to include('keyword')
715
+ end
702
716
 
703
- it 'does not display element type if not specified' do
704
- element = browser.element(index: 4)
705
- expect(element.inspect).to include('Watir::HTMLElement')
706
- end
717
+ it 'locate is false when not located' do
718
+ element = browser.div(id: 'not_present')
719
+ expect(element.inspect).to include('located: false')
720
+ end
707
721
 
708
- it 'displays keyword if specified' do
709
- element = browser.h3
710
- element.keyword = 'foo'
711
- expect(element.inspect).to include('keyword: foo')
712
- end
722
+ it 'locate is true when located' do
723
+ element = browser.h3
724
+ element.exists?
725
+ expect(element.inspect).to include('located: true')
726
+ end
713
727
 
714
- it 'does not display keyword if not specified' do
715
- element = browser.h3
716
- expect(element.inspect).to_not include('keyword')
717
- end
728
+ it 'displays selector string for element from colection' do
729
+ elements = browser.frames
730
+ expect(elements.last.inspect).to include '{:tag_name=>"frame", :index=>-1}'
731
+ end
718
732
 
719
- it 'locate is false when not located' do
720
- element = browser.div(id: 'not_present')
721
- expect(element.inspect).to include('located: false')
722
- end
733
+ it 'displays selector string for nested element' do
734
+ browser.goto(WatirSpec.url_for('wait.html'))
735
+ element = browser.div(index: 1).div(id: 'div2')
736
+ expect(element.inspect).to include '{:index=>1, :tag_name=>"div"} --> {:id=>"div2", :tag_name=>"div"}'
737
+ end
723
738
 
724
- it 'locate is true when located' do
725
- element = browser.h3
726
- element.exists?
727
- expect(element.inspect).to include('located: true')
739
+ it 'displays selector string for nested element under frame' do
740
+ element = browser.iframe(id: 'one').iframe(id: 'three')
741
+ expect(element.inspect).to include '{:id=>"one", :tag_name=>"iframe"} --> {:id=>"three", :tag_name=>"iframe"}'
742
+ end
728
743
  end
729
744
 
730
- it 'displays selector string for element from colection' do
731
- elements = browser.frames
732
- expect(elements.last.inspect).to include '{:tag_name=>"frame", :index=>-1}'
745
+ describe '#text_content' do
746
+ it 'returns inner Text code of element' do
747
+ browser.goto WatirSpec.url_for('non_control_elements.html')
748
+ expect(browser.div(id: 'shown').text_content).to eq('Not shownNot hidden')
749
+ end
733
750
  end
734
751
 
735
- it 'displays selector string for nested element' do
736
- browser.goto(WatirSpec.url_for('wait.html'))
737
- element = browser.div(index: 1).div(id: 'div2')
738
- expect(element.inspect).to include '{:index=>1, :tag_name=>"div"} --> {:id=>"div2", :tag_name=>"div"}'
752
+ describe '#inner_text' do
753
+ it 'returns inner HTML code of element',
754
+ except: {browser: :ie, reason: 'also returning explicitly hidden results'} do
755
+ browser.goto WatirSpec.url_for('non_control_elements.html')
756
+ div = browser.div(id: 'shown')
757
+ expect(div.inner_text).to eq('Not hidden')
758
+ end
739
759
  end
740
760
 
741
- it 'displays selector string for nested element under frame' do
742
- element = browser.iframe(id: 'one').iframe(id: 'three')
743
- expect(element.inspect).to include '{:id=>"one", :tag_name=>"iframe"} --> {:id=>"three", :tag_name=>"iframe"}'
761
+ describe '#inner_html' do
762
+ it 'returns inner HTML code of element' do
763
+ browser.goto WatirSpec.url_for('non_control_elements.html')
764
+ div = browser.div(id: 'shown')
765
+ expected_text = '<div id="hidden" style="display: none;">Not shown</div><div>Not hidden</div>'
766
+ expect(div.inner_html).to eq expected_text
767
+ end
744
768
  end
745
- end
746
769
 
747
- describe '#text_content' do
748
- it 'returns inner Text code of element' do
749
- browser.goto WatirSpec.url_for('non_control_elements.html')
750
- expect(browser.div(id: 'shown').text_content).to eq('Not shownNot hidden')
770
+ describe '#outer_html' do
771
+ it 'returns outer (inner + element itself) HTML code of element' do
772
+ browser.goto WatirSpec.url_for('non_control_elements.html')
773
+ div = browser.div(id: 'shown')
774
+ text = '<div id="shown"><div id="hidden" style="display: none;">Not shown</div><div>Not hidden</div></div>'
775
+ expect(div.outer_html).to eq text
776
+ end
751
777
  end
752
- end
753
778
 
754
- describe '#inner_text' do
755
- it 'returns inner HTML code of element',
756
- except: {browser: :ie, reason: 'also returning explicitly hidden results'} do
757
- browser.goto WatirSpec.url_for('non_control_elements.html')
758
- div = browser.div(id: 'shown')
759
- expect(div.inner_text).to eq('Not hidden')
779
+ describe '#select_text and #selected_text' do
780
+ it 'selects text and returns selected text',
781
+ except: {browser: :ie, reason: 'Select Text atom appears broken in IE 11'} do
782
+ browser.goto WatirSpec.url_for('non_control_elements.html')
783
+ element = browser.element(visible_text: 'all visible')
784
+ element.select_text('all visible')
785
+ expect(element.selected_text).to eq 'all visible'
786
+ end
760
787
  end
761
- end
762
788
 
763
- describe '#inner_html' do
764
- it 'returns inner HTML code of element' do
765
- browser.goto WatirSpec.url_for('non_control_elements.html')
766
- div = browser.div(id: 'shown')
767
- expected_text = '<div id="hidden" style="display: none;">Not shown</div><div>Not hidden</div>'
768
- expect(div.inner_html).to eq expected_text
769
- end
770
- end
789
+ describe '#location' do
790
+ it 'returns coordinates for element location' do
791
+ location = browser.button(name: 'new_user_image').location
771
792
 
772
- describe '#outer_html' do
773
- it 'returns outer (inner + element itself) HTML code of element' do
774
- browser.goto WatirSpec.url_for('non_control_elements.html')
775
- div = browser.div(id: 'shown')
776
- text = '<div id="shown"><div id="hidden" style="display: none;">Not shown</div><div>Not hidden</div></div>'
777
- expect(div.outer_html).to eq text
793
+ expect(location).to be_a Selenium::WebDriver::Point
794
+ expect(location['y']).to be > 0
795
+ expect(location['x']).to be > 0
796
+ end
778
797
  end
779
- end
780
798
 
781
- describe '#select_text and #selected_text' do
782
- it 'selects text and returns selected text',
783
- except: {browser: :ie, reason: 'Select Text atom appears broken in IE 11'} do
784
- browser.goto WatirSpec.url_for('non_control_elements.html')
785
- element = browser.element(visible_text: 'all visible')
786
- element.select_text('all visible')
787
- expect(element.selected_text).to eq 'all visible'
788
- end
789
- end
799
+ describe '#size' do
800
+ it 'returns size of element' do
801
+ size = browser.button(name: 'new_user_image').size
802
+ expect(size).to be_a Selenium::WebDriver::Dimension
790
803
 
791
- describe '#location' do
792
- it 'returns coordinates for element location' do
793
- location = browser.button(name: 'new_user_image').location
804
+ expected_width = browser.name == :safari ? 105 : 104
805
+ expected_height = browser.name == :safari ? 71 : 70
794
806
 
795
- expect(location).to be_a Selenium::WebDriver::Point
796
- expect(location['y']).to be > 0
797
- expect(location['x']).to be > 0
807
+ expect(size['width']).to eq expected_width
808
+ expect(size['height']).to eq expected_height
809
+ end
798
810
  end
799
- end
800
811
 
801
- describe '#size' do
802
- it 'returns size of element' do
803
- size = browser.button(name: 'new_user_image').size
804
- expect(size).to be_a Selenium::WebDriver::Dimension
812
+ describe '#height' do
813
+ it 'returns height of element' do
814
+ height = browser.button(name: 'new_user_image').height
805
815
 
806
- expected_width = browser.name == :safari ? 105 : 104
807
- expected_height = browser.name == :safari ? 71 : 70
808
-
809
- expect(size['width']).to eq expected_width
810
- expect(size['height']).to eq expected_height
816
+ expected_height = browser.name == :safari ? 71 : 70
817
+ expect(height).to eq expected_height
818
+ end
811
819
  end
812
- end
813
820
 
814
- describe '#height' do
815
- it 'returns height of element' do
816
- height = browser.button(name: 'new_user_image').height
821
+ describe '#width' do
822
+ it 'returns width of element' do
823
+ width = browser.button(name: 'new_user_image').width
817
824
 
818
- expected_height = browser.name == :safari ? 71 : 70
819
- expect(height).to eq expected_height
825
+ expected_width = browser.name == :safari ? 105 : 104
826
+ expect(width).to eq expected_width
827
+ end
820
828
  end
821
- end
822
829
 
823
- describe '#width' do
824
- it 'returns width of element' do
825
- width = browser.button(name: 'new_user_image').width
830
+ describe '#center' do
831
+ it 'returns center of element' do
832
+ center = browser.button(name: 'new_user_image').center
826
833
 
827
- expected_width = browser.name == :safari ? 105 : 104
828
- expect(width).to eq expected_width
834
+ expect(center).to be_a Selenium::WebDriver::Point
835
+ expect(center['y']).to be > 0.0
836
+ expect(center['x']).to be > 0.0
837
+ end
829
838
  end
830
- end
831
839
 
832
- describe '#center' do
833
- it 'returns center of element' do
834
- center = browser.button(name: 'new_user_image').center
840
+ describe '#attribute_value' do
841
+ before { browser.goto WatirSpec.url_for('data_attributes.html') }
835
842
 
836
- expect(center).to be_a Selenium::WebDriver::Point
837
- expect(center['y']).to be > 0.0
838
- expect(center['x']).to be > 0.0
843
+ it 'returns attribute value by string attribute name' do
844
+ expect(browser.p.attribute_value('data-type')).to eq 'ruby-library'
845
+ end
846
+
847
+ it 'returns attribute value by symbol attribute name' do
848
+ expect(browser.p.attribute_value(:data_type)).to eq 'ruby-library'
849
+ end
839
850
  end
840
- end
841
851
 
842
- describe '#attribute_value' do
843
- before { browser.goto WatirSpec.url_for('data_attributes.html') }
852
+ describe '#attribute_values' do
853
+ before { browser.goto WatirSpec.url_for('data_attributes.html') }
844
854
 
845
- it 'returns attribute value by string attribute name' do
846
- expect(browser.p.attribute_value('data-type')).to eq 'ruby-library'
847
- end
855
+ it 'returns a Hash object' do
856
+ expect(browser.p.attribute_values).to be_an_instance_of(Hash)
857
+ end
848
858
 
849
- it 'returns attribute value by symbol attribute name' do
850
- expect(browser.p.attribute_value(:data_type)).to eq 'ruby-library'
851
- end
852
- end
859
+ it 'returns attribute values from an element' do
860
+ expected = {data_type: 'ruby-library'}
861
+ expect(browser.p.attribute_values).to eq expected
862
+ end
853
863
 
854
- describe '#attribute_values' do
855
- before { browser.goto WatirSpec.url_for('data_attributes.html') }
864
+ it 'returns attribute with special characters' do
865
+ expected = {data_type: 'description', 'data-type_$p3c!a1' => 'special-description'}
866
+ expect(browser.div.attribute_values).to eq expected
867
+ end
856
868
 
857
- it 'returns a Hash object' do
858
- expect(browser.p.attribute_values).to be_an_instance_of(Hash)
869
+ it 'returns attribute with special characters as a String' do
870
+ expect(browser.div.attribute_values.keys[0]).to be_an_instance_of(String)
871
+ end
859
872
  end
860
873
 
861
- it 'returns attribute values from an element' do
862
- expected = {data_type: 'ruby-library'}
863
- expect(browser.p.attribute_values).to eq expected
864
- end
874
+ describe '#attribute_list' do
875
+ before { browser.goto WatirSpec.url_for('data_attributes.html') }
865
876
 
866
- it 'returns attribute with special characters' do
867
- expected = {data_type: 'description', 'data-type_$p3c!a1' => 'special-description'}
868
- expect(browser.div.attribute_values).to eq expected
869
- end
877
+ it 'returns an Array object' do
878
+ expect(browser.div.attribute_list).to be_an_instance_of(Array)
879
+ end
880
+
881
+ it 'returns list of attributes from an element' do
882
+ expect(browser.p.attribute_list).to eq [:data_type]
883
+ end
870
884
 
871
- it 'returns attribute with special characters as a String' do
872
- expect(browser.div.attribute_values.keys[0]).to be_an_instance_of(String)
885
+ it 'returns attribute name with special characters as a String' do
886
+ expect(browser.div.attribute_list[0]).to be_an_instance_of(String)
887
+ end
873
888
  end
874
- end
875
889
 
876
- describe '#attribute_list' do
877
- before { browser.goto WatirSpec.url_for('data_attributes.html') }
890
+ describe '#located?' do
891
+ it 'returns true if element has been located' do
892
+ expect(browser.form(id: 'new_user')).not_to be_located
893
+ end
878
894
 
879
- it 'returns an Array object' do
880
- expect(browser.div.attribute_list).to be_an_instance_of(Array)
895
+ it 'returns false if element has not been located' do
896
+ expect(browser.form(id: 'new_user').locate).to be_located
897
+ end
881
898
  end
882
899
 
883
- it 'returns list of attributes from an element' do
884
- expect(browser.p.attribute_list).to eq [:data_type]
900
+ describe '#wd' do
901
+ it 'returns a Selenium::WebDriver::Element instance' do
902
+ element = browser.text_field(id: 'new_user_email')
903
+ expect(element.wd).to be_a(Selenium::WebDriver::Element)
904
+ end
885
905
  end
886
906
 
887
- it 'returns attribute name with special characters as a String' do
888
- expect(browser.div.attribute_list[0]).to be_an_instance_of(String)
907
+ describe '#hash' do
908
+ it 'returns a hash' do
909
+ element = browser.text_field(id: 'new_user_email')
910
+ hash1 = element.hash
911
+ hash2 = element.locate.hash
912
+ expect(hash1).to be_a Integer
913
+ expect(hash2).to be_a Integer
914
+ expect(hash1).not_to eq hash2
915
+ end
889
916
  end
890
- end
891
917
 
892
- describe '#located?' do
893
- it 'returns true if element has been located' do
894
- expect(browser.form(id: 'new_user')).to_not be_located
895
- end
918
+ describe 'Numeric Attribute' do
919
+ it 'returns Float value',
920
+ except: {browser: :ie, reason: 'not recognizing the value of the element'} do
921
+ element = browser.text_field(id: 'number')
922
+ expect(element.valueasnumber).to be_a Float
923
+ end
896
924
 
897
- it 'returns false if element has not been located' do
898
- expect(browser.form(id: 'new_user').locate).to be_located
899
- end
900
- end
925
+ it 'returns nil for unspecified value' do
926
+ element = browser.input
927
+ expect(element.valueasnumber).to be_nil
928
+ end
901
929
 
902
- describe '#wd' do
903
- it 'returns a Selenium::WebDriver::Element instance' do
904
- element = browser.text_field(id: 'new_user_email')
905
- expect(element.wd).to be_a(Selenium::WebDriver::Element)
930
+ it 'returns Integer value' do
931
+ element = browser.form
932
+ expect(element.length).to be_a Integer
933
+ end
906
934
  end
907
- end
908
935
 
909
- describe '#hash' do
910
- it 'returns a hash' do
911
- element = browser.text_field(id: 'new_user_email')
912
- hash1 = element.hash
913
- hash2 = element.locate.hash
914
- expect(hash1).to be_a Integer
915
- expect(hash2).to be_a Integer
916
- expect(hash1).to_not eq hash2
917
- end
918
- end
936
+ describe 'Special Characters' do
937
+ before do
938
+ browser.goto WatirSpec.url_for('special_chars.html')
939
+ end
919
940
 
920
- describe 'Numeric Attribute' do
921
- it 'returns Float value',
922
- except: {browser: :ie, reason: 'not recognizing the value of the element'} do
923
- element = browser.text_field(id: 'number')
924
- expect(element.valueasnumber).to be_a Float
925
- end
941
+ it 'finds elements with single quotes' do
942
+ expect(browser.div(text: "single 'quotes'")).to exist
943
+ end
926
944
 
927
- it 'returns nil for unspecified value' do
928
- element = browser.input
929
- expect(element.valueasnumber).to be_nil
930
- end
945
+ it 'finds elements with non-standard character locators' do
946
+ expect(browser.div('we{ird' => 'foo')).to exist
947
+ expect(browser.div('we{ird': 'foo')).to exist
948
+ end
931
949
 
932
- it 'returns Integer value' do
933
- element = browser.form
934
- expect(element.length).to be_a Integer
950
+ it 'finds element with underscored attribute' do
951
+ expect(browser.div('underscored_attribute' => 'true')).to exist
952
+ expect(browser.div('underscored_attribute' => true)).to exist
953
+ end
935
954
  end
936
- end
937
955
 
938
- describe '#class_name' do
939
- it 'returns single class name' do
940
- expect(browser.form(id: 'new_user').class_name).to eq 'user'
941
- end
956
+ describe '#class_name' do
957
+ it 'returns single class name' do
958
+ expect(browser.form(id: 'new_user').class_name).to eq 'user'
959
+ end
942
960
 
943
- it 'returns multiple class names in a String' do
944
- expect(browser.div(id: 'messages').class_name).to eq 'multiple classes here'
945
- end
961
+ it 'returns multiple class names in a String' do
962
+ expect(browser.div(id: 'messages').class_name).to eq 'multiple classes here'
963
+ end
946
964
 
947
- it 'returns an empty string if the element exists but there is no class attribute' do
948
- expect(browser.div(id: 'changed_language').class_name).to eq ''
949
- end
965
+ it 'returns an empty string if the element exists but there is no class attribute' do
966
+ expect(browser.div(id: 'changed_language').class_name).to eq ''
967
+ end
950
968
 
951
- it 'raises UnknownObjectException if the element does not exist' do
952
- expect { browser.div(id: 'no_such_id').class_name }.to raise_unknown_object_exception
969
+ it 'raises UnknownObjectException if the element does not exist' do
970
+ expect { browser.div(id: 'no_such_id').class_name }.to raise_unknown_object_exception
971
+ end
953
972
  end
954
- end
955
973
 
956
- describe '#classes' do
957
- it 'returns the class attribute if the element exists' do
958
- expect(browser.div(id: 'messages').classes).to eq %w[multiple classes here]
959
- end
974
+ describe '#classes' do
975
+ it 'returns the class attribute if the element exists' do
976
+ expect(browser.div(id: 'messages').classes).to eq %w[multiple classes here]
977
+ end
960
978
 
961
- it 'returns an empty array if the element exists but there is no class attribute' do
962
- expect(browser.div(id: 'changed_language').classes).to eq []
963
- end
979
+ it 'returns an empty array if the element exists but there is no class attribute' do
980
+ expect(browser.div(id: 'changed_language').classes).to eq []
981
+ end
964
982
 
965
- it 'raises UnknownObjectException if the element does not exist' do
966
- expect { browser.div(id: 'no_such_id').classes }.to raise_unknown_object_exception
983
+ it 'raises UnknownObjectException if the element does not exist' do
984
+ expect { browser.div(id: 'no_such_id').classes }.to raise_unknown_object_exception
985
+ end
967
986
  end
968
- end
969
987
 
970
- describe '#obscured?' do
971
- before { browser.goto WatirSpec.url_for('obscured.html') }
988
+ describe '#obscured?' do
989
+ before { browser.goto WatirSpec.url_for('obscured.html') }
972
990
 
973
- it 'returns false if element center is not covered' do
974
- btn = browser.button(id: 'not_obscured')
975
- btn.scroll.to :center
976
- expect { btn.click }.not_to raise_exception
977
- expect(btn).not_to be_obscured
978
- end
991
+ it 'returns false if element center is not covered' do
992
+ btn = browser.button(id: 'not_obscured')
993
+ btn.scroll.to :center
994
+ expect { btn.click }.not_to raise_exception
995
+ expect(btn).not_to be_obscured
996
+ end
979
997
 
980
- it 'returns false if element center is covered by its descendant' do
981
- btn = browser.button(id: 'has_descendant')
982
- btn.scroll.to :center
983
- expect { btn.click }.not_to raise_exception
984
- expect(btn).not_to be_obscured
985
- end
998
+ it 'returns false if element center is covered by its descendant' do
999
+ btn = browser.button(id: 'has_descendant')
1000
+ btn.scroll.to :center
1001
+ expect { btn.click }.not_to raise_exception
1002
+ expect(btn).not_to be_obscured
1003
+ end
986
1004
 
987
- it 'returns true if element center is covered by a non-descendant',
988
- except: {browser: :safari, reason: 'not getting element click intercepted'} do
989
- btn = browser.button(id: 'obscured')
990
- btn.scroll.to :center
991
- expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::ElementClickInterceptedError)
992
- expect(btn).to be_obscured
993
- end
1005
+ it 'returns true if element center is covered by a non-descendant',
1006
+ except: {browser: :safari, reason: 'not getting element click intercepted'} do
1007
+ btn = browser.button(id: 'obscured')
1008
+ btn.scroll.to :center
1009
+ expect { btn.click }.to raise_exception(Selenium::WebDriver::Error::ElementClickInterceptedError)
1010
+ expect(btn).to be_obscured
1011
+ end
994
1012
 
995
- it 'returns false if element center is surrounded by non-descendants' do
996
- btn = browser.button(id: 'surrounded')
997
- btn.scroll.to :center
998
- expect { btn.click }.not_to raise_exception
999
- expect(btn).not_to be_obscured
1000
- end
1013
+ it 'returns false if element center is surrounded by non-descendants' do
1014
+ btn = browser.button(id: 'surrounded')
1015
+ btn.scroll.to :center
1016
+ expect { btn.click }.not_to raise_exception
1017
+ expect(btn).not_to be_obscured
1018
+ end
1001
1019
 
1002
- it 'correctly scrolls element below viewport' do
1003
- browser.goto WatirSpec.url_for('sticky_elements.html')
1020
+ it 'correctly scrolls element below viewport' do
1021
+ browser.goto WatirSpec.url_for('sticky_elements.html')
1004
1022
 
1005
- element = browser.div(id: 'center')
1023
+ element = browser.div(id: 'center')
1006
1024
 
1007
- browser.scroll.to :top
1008
- expect { element.click }.not_to raise_exception
1025
+ browser.scroll.to :top
1026
+ expect { element.click }.not_to raise_exception
1009
1027
 
1010
- browser.scroll.to :top
1011
- expect(element).not_to be_obscured
1012
- end
1028
+ browser.scroll.to :top
1029
+ expect(element).not_to be_obscured
1030
+ end
1013
1031
 
1014
- it 'correctly scrolls element above viewport',
1015
- except: {browser: %i[chrome edge],
1016
- reason: 'https://bugs.chromium.org/p/chromedriver/issues/detail?id=3954'} do
1017
- browser.goto WatirSpec.url_for('sticky_elements.html')
1018
- element = browser.div(id: 'center')
1032
+ it 'correctly scrolls element above viewport',
1033
+ except: {browser: %i[chrome edge],
1034
+ reason: 'https://bugs.chromium.org/p/chromedriver/issues/detail?id=3954'} do
1035
+ browser.goto WatirSpec.url_for('sticky_elements.html')
1036
+ element = browser.div(id: 'center')
1019
1037
 
1020
- browser.scroll.to :bottom
1021
- expect { element.click }.not_to raise_exception
1038
+ browser.scroll.to :bottom
1039
+ expect { element.click }.not_to raise_exception
1022
1040
 
1023
- browser.scroll.to :bottom
1024
- expect(element).not_to be_obscured
1025
- end
1041
+ browser.scroll.to :bottom
1042
+ expect(element).not_to be_obscured
1043
+ end
1026
1044
 
1027
- it 'scrolls non-interactive element into view before checking if obscured' do
1028
- div = browser.div(id: 'requires_scrolling_container')
1029
- expect { div.click }.not_to raise_exception
1030
- browser.scroll.to :top
1031
- expect(div).not_to be_obscured
1032
- end
1045
+ it 'scrolls non-interactive element into view before checking if obscured' do
1046
+ div = browser.div(id: 'requires_scrolling_container')
1047
+ expect { div.click }.not_to raise_exception
1048
+ browser.scroll.to :top
1049
+ expect(div).not_to be_obscured
1050
+ end
1033
1051
 
1034
- it 'returns true if element cannot be scrolled into view' do
1035
- btn = browser.button(id: 'off_screen')
1036
- expect(btn).to be_obscured
1037
- expect { btn.click }.to raise_unknown_object_exception
1038
- end
1052
+ it 'returns true if element cannot be scrolled into view' do
1053
+ btn = browser.button(id: 'off_screen')
1054
+ expect(btn).to be_obscured
1055
+ expect { btn.click }.to raise_unknown_object_exception
1056
+ end
1039
1057
 
1040
- it 'returns true if element is hidden' do
1041
- btn = browser.button(id: 'hidden')
1042
- expect(btn).to be_obscured
1043
- expect { btn.click }.to raise_unknown_object_exception
1044
- end
1058
+ it 'returns true if element is hidden' do
1059
+ btn = browser.button(id: 'hidden')
1060
+ expect(btn).to be_obscured
1061
+ expect { btn.click }.to raise_unknown_object_exception
1062
+ end
1045
1063
 
1046
- it 'raises UnknownObjectException if element does not exist' do
1047
- expect { browser.button(id: 'does_not_exist').obscured? }.to raise_unknown_object_exception
1064
+ it 'raises UnknownObjectException if element does not exist' do
1065
+ expect { browser.button(id: 'does_not_exist').obscured? }.to raise_unknown_object_exception
1066
+ end
1048
1067
  end
1049
1068
  end
1050
1069
  end