forked from cheezy/page-object
/
multi_elements_steps.rb
305 lines (229 loc) · 9.28 KB
/
multi_elements_steps.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
class MultiElementsPage
include PageObject
end
Given /^I am on the multi elements page$/ do
@page = MultiElementsPage.new(@browser)
@page.navigate_to(UrlHelper.multi)
end
When /^I select the buttons with class "([^\"]*)"$/ do |class_name|
@elements = @page.button_elements(:class => class_name)
end
Then /^I should have (\d+) buttons$/ do |num_buttons|
@elements.size.should == num_buttons.to_i
end
Then /^the value of button (\d+) should be "([^\"]*)"$/ do |button_num, value|
@elements[button_num.to_i - 1].value.should == value
end
When /^I select the text fields with class "([^\"]*)"$/ do |class_name|
@elements = @page.text_field_elements(:class => class_name)
end
Then /^I should have (\d+) text fields$/ do |num_text_fields|
@elements.size.should == num_text_fields.to_i
end
Then /^the value of text field (\d+) should be "([^\"]*)"$/ do |text_field_num, value|
@elements[text_field_num.to_i - 1].value.should == value
end
When /^I select the hidden fields with class "([^\"]*)"$/ do |class_name|
@elements = @page.hidden_field_elements(:class => class_name)
end
Then /^I should have (\d+) hidden fields$/ do |num_hidden_fields|
@elements.size.should == num_hidden_fields.to_i
end
Then /^the value of hidden field (\d+) should be "([^\"]*)"$/ do |hidden_field_num, value|
@elements[hidden_field_num.to_i - 1].value.should == value
end
When /^I select the text areas with class "([^\"]*)"$/ do |class_name|
@elements = @page.text_area_elements(:class => class_name)
end
Then /^I should have (\d+) text areas$/ do |num_text_areas|
@elements.size.should == num_text_areas.to_i
end
Then /^the value of text area (\d+) should be "([^\"]*)"$/ do |text_area_num, value|
@elements[text_area_num.to_i - 1].value.should == value
end
When /^I select the select lists with class "([^\"]*)"$/ do |class_name|
@elements = @page.select_list_elements(:class => class_name)
end
Then /^I should have (\d+) select lists$/ do |num_select_lists|
@elements.size.should == num_select_lists.to_i
end
Then /^the value of select list (\d+) should be "([^\"]*)"$/ do |select_list_num, value|
@elements[select_list_num.to_i - 1].value.should == value
end
When /^I select the link with class "([^\"]*)"$/ do |link_class|
@elements = @page.link_elements(:class => link_class)
end
Then /^I should have (\d+) links$/ do |num_links|
@elements.size.should == num_links.to_i
end
Then /^the text of link (\d+) should be "([^\"]*)"$/ do |link_num, text|
@elements[link_num.to_i - 1].text.should == text
end
When /^I select the check boxes with class "([^\"]*)"$/ do |class_name|
@elements = @page.checkbox_elements(:class => class_name)
end
Then /^I should have (\d+) checkboxes$/ do |num_checkboxes|
@elements.size.should == num_checkboxes.to_i
end
Then /^the value of checkbox (\d+) should be "([^\"]*)"$/ do |checkbox_num, value|
@elements[checkbox_num.to_i - 1].value.should == value
end
When /^I select the radio button with class "([^\"]*)"$/ do |class_name|
@elements = @page.radio_button_elements(:class => class_name)
end
Then /^I should have (\d+) radio buttons$/ do |num_radio_buttons|
@elements.size.should == num_radio_buttons.to_i
end
Then /^the value of radio button (\d+) should be "([^\"]*)"$/ do |radio_button_num, value|
@elements[radio_button_num.to_i - 1].value.should == value
end
When /^I select the div with class "([^\"]*)"$/ do |class_name|
@elements = @page.div_elements(:class => class_name)
end
Then /^I should have (\d+) divs$/ do |num_divs|
@elements.size.should == num_divs.to_i
end
Then /^the text of div (\d+) should be "([^\"]*)"$/ do |div_num, text|
@elements[div_num.to_i - 1].text.should == text
end
When /^I select the spans with class "([^\"]*)"$/ do |class_name|
@elements = @page.span_elements(:class => class_name)
end
Then /^I should have (\d+) spans$/ do |num_spans|
@elements.size.should == num_spans.to_i
end
Then /^the text of span (\d+) should be "([^\"]*)"$/ do |span_num, text|
@elements[span_num.to_i - 1].text.should == text
end
When /^I select the tables with class "([^\"]*)"$/ do |class_name|
@elements = @page.table_elements(:class => class_name)
end
Then /^I should have (\d+) tables$/ do |num_tables|
@elements.size.should == num_tables.to_i
end
Then /^the first row first column for table (\d+) should have "([^\"]*)"$/ do |table_num, text|
@elements[table_num.to_i - 1][0][0].text.should == text
end
When /^I select the cells with class "([^\"]*)"$/ do |cell_class|
@elements = @page.cell_elements(:class => cell_class)
end
Then /^I should have (\d+) cells$/ do |num_cells|
@elements.size.should == num_cells.to_i
end
Then /^the text for cell (\d+) should be "([^\"]*)"$/ do |cell_num, text|
@elements[cell_num.to_i - 1].text.should == text
end
When /^I select the images with class "([^\"]*)"$/ do |class_name|
@elements = @page.image_elements(:class => class_name)
end
Then /^I should have (\d+) images$/ do |num_images|
@elements.size.should == num_images.to_i
end
Then /^the alt for image (\d+) should be "([^\"]*)"$/ do |image_num, alt|
@elements[image_num.to_i - 1].attribute(:alt).should == alt
end
When /^I select the forms with class "([^\"]*)"$/ do |class_name|
@elements = @page.form_elements(:class => class_name)
end
Then /^I should have (\d+) forms$/ do |number|
@elements.size.should == number.to_i
end
Then /^the action for form (\d+) should be "([^\"]*)"$/ do |form_number, action|
@elements[form_number.to_i-1].attribute(:action).should match action
end
When /^I select the list items with class "([^\"]*)"$/ do |class_name|
@elements = @page.list_item_elements(:class => class_name)
end
Then /^I should have (\d+) list items$/ do |num_list_items|
@elements.size.should == num_list_items.to_i
end
Then /^the text for list item (\d+) should be "([^\"]*)"$/ do |list_item_num, text|
@elements[list_item_num.to_i - 1].text.should == text
end
When /^I select the unordered list with class "([^\"]*)"$/ do |class_name|
@elements = @page.unordered_list_elements(:class => class_name)
end
Then /^I should have (\d+) unordered lists$/ do |num_unordered_lists|
@elements.size.should == num_unordered_lists.to_i
end
Then /^the text for the first item in unordered list (\d+) should be "([^\"]*)"$/ do |ul_num, text|
@elements[ul_num.to_i - 1][0].text.should == text
end
When /^I select the ordered lists with class "([^\"]*)"$/ do |class_name|
@elements = @page.ordered_list_elements(:class => class_name)
end
Then /^I should have (\d+) ordered lists$/ do |num_ol|
@elements.size.should == num_ol.to_i
end
Then /^the text for the first item in ordered list (\d+) should be "([^\"]*)"$/ do |ol_num, text|
@elements[ol_num.to_i - 1][0].text.should == text
end
When /^I select the h1s with class "([^\"]*)"$/ do |class_name|
@elements = @page.h1_elements(:class => class_name)
end
Then /^I should have (\d+) h1s$/ do |num_h1s|
@elements.size.should == num_h1s.to_i
end
Then /^the text for h1 (\d+) should be "([^\"]*)"$/ do |h1_num, text|
@elements[h1_num.to_i - 1].text.should == text
end
When /^I select the h2s with the class "([^\"]*)"$/ do |class_name|
@elements = @page.h2_elements(:class => class_name)
end
Then /^I should have (\d+) h2s$/ do |num_h2s|
@elements.size.should == num_h2s.to_i
end
Then /^the text for h2 (\d+) should be "([^\"]*)"$/ do |h2_num, text|
@elements[h2_num.to_i - 1].text.should == text
end
When /^I select the h3s with the class "([^\"]*)"$/ do |class_name|
@elements = @page.h3_elements(:class => class_name)
end
Then /^I should have (\d+) h3s$/ do |num_h3s|
@elements.size.should == num_h3s.to_i
end
Then /^the text for h3 (\d+) should be "([^\"]*)"$/ do |h3_num, text|
@elements[h3_num.to_i - 1].text.should == text
end
When /^I select the h4s with the class "([^\"]*)"$/ do |class_name|
@elements = @page.h4_elements(:class => class_name)
end
Then /^I should have (\d+) h4s$/ do |num_h4s|
@elements.size.should == num_h4s.to_i
end
Then /^the text for H4 (\d+) should be "([^\"]*)"$/ do |h4_num, text|
@elements[h4_num.to_i - 1].text.should == text
end
When /^I select the h5s with the class "([^\"]*)"$/ do |class_name|
@elements = @page.h5_elements(:class => class_name)
end
Then /^I should have (\d+) h5s$/ do |num_h5s|
@elements.size.should == num_h5s.to_i
end
Then /^the text for H5 (\d+) should be "([^\"]*)"$/ do |h5_num, text|
@elements[h5_num.to_i - 1].text.should == text
end
When /^I select the h6s with the class "([^\"]*)"$/ do |class_name|
@elements = @page.h6_elements(:class => class_name)
end
Then /^I should have (\d+) h6s$/ do |num_h6s|
@elements.size.should == num_h6s.to_i
end
Then /^the text for H6 (\d+) should be "([^\"]*)"$/ do |h6_num, text|
@elements[h6_num.to_i - 1].text.should == text
end
When /^I select the paragraph with class "([^\"]*)"$/ do |class_name|
@elements = @page.paragraph_elements(:class => class_name)
end
Then /^I should have (\d+) paragraphs$/ do |num_paragraphs|
@elements.size.should == num_paragraphs.to_i
end
Then /^the text for paragraph (\d+) should be "([^\"]*)"$/ do |para_num, text|
@elements[para_num.to_i - 1].text.should == text
end
Then /^I should be able to find (\d+) buttons using no identifier$/ do |num_buttons|
@page.button_elements.size.should == num_buttons.to_i
end
Then /^I should be able to find (\d+) text fields using no identifier$/ do |num_text_fields|
@page.text_field_elements.size.should == num_text_fields.to_i
end