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,208 +2,215 @@
2
2
 
3
3
  require_relative '../unit_helper'
4
4
 
5
- describe Watir::Locators::Button::SelectorBuilder do
6
- include LocatorSpecHelper
7
-
8
- let(:selector_builder) { described_class.new(attributes, query_scope) }
9
- let(:uppercase) { 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ' }
10
- let(:lowercase) { 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ' }
11
- let(:default_types) do
12
- "translate(@type,'#{uppercase}','#{lowercase}')=translate('button','#{uppercase}','#{lowercase}') or " \
13
- "translate(@type,'#{uppercase}','#{lowercase}')=translate('reset','#{uppercase}','#{lowercase}') or " \
14
- "translate(@type,'#{uppercase}','#{lowercase}')=translate('submit','#{uppercase}','#{lowercase}') or " \
15
- "translate(@type,'#{uppercase}','#{lowercase}')=translate('image','#{uppercase}','#{lowercase}')"
16
- end
17
-
18
- describe '#build' do
19
- it 'without any arguments' do
20
- selector = {}
21
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]"}
22
- expect(selector_builder.build(selector)).to eq built
23
- end
24
-
25
- context 'with type' do
26
- it 'false only locates with button without a type' do
27
- selector = {type: false}
28
- built = {xpath: ".//*[(local-name()='button' and not(@type))]"}
29
- expect(selector_builder.build(selector)).to eq built
30
- end
31
-
32
- it 'true locates button or input with a type' do
33
- selector = {type: true}
34
- built = {xpath: ".//*[(local-name()='button' and @type) or " \
35
- "(local-name()='input' and (#{default_types}))]"}
36
- expect(selector_builder.build(selector)).to eq built
37
- end
38
-
39
- it 'locates input or button element with specified type' do
40
- selector = {type: 'reset'}
41
- type = "translate('reset','#{uppercase}','#{lowercase}')"
42
- built = {xpath: ".//*[(local-name()='button' and " \
43
- "translate(@type,'#{uppercase}','#{lowercase}')=#{type}) or " \
44
- "(local-name()='input' and (translate(@type,'#{uppercase}','#{lowercase}')=#{type}))]"}
45
- expect(selector_builder.build(selector)).to eq built
46
- end
47
-
48
- it 'raises exception when a non-button type input is specified' do
49
- selector = {type: 'checkbox'}
50
- msg = 'Button Elements can not be located by input type: checkbox'
51
- expect { selector_builder.build(selector) }
52
- .to raise_exception Watir::Exception::LocatorException, msg
53
- end
54
- end
55
-
56
- context 'with xpath or css' do
57
- it 'returns tag name and type to the locator' do
58
- selector = {xpath: '#disabled_button', tag_name: 'input', type: 'submit'}
59
- built = {xpath: '#disabled_button', tag_name: 'input', type: 'submit'}
60
- expect(selector_builder.build(selector)).to eq built
61
- end
62
- end
63
-
64
- context 'with text' do
65
- it 'locates value of input element with String' do
66
- selector = {text: 'Button'}
67
- built = {xpath: ".//*[(local-name()='button' and normalize-space()='Button') or " \
68
- "(local-name()='input' and (#{default_types}) and @value='Button')]"}
69
- expect(selector_builder.build(selector)).to eq built
70
- end
71
-
72
- it 'locates text of button element with String' do
73
- selector = {text: 'Button 2'}
74
- built = {xpath: ".//*[(local-name()='button' and normalize-space()='Button 2') or " \
75
- "(local-name()='input' and (#{default_types}) and @value='Button 2')]"}
76
- expect(selector_builder.build(selector)).to eq built
77
- end
78
-
79
- it 'locates value of input element with simple Regexp' do
80
- selector = {text: /Button/}
81
- built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"Button\")) or " \
82
- "(local-name()='input' and (#{default_types}) and contains(@value, \"Button\"))]"}
83
- expect(selector_builder.build(selector)).to eq built
84
- end
85
-
86
- it 'locates text of button element with simple Regexp' do
87
- selector = {text: /Button 2/}
88
- built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"Button 2\")) or " \
89
- "(local-name()='input' and (#{default_types}) and contains(@value, \"Button 2\"))]"}
90
- expect(selector_builder.build(selector)).to eq built
91
- end
92
-
93
- it 'Simple Regexp for text' do
94
- selector = {text: /n 2/}
95
- built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"n 2\")) or " \
96
- "(local-name()='input' and (#{default_types}) and contains(@value, \"n 2\"))]"}
97
- expect(selector_builder.build(selector)).to eq built
98
- end
99
-
100
- it 'Simple Regexp for value' do
101
- selector = {text: /Prev/}
102
- built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"Prev\")) or " \
103
- "(local-name()='input' and (#{default_types}) and contains(@value, \"Prev\"))]"}
104
- expect(selector_builder.build(selector)).to eq built
105
- end
106
-
107
- it 'returns complex Regexp to the locator' do
108
- selector = {text: /^foo$/}
109
- built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"foo\")) or " \
110
- "(local-name()='input' and (#{default_types}) and contains(@value, \"foo\"))]", text: /^foo$/}
111
- expect(selector_builder.build(selector)).to eq built
112
- end
113
- end
114
-
115
- context 'with value' do
116
- it 'input element value with String' do
117
- selector = {value: 'Preview'}
118
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
119
- "[normalize-space()='Preview' or @value='Preview']"}
120
- expect(selector_builder.build(selector)).to eq built
121
- end
122
-
123
- it 'button element value with String' do
124
- selector = {value: 'button_2'}
125
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
126
- "[normalize-space()='button_2' or @value='button_2']"}
127
- expect(selector_builder.build(selector)).to eq built
128
- end
129
-
130
- it 'input element value with simple Regexp' do
131
- selector = {value: /Prev/}
132
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
133
- '[contains(normalize-space(), "Prev") or contains(@value, "Prev")]'}
134
- expect(selector_builder.build(selector)).to eq built
135
- end
136
-
137
- it 'button element value with simple Regexp' do
138
- selector = {value: /on_2/}
139
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
140
- '[contains(normalize-space(), "on_2") or contains(@value, "on_2")]'}
141
- expect(selector_builder.build(selector)).to eq built
142
- end
143
-
144
- it 'button element text with String' do
145
- selector = {value: 'Button 2'}
146
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
147
- "[normalize-space()='Button 2' or @value='Button 2']"}
148
- expect(selector_builder.build(selector)).to eq built
149
- end
150
-
151
- it 'button element text with simple Regexp' do
152
- selector = {value: /ton 2/}
153
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
154
- '[contains(normalize-space(), "ton 2") or contains(@value, "ton 2")]'}
155
- expect(selector_builder.build(selector)).to eq built
156
- end
157
-
158
- it 'returns complex Regexp to the locator' do
159
- selector = {value: /^foo$/}
160
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
161
- '[contains(normalize-space(), "foo") or contains(@value, "foo")]', value: /^foo$/}
162
- expect(selector_builder.build(selector)).to eq built
163
- end
164
- end
165
-
166
- context 'with index' do
167
- it 'positive' do
168
- selector = {index: 3}
169
- built = {xpath: "(.//*[(local-name()='button') or (local-name()='input' and (#{default_types}))])[4]"}
170
- expect(selector_builder.build(selector)).to eq built
171
- end
172
-
173
- it 'negative' do
174
- selector = {index: -4}
175
- built = {xpath: "(.//*[(local-name()='button') or " \
176
- "(local-name()='input' and (#{default_types}))])[last()-3]"}
177
- expect(selector_builder.build(selector)).to eq built
178
- end
179
-
180
- it 'last' do
181
- selector = {index: -1}
182
- built = {xpath: "(.//*[(local-name()='button') or " \
183
- "(local-name()='input' and (#{default_types}))])[last()]"}
184
- expect(selector_builder.build(selector)).to eq built
185
- end
186
-
187
- it 'does not return index if it is zero' do
188
- selector = {index: 0}
189
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]"}
190
- expect(selector_builder.build(selector)).to eq built
191
- end
192
-
193
- it 'raises exception when index is not an Integer', skip_after: true do
194
- selector = {index: 'foo'}
195
- msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
196
- expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
197
- end
198
- end
199
-
200
- context 'with multiple locators' do
201
- it 'locates using class and attributes' do
202
- selector = {class: 'image', name: 'new_user_image', src: true}
203
- built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
204
- "[contains(concat(' ', normalize-space(@class), ' '), ' image ')]" \
205
- "[@name='new_user_image' and @src]"}
206
- expect(selector_builder.build(selector)).to eq built
5
+ module Watir
6
+ module Locators
7
+ class Button
8
+ describe SelectorBuilder do
9
+ include LocatorSpecHelper
10
+
11
+ let(:selector_builder) { described_class.new(attributes, query_scope) }
12
+ let(:uppercase) { 'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ' }
13
+ let(:lowercase) { 'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ' }
14
+ let(:default_types) do
15
+ "translate(@type,'#{uppercase}','#{lowercase}')=translate('button','#{uppercase}','#{lowercase}') or " \
16
+ "translate(@type,'#{uppercase}','#{lowercase}')=translate('reset','#{uppercase}','#{lowercase}') or " \
17
+ "translate(@type,'#{uppercase}','#{lowercase}')=translate('submit','#{uppercase}','#{lowercase}') or " \
18
+ "translate(@type,'#{uppercase}','#{lowercase}')=translate('image','#{uppercase}','#{lowercase}')"
19
+ end
20
+
21
+ describe '#build' do
22
+ it 'without any arguments' do
23
+ selector = {}
24
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]"}
25
+ expect(selector_builder.build(selector)).to eq built
26
+ end
27
+
28
+ context 'with type' do
29
+ it 'false only locates with button without a type' do
30
+ selector = {type: false}
31
+ built = {xpath: ".//*[(local-name()='button' and not(@type))]"}
32
+ expect(selector_builder.build(selector)).to eq built
33
+ end
34
+
35
+ it 'true locates button or input with a type' do
36
+ selector = {type: true}
37
+ built = {xpath: ".//*[(local-name()='button' and @type) or " \
38
+ "(local-name()='input' and (#{default_types}))]"}
39
+ expect(selector_builder.build(selector)).to eq built
40
+ end
41
+
42
+ it 'locates input or button element with specified type' do
43
+ selector = {type: 'reset'}
44
+ type = "translate('reset','#{uppercase}','#{lowercase}')"
45
+ built = {xpath: ".//*[(local-name()='button' and " \
46
+ "translate(@type,'#{uppercase}','#{lowercase}')=#{type}) or " \
47
+ "(local-name()='input' and (translate(@type,'#{uppercase}','#{lowercase}')=#{type}))]"}
48
+ expect(selector_builder.build(selector)).to eq built
49
+ end
50
+
51
+ it 'raises exception when a non-button type input is specified' do
52
+ selector = {type: 'checkbox'}
53
+ msg = 'Button Elements can not be located by input type: checkbox'
54
+ expect { selector_builder.build(selector) }
55
+ .to raise_exception Watir::Exception::LocatorException, msg
56
+ end
57
+ end
58
+
59
+ context 'with xpath or css' do
60
+ it 'returns tag name and type to the locator' do
61
+ selector = {xpath: '#disabled_button', tag_name: 'input', type: 'submit'}
62
+ built = {xpath: '#disabled_button', tag_name: 'input', type: 'submit'}
63
+ expect(selector_builder.build(selector)).to eq built
64
+ end
65
+ end
66
+
67
+ context 'with text' do
68
+ it 'locates value of input element with String' do
69
+ selector = {text: 'Button'}
70
+ built = {xpath: ".//*[(local-name()='button' and normalize-space()='Button') or " \
71
+ "(local-name()='input' and (#{default_types}) and @value='Button')]"}
72
+ expect(selector_builder.build(selector)).to eq built
73
+ end
74
+
75
+ it 'locates text of button element with String' do
76
+ selector = {text: 'Button 2'}
77
+ built = {xpath: ".//*[(local-name()='button' and normalize-space()='Button 2') or " \
78
+ "(local-name()='input' and (#{default_types}) and @value='Button 2')]"}
79
+ expect(selector_builder.build(selector)).to eq built
80
+ end
81
+
82
+ it 'locates value of input element with simple Regexp' do
83
+ selector = {text: /Button/}
84
+ built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"Button\")) or " \
85
+ "(local-name()='input' and (#{default_types}) and contains(@value, \"Button\"))]"}
86
+ expect(selector_builder.build(selector)).to eq built
87
+ end
88
+
89
+ it 'locates text of button element with simple Regexp' do
90
+ selector = {text: /Button 2/}
91
+ built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"Button 2\")) or " \
92
+ "(local-name()='input' and (#{default_types}) and contains(@value, \"Button 2\"))]"}
93
+ expect(selector_builder.build(selector)).to eq built
94
+ end
95
+
96
+ it 'Simple Regexp for text' do
97
+ selector = {text: /n 2/}
98
+ built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"n 2\")) or " \
99
+ "(local-name()='input' and (#{default_types}) and contains(@value, \"n 2\"))]"}
100
+ expect(selector_builder.build(selector)).to eq built
101
+ end
102
+
103
+ it 'Simple Regexp for value' do
104
+ selector = {text: /Prev/}
105
+ built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"Prev\")) or " \
106
+ "(local-name()='input' and (#{default_types}) and contains(@value, \"Prev\"))]"}
107
+ expect(selector_builder.build(selector)).to eq built
108
+ end
109
+
110
+ it 'returns complex Regexp to the locator' do
111
+ selector = {text: /^foo$/}
112
+ built = {xpath: ".//*[(local-name()='button' and contains(normalize-space(), \"foo\")) or " \
113
+ "(local-name()='input' and (#{default_types}) and contains(@value, \"foo\"))]",
114
+ text: /^foo$/}
115
+ expect(selector_builder.build(selector)).to eq built
116
+ end
117
+ end
118
+
119
+ context 'with value' do
120
+ it 'input element value with String' do
121
+ selector = {value: 'Preview'}
122
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
123
+ "[normalize-space()='Preview' or @value='Preview']"}
124
+ expect(selector_builder.build(selector)).to eq built
125
+ end
126
+
127
+ it 'button element value with String' do
128
+ selector = {value: 'button_2'}
129
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
130
+ "[normalize-space()='button_2' or @value='button_2']"}
131
+ expect(selector_builder.build(selector)).to eq built
132
+ end
133
+
134
+ it 'input element value with simple Regexp' do
135
+ selector = {value: /Prev/}
136
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
137
+ '[contains(normalize-space(), "Prev") or contains(@value, "Prev")]'}
138
+ expect(selector_builder.build(selector)).to eq built
139
+ end
140
+
141
+ it 'button element value with simple Regexp' do
142
+ selector = {value: /on_2/}
143
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
144
+ '[contains(normalize-space(), "on_2") or contains(@value, "on_2")]'}
145
+ expect(selector_builder.build(selector)).to eq built
146
+ end
147
+
148
+ it 'button element text with String' do
149
+ selector = {value: 'Button 2'}
150
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
151
+ "[normalize-space()='Button 2' or @value='Button 2']"}
152
+ expect(selector_builder.build(selector)).to eq built
153
+ end
154
+
155
+ it 'button element text with simple Regexp' do
156
+ selector = {value: /ton 2/}
157
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
158
+ '[contains(normalize-space(), "ton 2") or contains(@value, "ton 2")]'}
159
+ expect(selector_builder.build(selector)).to eq built
160
+ end
161
+
162
+ it 'returns complex Regexp to the locator' do
163
+ selector = {value: /^foo$/}
164
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
165
+ '[contains(normalize-space(), "foo") or contains(@value, "foo")]', value: /^foo$/}
166
+ expect(selector_builder.build(selector)).to eq built
167
+ end
168
+ end
169
+
170
+ context 'with index' do
171
+ it 'positive' do
172
+ selector = {index: 3}
173
+ built = {xpath: "(.//*[(local-name()='button') or (local-name()='input' and (#{default_types}))])[4]"}
174
+ expect(selector_builder.build(selector)).to eq built
175
+ end
176
+
177
+ it 'negative' do
178
+ selector = {index: -4}
179
+ built = {xpath: "(.//*[(local-name()='button') or " \
180
+ "(local-name()='input' and (#{default_types}))])[last()-3]"}
181
+ expect(selector_builder.build(selector)).to eq built
182
+ end
183
+
184
+ it 'last' do
185
+ selector = {index: -1}
186
+ built = {xpath: "(.//*[(local-name()='button') or " \
187
+ "(local-name()='input' and (#{default_types}))])[last()]"}
188
+ expect(selector_builder.build(selector)).to eq built
189
+ end
190
+
191
+ it 'does not return index if it is zero' do
192
+ selector = {index: 0}
193
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]"}
194
+ expect(selector_builder.build(selector)).to eq built
195
+ end
196
+
197
+ it 'raises exception when index is not an Integer', skip_after: true do
198
+ selector = {index: 'foo'}
199
+ msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
200
+ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
201
+ end
202
+ end
203
+
204
+ context 'with multiple locators' do
205
+ it 'locates using class and attributes' do
206
+ selector = {class: 'image', name: 'new_user_image', src: true}
207
+ built = {xpath: ".//*[(local-name()='button') or (local-name()='input' and (#{default_types}))]" \
208
+ "[contains(concat(' ', normalize-space(@class), ' '), ' image ')]" \
209
+ "[@name='new_user_image' and @src]"}
210
+ expect(selector_builder.build(selector)).to eq built
211
+ end
212
+ end
213
+ end
207
214
  end
208
215
  end
209
216
  end
@@ -2,63 +2,69 @@
2
2
 
3
3
  require_relative '../unit_helper'
4
4
 
5
- describe Watir::Locators::Cell::SelectorBuilder do
6
- include LocatorSpecHelper
5
+ module Watir
6
+ module Locators
7
+ class Cell
8
+ describe SelectorBuilder do
9
+ include LocatorSpecHelper
7
10
 
8
- let(:selector_builder) { described_class.new(attributes, query_scope) }
11
+ let(:selector_builder) { described_class.new(attributes, query_scope) }
9
12
 
10
- describe '#build' do
11
- it 'without any arguments' do
12
- selector = {}
13
- built = {xpath: "./*[local-name()='th' or local-name()='td']"}
13
+ describe '#build' do
14
+ it 'without any arguments' do
15
+ selector = {}
16
+ built = {xpath: "./*[local-name()='th' or local-name()='td']"}
14
17
 
15
- expect(selector_builder.build(selector)).to eq built
16
- end
18
+ expect(selector_builder.build(selector)).to eq built
19
+ end
17
20
 
18
- context 'with index' do
19
- it 'positive' do
20
- selector = {index: 3}
21
- built = {xpath: "(./*[local-name()='th' or local-name()='td'])[4]"}
21
+ context 'with index' do
22
+ it 'positive' do
23
+ selector = {index: 3}
24
+ built = {xpath: "(./*[local-name()='th' or local-name()='td'])[4]"}
22
25
 
23
- expect(selector_builder.build(selector)).to eq built
24
- end
26
+ expect(selector_builder.build(selector)).to eq built
27
+ end
25
28
 
26
- it 'negative' do
27
- selector = {index: -3}
28
- built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()-2]"}
29
+ it 'negative' do
30
+ selector = {index: -3}
31
+ built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()-2]"}
29
32
 
30
- expect(selector_builder.build(selector)).to eq built
31
- end
33
+ expect(selector_builder.build(selector)).to eq built
34
+ end
32
35
 
33
- it 'last' do
34
- selector = {index: -1}
35
- built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()]"}
36
+ it 'last' do
37
+ selector = {index: -1}
38
+ built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()]"}
36
39
 
37
- expect(selector_builder.build(selector)).to eq built
38
- end
40
+ expect(selector_builder.build(selector)).to eq built
41
+ end
39
42
 
40
- it 'does not return index if it is zero' do
41
- selector = {index: 0}
42
- built = {xpath: "./*[local-name()='th' or local-name()='td']"}
43
+ it 'does not return index if it is zero' do
44
+ selector = {index: 0}
45
+ built = {xpath: "./*[local-name()='th' or local-name()='td']"}
43
46
 
44
- expect(selector_builder.build(selector)).to eq built
45
- end
47
+ expect(selector_builder.build(selector)).to eq built
48
+ end
46
49
 
47
- it 'raises exception when index is not an Integer' do
48
- selector = {index: 'foo'}
49
- msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
50
+ it 'raises exception when index is not an Integer' do
51
+ selector = {index: 'foo'}
52
+ msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/
50
53
 
51
- expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
52
- end
53
- end
54
+ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
55
+ end
56
+ end
54
57
 
55
- context 'with multiple locators' do
56
- it 'attribute and text' do
57
- selector = {headers: /before_tax/, text: '5 934'}
58
- built = {xpath: "./*[local-name()='th' or local-name()='td']" \
59
- "[normalize-space()='5 934'][contains(@headers, \"before_tax\")]"}
58
+ context 'with multiple locators' do
59
+ it 'attribute and text' do
60
+ selector = {headers: /before_tax/, text: '5 934'}
61
+ built = {xpath: "./*[local-name()='th' or local-name()='td']" \
62
+ "[normalize-space()='5 934'][contains(@headers, \"before_tax\")]"}
60
63
 
61
- expect(selector_builder.build(selector)).to eq built
64
+ expect(selector_builder.build(selector)).to eq built
65
+ end
66
+ end
67
+ end
62
68
  end
63
69
  end
64
70
  end