-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxlwatir.rb
182 lines (150 loc) · 5.1 KB
/
xlwatir.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
#Collection of commands
#Separated out to a new file 'BaseCommandsWatir.rb'
# Ref: http://wiki.seleniumhq.org/display/WTR/Cheat+Sheet
# Ref: http://www.w3schools.com/html/html_forms.asp
# ref: http://pettichord.com/watirtutorial/docs/watir_cheat_sheet/WTR/Methods%20supported%20by%20Element.html
# --- Browser/Form functions ---
def goto_url(params)
$ie.goto(params[0])
end
def go_back(params)
$ie.back()
end
def submit_form(params)
#test default form action
$ie.form(:action, "submit")
end
def bypass_cert(params)
# Dismiss annoying IE warning
if $ie.text.include?("There is a problem with this website's security certificate.")
$log.add("bypassing TA certificate error")
$ie.link(:name, "overridelink").click
end
end
# --- Normal Buttons ---
def click_button_by_id(params)
$ie.button(:id, params[0]).click
end
def click_button_by_name(params)
$ie.button(:name, params[0]).click
end
# --- Text & Labels ---
def click_label_text(params)
$ie.label(:text, params[0]).click
end
def verify_text_on_page(params)
if ($ie.pageContainsText(params[0]))
$log.pass("Page contains text: #{params[0]}")
else
$log.fail("Page does not contain text: #{params[0]}")
end
end
def verify_page_title(params)
if ($ie.title = params[0])
$log.pass("Found expected page title: #{params[0]}")
else
$log.fail("Did not find expected page title: #{params[0]}, Actual was: #{$ie.title}")
end
end
def verify_table_entry_by_id(params)
#example: first row, third column of table "customers"
# $ie.table(:id, "customers")[1][3].text = "[email protected]"
table_id = params[0]
rownum = params[1]
colnum = params[2]
expected = params[3]
$log.add("Checking text in Table[table_id,row,col] => [#{table_id},#{rownum},#{colnum}]")
actual_data = $ie.table(:id, table_id)[rownum][colnum].text
if (actual_data == expected)
$log.pass("Found expected table data: #{expected}")
else
$log.fail("Did not find expected table data: #{expected}, Actual was: #{actual_data}")
end
end
# --- Interact via XPath ---
def click_element_by_xpath(params)
#use an XPath expression to find ANY element and click it!
#eg: $ie.element_by_xpath("//area[contains(@href , 'signup.htm')]").click()
# Requires latest WATiR gem (won't work with 1.4.1!)
$ie.element_by_xpath(params[0]).click()
end
def find_text_by_xpath(params)
#use an XPath expression to find some text
#eg: $ie.element_by_xpath("//h2[contains(text(),'Now you')]").innerText
if ie.element_by_xpath(params[0]).nil?
$log.fail "Nothing found via XPath expression: #{params[0]}"
else
$log.pass "The text is existent, it is: #{$ie.element_by_xpath(params[0]).innerText}"
end
end
def verify_text_by_xpath(params)
#use an XPath expression to find some text, then verify it
#eg: $ie.element_by_xpath("//h2[contains(text(),'Now you')]").innerText
actual_data = $ie.element_by_xpath(params[0]).innerText
expected = params[1]
if actual_data == expected
$log.pass("Found expected data: #{expected}")
else
$log.fail("Did not find expected data: #{expected}, Actual was: #{actual_data}")
end
end
# --- Input Fields ---
def input_text_by_name(params)
$ie.text_field(:name, params[0]).set params[1]
end
def input_text_by_id(params)
$ie.text_field(:id, params[0]).set params[1]
end
def clear_text_by_name(params)
$ie.text_field(:name, params[0]).clear
end
# --- Radio Buttons ---
def set_radio_by_id(params)
$ie.radio(:id, params[0]).set
end
def set_radio_by_name(params)
$ie.radio(:name, params[0]).set
end
def set_radio_by_index(params)
$ie.radio(:index, params[0]).set
end
def clear_radio_by_name(params)
$ie.radio(:name, params[0]).clear
end
# --- CheckBoxes ---
def set_checkbox_by_name(params)
$ie.checkbox(:name, params[0]).set
end
def set_checkbox_by_index(params)
$ie.checkbox(:index, params[0]).set
end
def clear_checkbox_by_name(params)
$ie.checkbox(:name, params[0]).clear
end
# --- Dropdown List ---
def select_list_item_by_name(params)
#param[0]=overall list name
#param[1]=item text
$ie.select_list(:name, params[0]).select(params[1])
end
def select_list_item_by_id(params)
#param[0]=overall list name
#param[1]=item text
$ie.select_list(:id, params[0]).select(params[1])
end
def clear_list_by_name(params)
$ie.select_list(:name, params[0]).clearSelection
end
# --- Links ---
def click_link_by_url(params)
#TODO Any element can be 'flashed'. Make flashing an option for scripter
$ie.link(:href, params[0]).flash
$ie.link(:href, params[0]).click
end
def click_link_by_text(params)
$ie.link(:text, params[0]).flash
$ie.link(:text, params[0]).click
end
#if __FILE__ == $0
#TODO Generated stub
#end