watir_robot 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/KEYWORDS.rdoc +83 -0
- data/LICENSE +24 -0
- data/Manifest +28 -0
- data/README.rdoc +116 -0
- data/Rakefile +50 -0
- data/lib/watir_robot.rb +56 -0
- data/lib/watir_robot/exception.rb +76 -0
- data/lib/watir_robot/keywords/browser.rb +317 -0
- data/lib/watir_robot/keywords/button.rb +21 -0
- data/lib/watir_robot/keywords/checkbox.rb +53 -0
- data/lib/watir_robot/keywords/element.rb +95 -0
- data/lib/watir_robot/keywords/file_field.rb +30 -0
- data/lib/watir_robot/keywords/form.rb +143 -0
- data/lib/watir_robot/keywords/image.rb +18 -0
- data/lib/watir_robot/keywords/link.rb +21 -0
- data/lib/watir_robot/keywords/list.rb +42 -0
- data/lib/watir_robot/keywords/native.rb +148 -0
- data/lib/watir_robot/keywords/page.rb +324 -0
- data/lib/watir_robot/keywords/radio.rb +44 -0
- data/lib/watir_robot/keywords/select.rb +82 -0
- data/lib/watir_robot/keywords/table.rb +100 -0
- data/lib/watir_robot/keywords/text_field.rb +69 -0
- data/lib/watir_robot/parser.rb +170 -0
- data/scripts/example_tests/resource.txt +14 -0
- data/scripts/example_tests/test.txt +171 -0
- data/scripts/run_server.rb +13 -0
- data/watir_robot.gemspec +36 -0
- metadata +152 -0
@@ -0,0 +1,324 @@
|
|
1
|
+
module WatirRobot
|
2
|
+
|
3
|
+
#
|
4
|
+
# Functionality scoped against the entire HTML page
|
5
|
+
#
|
6
|
+
module Page
|
7
|
+
|
8
|
+
### Actions ###
|
9
|
+
|
10
|
+
#
|
11
|
+
# Log page source in a readable format
|
12
|
+
#
|
13
|
+
def log_page_source
|
14
|
+
print @browser.html
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Get source of page
|
19
|
+
#
|
20
|
+
# @return [String] the HTML content of the entire page
|
21
|
+
#
|
22
|
+
def get_page_source
|
23
|
+
@browser.html
|
24
|
+
end
|
25
|
+
|
26
|
+
#
|
27
|
+
# Get text of a page
|
28
|
+
#
|
29
|
+
# @return [String] teh text content of the entire page, without HTML markup
|
30
|
+
#
|
31
|
+
def get_page_text
|
32
|
+
@browser.text
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# Get status of page (located at bottom of browser window)
|
37
|
+
#
|
38
|
+
# @return [String] the status displayed at the bottom of the browser window
|
39
|
+
#
|
40
|
+
def get_page_status
|
41
|
+
@browser.status
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# Get page title
|
46
|
+
#
|
47
|
+
# @return [String] the title of the page as defined by the +<title>+ tag
|
48
|
+
def get_title
|
49
|
+
@browser.title
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Get the text of all elements that match a given XPath query
|
54
|
+
#
|
55
|
+
# @param [String] xpath the xpath query to use for searching
|
56
|
+
# @param [String] sep the separator that will be used in printing out the results
|
57
|
+
# @return [String] a string of the text of all the matching elements, separated by sep
|
58
|
+
#
|
59
|
+
def get_all_elements_by_xpath(xpath, sep = ';;')
|
60
|
+
matches = []
|
61
|
+
@browser.elements_by_xpath(xpath).each do |element|
|
62
|
+
matches << element.text
|
63
|
+
end
|
64
|
+
return matches.join(sep)
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Execute arbitrary JavaScript
|
69
|
+
#
|
70
|
+
def execute_javascript(code)
|
71
|
+
@browser.execute_script(code)
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
### Conditions ###
|
76
|
+
|
77
|
+
#
|
78
|
+
# Verify page text contains a certain value
|
79
|
+
#
|
80
|
+
# @param [String] text the text to compare against
|
81
|
+
#
|
82
|
+
def page_should_contain(text)
|
83
|
+
raise(Exception::PageMatchError, "The expected text #{text} was not contained in the page: #{@browser.text}") unless
|
84
|
+
@browser.text.include? text
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Verify page text does not contain a certain value
|
89
|
+
#
|
90
|
+
# @param [String] text the text to compare against
|
91
|
+
#
|
92
|
+
def page_should_not_contain(text)
|
93
|
+
raise(Exception::PageMatchError, "The expected text #{text} was not contained in the page: #{@browser.text}") if
|
94
|
+
@browser.text.include? text
|
95
|
+
end
|
96
|
+
|
97
|
+
#
|
98
|
+
# Verify button exists on page
|
99
|
+
#
|
100
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
101
|
+
#
|
102
|
+
def page_should_contain_button(loc)
|
103
|
+
raise(Exception::ElementDoesNotExist, "The button described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
104
|
+
@browser.button(parse_location(loc)).exists?
|
105
|
+
end
|
106
|
+
|
107
|
+
#
|
108
|
+
# Verify button does not exist on page
|
109
|
+
#
|
110
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
111
|
+
#
|
112
|
+
def page_should_not_contain_button(loc)
|
113
|
+
raise(Exception::ElementDoesNotExist, "The button described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
114
|
+
@browser.button(parse_location(loc)).exists?
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Verify checkbox exists on page
|
119
|
+
#
|
120
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
121
|
+
#
|
122
|
+
def page_should_contain_checkbox(loc)
|
123
|
+
raise(Exception::ElementDoesNotExist, "The checkbox described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
124
|
+
@browser.checkbox(parse_location(loc)).exists?
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# Verify checkbox does not exist on page
|
129
|
+
#
|
130
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
131
|
+
#
|
132
|
+
def page_should_not_contain_checkbox(loc)
|
133
|
+
raise(Exception::ElementDoesNotExist, "The checkbox described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
134
|
+
@browser.checkbox(parse_location(loc)).exists?
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Verify element exists on page
|
139
|
+
#
|
140
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
141
|
+
#
|
142
|
+
def page_should_contain_element(loc)
|
143
|
+
raise(Exception::ElementDoesNotExist, "The element described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
144
|
+
@browser.element(parse_location(loc)).exists?
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Verify element exists on page
|
149
|
+
#
|
150
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
151
|
+
#
|
152
|
+
def page_should_not_contain_element(loc)
|
153
|
+
raise(Exception::ElementDoesNotExist, "The element described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
154
|
+
@browser.element(parse_location(loc)).exists?
|
155
|
+
end
|
156
|
+
|
157
|
+
#
|
158
|
+
# Verify image exists on page
|
159
|
+
#
|
160
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
161
|
+
#
|
162
|
+
def page_should_contain_image(loc)
|
163
|
+
raise(Exception::ElementDoesNotExist, "The image described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
164
|
+
@browser.image(parse_location(loc)).exists?
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
# Verify image does not exist on page
|
169
|
+
#
|
170
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
171
|
+
#
|
172
|
+
def page_should_not_contain_image(loc)
|
173
|
+
raise(Exception::ElementDoesNotExist, "The image described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
174
|
+
@browser.image(parse_location(loc)).exists?
|
175
|
+
end
|
176
|
+
|
177
|
+
#
|
178
|
+
# Verify link exists on page
|
179
|
+
#
|
180
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
181
|
+
#
|
182
|
+
def page_should_contain_link(loc)
|
183
|
+
raise(Exception::ElementDoesNotExist, "The link described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
184
|
+
@browser.link(parse_location(loc)).exists?
|
185
|
+
end
|
186
|
+
|
187
|
+
#
|
188
|
+
# Verify link does not exist on page
|
189
|
+
#
|
190
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
191
|
+
#
|
192
|
+
def page_should_not_contain_link(loc)
|
193
|
+
raise(Exception::ElementDoesNotExist, "The link described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
194
|
+
@browser.link(parse_location(loc)).exists?
|
195
|
+
end
|
196
|
+
|
197
|
+
#
|
198
|
+
# Verify list exists on page
|
199
|
+
#
|
200
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
201
|
+
# @param [String, nil] ordered nil means check both ul and ol, true is ol, false is ul; strings for the booleans because the arguments come from Robot Framework
|
202
|
+
#
|
203
|
+
def page_should_contain_list(loc, ordered = nil)
|
204
|
+
ordered = ordered.downcase unless ordered.nil?
|
205
|
+
if ordered.nil?
|
206
|
+
# Not specified; match either
|
207
|
+
raise(Exception::ElementDoesNotExist, "The list described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
208
|
+
(@browser.ol(parse_location(loc)).exists? || @browser.ul(parse_location(loc)).exists?)
|
209
|
+
elsif ordered == 'true'
|
210
|
+
raise(Exception::ElementDoesNotExist, "The ordered list described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
211
|
+
@browser.ol(parse_location(loc)).exists?
|
212
|
+
elsif ordered == 'false'
|
213
|
+
raise(Exception::ElementDoesNotExist, "The unordered list described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
214
|
+
@browser.ul(parse_location(loc)).exists?
|
215
|
+
else
|
216
|
+
raise(ArgumentError, "If you specify ordered vs. unordered lists, the only valid values are 'true' or 'false' (case-insensitive)")
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
#
|
221
|
+
# Verify list does not exist on page
|
222
|
+
#
|
223
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
224
|
+
# @param [String, nil] ordered nil means check both ul and ol, true is ol, false is ul; strings for the booleans because the arguments come from Robot Framework
|
225
|
+
#
|
226
|
+
def page_should_not_contain_list(loc, ordered = nil)
|
227
|
+
ordered = ordered.downcase unless ordered == nil
|
228
|
+
if ordered.nil?
|
229
|
+
# Not specified; match either
|
230
|
+
raise(Exception::ElementDoesNotExist, "The list described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
231
|
+
(@browser.ol(parse_location(loc)).exists? || @browser.ul(parse_location(loc)).exists?)
|
232
|
+
elsif ordered == 'true'
|
233
|
+
raise(Exception::ElementDoesNotExist, "The ordered list described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
234
|
+
@browser.ol(parse_location(loc)).exists?
|
235
|
+
elsif ordered == 'false'
|
236
|
+
raise(Exception::ElementDoesNotExist, "The unordered list described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
237
|
+
@browser.ul(parse_location(loc)).exists?
|
238
|
+
else
|
239
|
+
raise(ArgumentError, "If you specify ordered vs. unordered lists, the only valid values are 'true' or 'false' (case-insensitive)")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
#
|
244
|
+
# Verify radio button exists on page
|
245
|
+
#
|
246
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
247
|
+
#
|
248
|
+
def page_should_contain_radio_button(loc)
|
249
|
+
raise(Exception::ElementDoesNotExist, "The radio button described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
250
|
+
@browser.radio(parse_location(loc)).exists?
|
251
|
+
end
|
252
|
+
|
253
|
+
#
|
254
|
+
# Verify radio button does not exist on page
|
255
|
+
#
|
256
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
257
|
+
#
|
258
|
+
def page_should_not_contain_radio_button(loc)
|
259
|
+
raise(Exception::ElementDoesNotExist, "The radio button described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
260
|
+
@browser.radio(parse_location(loc)).exists?
|
261
|
+
end
|
262
|
+
|
263
|
+
#
|
264
|
+
# Verify select list does exist on page
|
265
|
+
#
|
266
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
267
|
+
#
|
268
|
+
def page_should_contain_select_list(loc)
|
269
|
+
raise(Exception::ElementDoesNotExist, "The select list described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
270
|
+
@browser.select(parse_location(loc)).exists?
|
271
|
+
end
|
272
|
+
|
273
|
+
#
|
274
|
+
# Verify select list does not exist on page
|
275
|
+
#
|
276
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
277
|
+
#
|
278
|
+
def page_should_not_contain_select_list(loc)
|
279
|
+
raise(Exception::ElementDoesNotExist, "The select list described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
280
|
+
@browser.select(parse_location(loc)).exists?
|
281
|
+
end
|
282
|
+
|
283
|
+
#
|
284
|
+
# Verify link exists on page
|
285
|
+
#
|
286
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
287
|
+
#
|
288
|
+
def page_should_contain_textfield(loc)
|
289
|
+
raise(Exception::ElementDoesNotExist, "The text field described by #{loc} is not contained within the page:\n#{@browser.html}") unless
|
290
|
+
@browser.text_field(parse_location(loc)).exists?
|
291
|
+
end
|
292
|
+
|
293
|
+
#
|
294
|
+
# Verify link does not exist on page
|
295
|
+
#
|
296
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
297
|
+
#
|
298
|
+
def page_should_not_contain_textfield(loc)
|
299
|
+
raise(Exception::ElementDoesNotExist, "The text field described by #{loc} is not contained within the page:\n#{@browser.html}") if
|
300
|
+
@browser.text_field(parse_location(loc)).exists?
|
301
|
+
end
|
302
|
+
|
303
|
+
#
|
304
|
+
# Verify page title, i.e. the <title> in <head>
|
305
|
+
#
|
306
|
+
# @param [String] title the title text to compare against
|
307
|
+
#
|
308
|
+
def title_should_be(title)
|
309
|
+
raise(Exception::TitleMatchError, "The page title #{@browser.title} is not correct; it should be #{title}") unless @browser.title == title
|
310
|
+
end
|
311
|
+
|
312
|
+
#
|
313
|
+
# Verify that the page title contains a certain value
|
314
|
+
#
|
315
|
+
# @param [String] text the text to compare against
|
316
|
+
#
|
317
|
+
def title_should_contain(text)
|
318
|
+
raise(Exception::TitleMatchError, "The page title #{@browser.url} is not correct; it should contain #{text}") unless @browser.title.include?(text)
|
319
|
+
end
|
320
|
+
|
321
|
+
end
|
322
|
+
|
323
|
+
end
|
324
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module WatirRobot
|
2
|
+
|
3
|
+
#
|
4
|
+
# Functionality related to radio button form elements
|
5
|
+
#
|
6
|
+
module Radio
|
7
|
+
|
8
|
+
### Actions ###
|
9
|
+
|
10
|
+
#
|
11
|
+
# Select a radio button
|
12
|
+
#
|
13
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
14
|
+
#
|
15
|
+
def select_radio_button(loc)
|
16
|
+
@browser.radio(parse_location(loc)).set
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
### Conditions ###
|
21
|
+
|
22
|
+
#
|
23
|
+
# Verify that radio button is selected
|
24
|
+
#
|
25
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
26
|
+
#
|
27
|
+
def radio_button_should_be_selected(loc)
|
28
|
+
raise(Exception::RadioSelectionError, "The radio button located at #{loc} is not selected.") unless
|
29
|
+
@browser.radio(parse_location(loc)).set?
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Verify that radio button is not selected
|
34
|
+
#
|
35
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
36
|
+
#
|
37
|
+
def radio_button_should_not_be_selected(loc)
|
38
|
+
raise(Exception::RadioSelectionError, "The radio button located at #{loc} is selected.") if
|
39
|
+
@browser.radio(parse_location(loc)).set?
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module WatirRobot
|
2
|
+
|
3
|
+
#
|
4
|
+
# Functionality related to select list form elements
|
5
|
+
#
|
6
|
+
module Select
|
7
|
+
|
8
|
+
### Actions ###
|
9
|
+
|
10
|
+
#
|
11
|
+
# Select a single item from a drop-down select list
|
12
|
+
#
|
13
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
14
|
+
# @param [String] item the label, text or value of an item to select
|
15
|
+
# @param [String] by_value boolean, whether or not to select an element by visible text or by value attribute (as string because arg comes from Robot Framework)
|
16
|
+
#
|
17
|
+
def select_item_from_list(list_loc, item_loc)
|
18
|
+
# Give user option to select by value rather than by text of option or label
|
19
|
+
# Since the text is immediately visible, I assume people will default to that
|
20
|
+
if item_loc[0..4].downcase == 'text='
|
21
|
+
item_loc = item_loc[5..item_loc.length]
|
22
|
+
@browser.select(parse_location(list_loc)).select(item_loc)
|
23
|
+
elsif item_loc[0..5].downcase == 'value='
|
24
|
+
item_loc = item_loc[6..item_loc.length]
|
25
|
+
@browser.select(parse_location(list_loc)).select_value(item_loc)
|
26
|
+
else
|
27
|
+
raise(ArgumentError, "The only attributes allowed are 'text' and 'value'")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Select all items from a drop-down select list
|
33
|
+
#
|
34
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
35
|
+
#
|
36
|
+
def select_all_items_from_list(loc)
|
37
|
+
select_list = @browser.select(parse_location(loc))
|
38
|
+
select_list.options.each do |item|
|
39
|
+
select_list.select_value(item.value) # Using value because it's more likely to be programmatically ensured unique
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Clear all select options from a drop-down select list
|
45
|
+
#
|
46
|
+
# @note The underlying Watir-WebDriver code will raise an error if the
|
47
|
+
# select list is not a multiple select list
|
48
|
+
#
|
49
|
+
# @param [String] loc attribute/value pairs that match an HTML element
|
50
|
+
#
|
51
|
+
def clear_items_from_list(loc)
|
52
|
+
@browser.select(parse_location(loc)).clear
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
### Conditions ###
|
57
|
+
|
58
|
+
#
|
59
|
+
# Ensure that an item is selected
|
60
|
+
#
|
61
|
+
# @param [String] list_loc attribute/value pairs that match a select list
|
62
|
+
# @param [String] item_loc attribute/value pairs that match an item in a select list
|
63
|
+
#
|
64
|
+
def item_should_be_selected(list_loc, item_loc)
|
65
|
+
raise(Exception::SelectListSelectionError, "The item described by #{item_loc} in the select list described by #{list_loc} is not selected") unless
|
66
|
+
@browser.select(parse_location(list_loc)).option(parse_location(item_loc)).selected?
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Ensure that an item is not selected
|
71
|
+
#
|
72
|
+
# @param [String] list_loc attribute/value pairs that match a select list
|
73
|
+
# @param [String] item_loc attribute/value pairs that match an item in a select list
|
74
|
+
#
|
75
|
+
def item_should_not_be_selected(list_loc, item_loc)
|
76
|
+
raise(Exception::SelectListSelectionError, "The item described by #{item_loc} in the select list described by #{list_loc} is selected") if
|
77
|
+
@browser.select(parse_location(list_loc)).option(parse_location(item_loc)).selected?
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|