watir-classic 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +721 -0
- data/LICENSE +34 -0
- data/README.rdoc +78 -0
- data/VERSION +1 -0
- data/bin/watir-console +5 -0
- data/lib/watir-classic.rb +14 -0
- data/lib/watir-classic/IEDialog/Release/IEDialog.dll +0 -0
- data/lib/watir-classic/assertions.rb +44 -0
- data/lib/watir-classic/browser.rb +149 -0
- data/lib/watir-classic/browsers.rb +7 -0
- data/lib/watir-classic/close_all.rb +31 -0
- data/lib/watir-classic/container.rb +110 -0
- data/lib/watir-classic/contrib/enabled_popup.rb +21 -0
- data/lib/watir-classic/contrib/ie-new-process.rb +27 -0
- data/lib/watir-classic/contrib/page_checker.rb +29 -0
- data/lib/watir-classic/cookies.rb +80 -0
- data/lib/watir-classic/core.rb +43 -0
- data/lib/watir-classic/dialogs/file_field.rb +34 -0
- data/lib/watir-classic/dialogs/javascript.rb +43 -0
- data/lib/watir-classic/drag_and_drop_helper.rb +68 -0
- data/lib/watir-classic/element.rb +438 -0
- data/lib/watir-classic/element_collection.rb +109 -0
- data/lib/watir-classic/element_extensions.rb +69 -0
- data/lib/watir-classic/exceptions.rb +50 -0
- data/lib/watir-classic/form.rb +96 -0
- data/lib/watir-classic/frame.rb +47 -0
- data/lib/watir-classic/ie-class.rb +767 -0
- data/lib/watir-classic/ie-process.rb +47 -0
- data/lib/watir-classic/ie.rb +20 -0
- data/lib/watir-classic/image.rb +111 -0
- data/lib/watir-classic/input_elements.rb +480 -0
- data/lib/watir-classic/irb-history.rb +31 -0
- data/lib/watir-classic/link.rb +46 -0
- data/lib/watir-classic/locator.rb +243 -0
- data/lib/watir-classic/logger.rb +19 -0
- data/lib/watir-classic/matches.rb +23 -0
- data/lib/watir-classic/modal_dialog.rb +72 -0
- data/lib/watir-classic/module.rb +12 -0
- data/lib/watir-classic/non_control_elements.rb +114 -0
- data/lib/watir-classic/options.rb +56 -0
- data/lib/watir-classic/page-container.rb +114 -0
- data/lib/watir-classic/process.rb +20 -0
- data/lib/watir-classic/screen_capture.rb +115 -0
- data/lib/watir-classic/supported_elements.rb +172 -0
- data/lib/watir-classic/table.rb +224 -0
- data/lib/watir-classic/testcase.rb +97 -0
- data/lib/watir-classic/util.rb +35 -0
- data/lib/watir-classic/version.rb +4 -0
- data/lib/watir-classic/wait.rb +41 -0
- data/lib/watir-classic/wait_helper.rb +12 -0
- data/lib/watir-classic/waiter.rb +98 -0
- data/lib/watir-classic/win32.rb +40 -0
- data/lib/watir-classic/win32ole.rb +16 -0
- data/lib/watir-classic/win32ole/1.8.7/win32ole.so +0 -0
- data/lib/watir-classic/win32ole/1.9.3/win32ole.so +0 -0
- data/lib/watir-classic/window.rb +68 -0
- data/lib/watir-classic/xpath_locator.rb +52 -0
- data/rakefile.rb +54 -0
- data/unittests/all_tests.rb +10 -0
- data/unittests/buttons_xpath_test.rb +68 -0
- data/unittests/checkbox_test.rb +163 -0
- data/unittests/checkbox_xpath_test.rb +106 -0
- data/unittests/click_no_wait_test.rb +23 -0
- data/unittests/close_all_test.rb +17 -0
- data/unittests/core_tests.rb +17 -0
- data/unittests/css_selector_test.rb +44 -0
- data/unittests/css_test.rb +38 -0
- data/unittests/dialog_test.rb +64 -0
- data/unittests/div2_xpath_test.rb +21 -0
- data/unittests/div_test.rb +170 -0
- data/unittests/div_xpath_test.rb +95 -0
- data/unittests/document_standards.rb +63 -0
- data/unittests/element_collection_indexes_test.rb +57 -0
- data/unittests/element_collections_test.rb +100 -0
- data/unittests/element_test.rb +47 -0
- data/unittests/errorchecker_test.rb +31 -0
- data/unittests/filefield_test.rb +43 -0
- data/unittests/filefield_xpath_test.rb +35 -0
- data/unittests/form_test.rb +282 -0
- data/unittests/form_xpath_test.rb +254 -0
- data/unittests/frame_test.rb +165 -0
- data/unittests/google_form_test.rb +15 -0
- data/unittests/html/JavascriptClick.html +39 -0
- data/unittests/html/blankpage.html +11 -0
- data/unittests/html/buttons1.html +40 -0
- data/unittests/html/checkboxes1.html +89 -0
- data/unittests/html/click_no_wait.html +14 -0
- data/unittests/html/complex_table.html +35 -0
- data/unittests/html/cssTest.html +42 -0
- data/unittests/html/depot_store.html +59 -0
- data/unittests/html/div.html +92 -0
- data/unittests/html/div_xml.html +21 -0
- data/unittests/html/fileupload.html +44 -0
- data/unittests/html/formTest1.html +38 -0
- data/unittests/html/forms2.html +44 -0
- data/unittests/html/forms3.html +131 -0
- data/unittests/html/forms4.html +26 -0
- data/unittests/html/frame_buttons.html +4 -0
- data/unittests/html/frame_links.html +4 -0
- data/unittests/html/frame_multi.html +5 -0
- data/unittests/html/google_india.html +119 -0
- data/unittests/html/ie7_document_standards.html +9 -0
- data/unittests/html/ie8_document_standards.html +9 -0
- data/unittests/html/ie9_document_standards.html +9 -0
- data/unittests/html/iframe.html +3 -0
- data/unittests/html/iframeTest.html +17 -0
- data/unittests/html/iframeTest1.html +7 -0
- data/unittests/html/iframeTest2.html +5 -0
- data/unittests/html/images/1.gif +0 -0
- data/unittests/html/images/2.GIF +0 -0
- data/unittests/html/images/3.GIF +0 -0
- data/unittests/html/images/button.jpg +0 -0
- data/unittests/html/images/circle.jpg +0 -0
- data/unittests/html/images/map.GIF +0 -0
- data/unittests/html/images/map2.gif +0 -0
- data/unittests/html/images/minus.GIF +0 -0
- data/unittests/html/images/originaltriangle.jpg +0 -0
- data/unittests/html/images/plus.gif +0 -0
- data/unittests/html/images/square.jpg +0 -0
- data/unittests/html/images/triangle.jpg +0 -0
- data/unittests/html/images1.html +65 -0
- data/unittests/html/javascriptevents.html +33 -0
- data/unittests/html/link_pass.html +11 -0
- data/unittests/html/links1.html +37 -0
- data/unittests/html/links2.html +11 -0
- data/unittests/html/links_multi.html +12 -0
- data/unittests/html/list_matters.html +720 -0
- data/unittests/html/lists.html +18 -0
- data/unittests/html/map_test.html +30 -0
- data/unittests/html/modal_dialog.html +10 -0
- data/unittests/html/modal_dialog_launcher.html +12 -0
- data/unittests/html/multiple_specifiers.html +64 -0
- data/unittests/html/nestedFrames.html +6 -0
- data/unittests/html/new_browser.html +17 -0
- data/unittests/html/pass.html +13 -0
- data/unittests/html/popups1.html +59 -0
- data/unittests/html/pre.html +29 -0
- data/unittests/html/quirks_document_standards.html +8 -0
- data/unittests/html/radioButtons1.html +71 -0
- data/unittests/html/select_tealeaf.html +54 -0
- data/unittests/html/selectboxes1.html +52 -0
- data/unittests/html/simple_table.html +25 -0
- data/unittests/html/simple_table_buttons.html +104 -0
- data/unittests/html/simple_table_columns.html +75 -0
- data/unittests/html/table1.html +179 -0
- data/unittests/html/tableCell_using_xpath.html +19 -0
- data/unittests/html/table_and_tablerow_to_a.html +174 -0
- data/unittests/html/textarea.html +30 -0
- data/unittests/html/textfields1.html +100 -0
- data/unittests/html/textsearch.html +44 -0
- data/unittests/html/wallofcheckboxes.html +1003 -0
- data/unittests/html/xpath_nbsp.html +11 -0
- data/unittests/html/zeroindex.html +11 -0
- data/unittests/ie_exists_test.rb +16 -0
- data/unittests/ie_mock.rb +94 -0
- data/unittests/ie_test.rb +54 -0
- data/unittests/images_test.rb +156 -0
- data/unittests/images_xpath_test.rb +90 -0
- data/unittests/index_specifier_test.rb +31 -0
- data/unittests/js_events_test.rb +31 -0
- data/unittests/links_multi_test.rb +34 -0
- data/unittests/links_test.rb +131 -0
- data/unittests/links_xpath_test.rb +38 -0
- data/unittests/lists_test.rb +23 -0
- data/unittests/map_test.rb +98 -0
- data/unittests/minmax_test.rb +37 -0
- data/unittests/navigate_test.rb +38 -0
- data/unittests/nbsp_xpath_test.rb +16 -0
- data/unittests/no_wait_test.rb +28 -0
- data/unittests/non_core_tests.rb +12 -0
- data/unittests/other/all_tests_concurrent.rb +57 -0
- data/unittests/other/navigate_exception_test.rb +24 -0
- data/unittests/other/rexml_unit_test.rb +27 -0
- data/unittests/other/screen_capture_test.rb +53 -0
- data/unittests/other/testcase_method_order_test.rb +36 -0
- data/unittests/other/testcase_verify_test.rb +25 -0
- data/unittests/other/wait_until_test.rb +102 -0
- data/unittests/pagecontainstext_test.rb +69 -0
- data/unittests/parent_child_test.rb +27 -0
- data/unittests/perf_test.rb +20 -0
- data/unittests/pre_test.rb +49 -0
- data/unittests/radios_test.rb +181 -0
- data/unittests/radios_xpath_test.rb +100 -0
- data/unittests/security_setting_test.rb +24 -0
- data/unittests/selectbox_test.rb +144 -0
- data/unittests/selectbox_xpath_test.rb +102 -0
- data/unittests/setup.rb +69 -0
- data/unittests/speed_settings_test.rb +67 -0
- data/unittests/table_cell_using_xpath_test.rb +34 -0
- data/unittests/table_test.rb +296 -0
- data/unittests/table_xpath_test.rb +109 -0
- data/unittests/test_tests.rb +9 -0
- data/unittests/textarea_test.rb +92 -0
- data/unittests/textarea_xpath_test.rb +77 -0
- data/unittests/textfield_for_ch_char_test.rb +32 -0
- data/unittests/textfields_test.rb +184 -0
- data/unittests/textfields_xpath_test.rb +110 -0
- data/unittests/version_test.rb +15 -0
- data/unittests/win32ole_so_test.rb +35 -0
- data/unittests/window_tests.rb +10 -0
- data/unittests/windows/attach_to_existing_window_test.rb +52 -0
- data/unittests/windows/attach_to_new_window_test.rb +74 -0
- data/unittests/windows/close_window_test.rb +20 -0
- data/unittests/windows/frame_links_test.rb +23 -0
- data/unittests/windows/ie-each_test.rb +46 -0
- data/unittests/windows/modal_dialog_test.rb +95 -0
- data/unittests/windows/new_process_test.rb +24 -0
- data/unittests/windows/new_test.rb +58 -0
- data/unittests/windows/open_close_test.rb +19 -0
- data/unittests/windows/send_keys_test.rb +26 -0
- data/unittests/xpath_tests.rb +11 -0
- data/watir-rdoc.rb +7 -0
- metadata +370 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
module Watir
|
|
2
|
+
|
|
3
|
+
module TableContainer
|
|
4
|
+
# Returns a row in the table
|
|
5
|
+
# * index - the index of the row
|
|
6
|
+
def [](index)
|
|
7
|
+
assert_exists
|
|
8
|
+
TableRow.new(self, :ole_object => @o.rows.item(index))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def strings
|
|
12
|
+
assert_exists
|
|
13
|
+
rows_memo = []
|
|
14
|
+
@o.rows.each do |row|
|
|
15
|
+
cells_memo = []
|
|
16
|
+
row.cells.each do |cell|
|
|
17
|
+
cells_memo << TableCell.new(self, :ole_object => cell).text.gsub("\r\n","")
|
|
18
|
+
end
|
|
19
|
+
rows_memo << cells_memo
|
|
20
|
+
end
|
|
21
|
+
rows_memo
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
module TableElementsContainer
|
|
26
|
+
def table_elements(klass, tags, how, what, ole_collection)
|
|
27
|
+
specifiers = format_specifiers(tags, how, what)
|
|
28
|
+
klass.new(self, specifiers, ole_collection)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private :table_elements
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module TableCellsContainer
|
|
35
|
+
include TableElementsContainer
|
|
36
|
+
|
|
37
|
+
def cells(how={}, what=nil)
|
|
38
|
+
assert_exists
|
|
39
|
+
table_elements(TableCellCollection, [:th, :td], how, what, @o.cells)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def cell(how={}, what=nil)
|
|
43
|
+
specifiers = format_specifiers([:th, :td], how, what)
|
|
44
|
+
index = specifiers.delete(:index) || 0
|
|
45
|
+
cells(specifiers)[index]
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
module TableRowsContainer
|
|
50
|
+
include TableElementsContainer
|
|
51
|
+
|
|
52
|
+
def rows(how={}, what=nil)
|
|
53
|
+
assert_exists
|
|
54
|
+
table_elements(TableRowCollection, [:tr], how, what, @o.rows)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def row(how={}, what=nil)
|
|
58
|
+
specifiers = format_specifiers([:tr], how, what)
|
|
59
|
+
index = specifiers.delete(:index) || 0
|
|
60
|
+
rows(specifiers)[index]
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# This class is used for dealing with tables.
|
|
65
|
+
# Normally a user would not need to create this object as it is returned by the Watir::Container#table method
|
|
66
|
+
#
|
|
67
|
+
# many of the methods available to this object are inherited from the Element class
|
|
68
|
+
#
|
|
69
|
+
class Table < Element
|
|
70
|
+
include TableContainer
|
|
71
|
+
include TableRowsContainer
|
|
72
|
+
include TableCellsContainer
|
|
73
|
+
|
|
74
|
+
attr_ole :rules
|
|
75
|
+
|
|
76
|
+
# override the highlight method, as if the tables rows are set to have a background color,
|
|
77
|
+
# this will override the table background color, and the normal flash method won't work
|
|
78
|
+
def highlight(set_or_clear)
|
|
79
|
+
if set_or_clear == :set
|
|
80
|
+
begin
|
|
81
|
+
@original_border = @o.border.to_i
|
|
82
|
+
if @o.border.to_i==1
|
|
83
|
+
@o.border = 2
|
|
84
|
+
else
|
|
85
|
+
@o.border = 1
|
|
86
|
+
end
|
|
87
|
+
rescue
|
|
88
|
+
@original_border = nil
|
|
89
|
+
end
|
|
90
|
+
else
|
|
91
|
+
begin
|
|
92
|
+
@o.border= @original_border unless @original_border == nil
|
|
93
|
+
@original_border = nil
|
|
94
|
+
rescue
|
|
95
|
+
# we could be here for a number of reasons...
|
|
96
|
+
ensure
|
|
97
|
+
@original_border = nil
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
super
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# this method is used to populate the properties in the to_s method
|
|
104
|
+
def table_string_creator
|
|
105
|
+
n = []
|
|
106
|
+
n << "rows:".ljust(TO_S_SIZE) + self.row_count.to_s
|
|
107
|
+
n << "cols:".ljust(TO_S_SIZE) + self.column_count.to_s
|
|
108
|
+
return n
|
|
109
|
+
end
|
|
110
|
+
private :table_string_creator
|
|
111
|
+
|
|
112
|
+
# returns the properties of the object in a string
|
|
113
|
+
# raises an ObjectNotFound exception if the object cannot be found
|
|
114
|
+
def to_s
|
|
115
|
+
assert_exists
|
|
116
|
+
r = string_creator
|
|
117
|
+
r += table_string_creator
|
|
118
|
+
return r.join("\n")
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
# Returns the number of rows inside the table, including rows in nested tables.
|
|
122
|
+
def row_count
|
|
123
|
+
assert_exists
|
|
124
|
+
rows.length
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# This method returns the number of columns in a row of the table.
|
|
128
|
+
# Raises an UnknownObjectException if the table doesn't exist.
|
|
129
|
+
# * index - the index of the row
|
|
130
|
+
def column_count(index=0)
|
|
131
|
+
assert_exists
|
|
132
|
+
rows[index].cells.length
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Returns an array containing all the text values in the specified column
|
|
136
|
+
# Raises an UnknownCellException if the specified column does not exist in every
|
|
137
|
+
# Raises an UnknownObjectException if the table doesn't exist.
|
|
138
|
+
# row of the table
|
|
139
|
+
# * columnnumber - column index to extract values from
|
|
140
|
+
def column_values(columnnumber)
|
|
141
|
+
return (0..row_count - 1).collect {|i| self[i][columnnumber].text}
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Returns an array containing all the text values in the specified row
|
|
145
|
+
# Raises an UnknownObjectException if the table doesn't exist.
|
|
146
|
+
# * rownumber - row index to extract values from
|
|
147
|
+
def row_values(rownumber)
|
|
148
|
+
return (0..column_count(rownumber) - 1).collect {|i| self[rownumber][i].text}
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def hashes
|
|
152
|
+
assert_exists
|
|
153
|
+
|
|
154
|
+
headers = []
|
|
155
|
+
@o.rows.item(0).cells.each do |cell|
|
|
156
|
+
headers << TableCell.new(self, :ole_object => cell).text
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
rows_memo = []
|
|
160
|
+
i = 0
|
|
161
|
+
@o.rows.each do |row|
|
|
162
|
+
next if row.uniqueID == @o.rows.item(0).uniqueID
|
|
163
|
+
|
|
164
|
+
cells_memo = {}
|
|
165
|
+
cells = row.cells
|
|
166
|
+
raise "row at index #{i} has #{cells.length} cells, expected #{headers.length}" if cells.length < headers.length
|
|
167
|
+
|
|
168
|
+
j = 0
|
|
169
|
+
cells.each do |cell|
|
|
170
|
+
cells_memo[headers[j]] = TableCell.new(self, :ole_object => cell).text
|
|
171
|
+
j += 1
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
rows_memo << cells_memo
|
|
175
|
+
i += 1
|
|
176
|
+
end
|
|
177
|
+
rows_memo
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
class TableSection < Element
|
|
182
|
+
include TableContainer
|
|
183
|
+
include TableRowsContainer
|
|
184
|
+
include TableCellsContainer
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
class TableRow < Element
|
|
188
|
+
include TableCellsContainer
|
|
189
|
+
|
|
190
|
+
# this method iterates through each of the cells in the row. Yields a TableCell object
|
|
191
|
+
def each
|
|
192
|
+
locate
|
|
193
|
+
cells.each {|cell| yield cell}
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Returns an element from the row as a TableCell object
|
|
197
|
+
def [](index)
|
|
198
|
+
assert_exists
|
|
199
|
+
if cells.length <= index
|
|
200
|
+
raise UnknownCellException, "Unable to locate a cell at index #{index}"
|
|
201
|
+
end
|
|
202
|
+
return cells[index]
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
def column_count
|
|
206
|
+
assert_exists
|
|
207
|
+
cells.length
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# this class is a table cell - when called via the Table object
|
|
213
|
+
class TableCell < Element
|
|
214
|
+
attr_ole :headers
|
|
215
|
+
|
|
216
|
+
alias_method :to_s, :text
|
|
217
|
+
|
|
218
|
+
def colspan
|
|
219
|
+
locate
|
|
220
|
+
@o.colSpan
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
require 'test/unit'
|
|
2
|
+
require 'watir-classic/assertions'
|
|
3
|
+
|
|
4
|
+
module Watir
|
|
5
|
+
|
|
6
|
+
# This is a 'test/unit' testcase customized to exeucte test methods sequentially by default
|
|
7
|
+
# and extra assertions
|
|
8
|
+
#
|
|
9
|
+
# Example Usage
|
|
10
|
+
#
|
|
11
|
+
# require 'watir-classic/testcase'
|
|
12
|
+
#
|
|
13
|
+
# class MyTestCase < Watir::TestCase
|
|
14
|
+
#
|
|
15
|
+
# # some helpers
|
|
16
|
+
# @@browser = nil
|
|
17
|
+
# def browser
|
|
18
|
+
# @browser ||= Watir::IE.start(:url, 'http://watir.com/")
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# # TESTS
|
|
22
|
+
# def test_text
|
|
23
|
+
# browser.goto "http://watir.com/"
|
|
24
|
+
# verify_match "Web Application Testing in Ruby", browser.text
|
|
25
|
+
# end
|
|
26
|
+
#
|
|
27
|
+
# def test_title
|
|
28
|
+
# verify browser.title == 'Watir'
|
|
29
|
+
# end
|
|
30
|
+
#
|
|
31
|
+
# def test_link
|
|
32
|
+
# verify_match 'watir.com', browser.link(:text, 'Home').href
|
|
33
|
+
# end
|
|
34
|
+
#
|
|
35
|
+
# def test_navigate_to_examples
|
|
36
|
+
# browser.div(:id, 'nav').link(:text, 'Examples').click
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# def test_url
|
|
40
|
+
# verify_equal browser.url, 'http://watir.com/examples/'
|
|
41
|
+
# end
|
|
42
|
+
#
|
|
43
|
+
# end
|
|
44
|
+
#
|
|
45
|
+
class TestCase < Test::Unit::TestCase
|
|
46
|
+
include Watir::Assertions
|
|
47
|
+
@@order = :sequentially
|
|
48
|
+
def initialize name
|
|
49
|
+
throw :invalid_test if name == :default_test && self.class == Watir::TestCase
|
|
50
|
+
super
|
|
51
|
+
end
|
|
52
|
+
class << self
|
|
53
|
+
attr_accessor :test_methods, :order
|
|
54
|
+
def test_methods
|
|
55
|
+
@test_methods ||= []
|
|
56
|
+
end
|
|
57
|
+
def order
|
|
58
|
+
@order || @@order
|
|
59
|
+
end
|
|
60
|
+
def default_order= order
|
|
61
|
+
@@order = order
|
|
62
|
+
end
|
|
63
|
+
def sorted_test_methods
|
|
64
|
+
case order
|
|
65
|
+
when :alphabetically then test_methods.sort
|
|
66
|
+
when :sequentially then test_methods
|
|
67
|
+
when :reversed_sequentially then test_methods.reverse
|
|
68
|
+
when :reversed_alphabetically then test_methods.sort.reverse
|
|
69
|
+
else raise ArgumentError, "Execute option not supported: #{@order}"
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
def suite
|
|
73
|
+
suite = Test::Unit::TestSuite.new(name)
|
|
74
|
+
sorted_test_methods.each do |test|
|
|
75
|
+
catch :invalid_test do
|
|
76
|
+
suite << new(test)
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
if (suite.empty?)
|
|
80
|
+
catch :invalid_test do
|
|
81
|
+
suite << new(:default_test)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
return suite
|
|
85
|
+
end
|
|
86
|
+
def method_added id
|
|
87
|
+
name = id.id2name
|
|
88
|
+
test_methods << name if name =~ /^test./
|
|
89
|
+
end
|
|
90
|
+
def execute order
|
|
91
|
+
@order = order
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
public :add_assertion
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module Watir
|
|
2
|
+
class Util
|
|
3
|
+
class << self
|
|
4
|
+
#
|
|
5
|
+
# "Watir::Span" => "Span"
|
|
6
|
+
#
|
|
7
|
+
def demodulize(str)
|
|
8
|
+
str.gsub(/^.*::/, '')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
#
|
|
12
|
+
# "FooBar" => "foo_bar"
|
|
13
|
+
#
|
|
14
|
+
def underscore(str)
|
|
15
|
+
str.gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#
|
|
19
|
+
# "Checkboxes" => "Checkbox"
|
|
20
|
+
# "Bodies" => "Body"
|
|
21
|
+
# "Buttons" => "Button"
|
|
22
|
+
#
|
|
23
|
+
def singularize(str)
|
|
24
|
+
case str.downcase
|
|
25
|
+
when "checkboxes"
|
|
26
|
+
str.chop.chop
|
|
27
|
+
when "bodies"
|
|
28
|
+
str.chop.chop.chop + "y"
|
|
29
|
+
else
|
|
30
|
+
str.chop
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
|
|
3
|
+
module Watir
|
|
4
|
+
module Wait
|
|
5
|
+
extend self
|
|
6
|
+
|
|
7
|
+
class TimeoutError < StandardError
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
#
|
|
11
|
+
# Wait until the block evaluates to true or times out.
|
|
12
|
+
#
|
|
13
|
+
|
|
14
|
+
def until(timeout = 60, &block)
|
|
15
|
+
end_time = ::Time.now + timeout
|
|
16
|
+
|
|
17
|
+
until ::Time.now > end_time
|
|
18
|
+
result = yield(self)
|
|
19
|
+
return result if result
|
|
20
|
+
sleep 0.1
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
raise TimeoutError, "timed out after #{timeout} seconds"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# Wait while the block evaluates to true or times out.
|
|
28
|
+
#
|
|
29
|
+
def while(timeout = 60, &block)
|
|
30
|
+
end_time = ::Time.now + timeout
|
|
31
|
+
|
|
32
|
+
until ::Time.now > end_time
|
|
33
|
+
return unless yield(self)
|
|
34
|
+
sleep 0.1
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
raise TimeoutError, "timed out after #{timeout} seconds"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end # Wait
|
|
41
|
+
end # Watir
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# include this module if there's a need to have wait_until and wait_while methods in some different scope
|
|
2
|
+
module Watir
|
|
3
|
+
module WaitHelper
|
|
4
|
+
def wait_until(*args, &blk)
|
|
5
|
+
Wait.until(*args, &blk)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def wait_while(*args, &blk)
|
|
9
|
+
Wait.while(*args, &blk)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#######
|
|
2
|
+
#
|
|
3
|
+
# Using Watir::Waiter is DEPRECATED and will be removed in some newer version of Watir! Use Watir::Wait and Watir::ElementExtensions methods instead!
|
|
4
|
+
#
|
|
5
|
+
#######
|
|
6
|
+
require 'watir-classic/exceptions'
|
|
7
|
+
|
|
8
|
+
module Watir
|
|
9
|
+
|
|
10
|
+
def wait_until(*args)
|
|
11
|
+
Waiter.wait_until(*args) {yield}
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class TimeKeeper
|
|
15
|
+
attr_reader :sleep_time
|
|
16
|
+
def initialize
|
|
17
|
+
@sleep_time = 0.0
|
|
18
|
+
end
|
|
19
|
+
def sleep seconds
|
|
20
|
+
@sleep_time += Kernel.sleep seconds
|
|
21
|
+
end
|
|
22
|
+
def now
|
|
23
|
+
::Time.now
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Waiter
|
|
28
|
+
# This is an interface to a TimeKeeper which proxies
|
|
29
|
+
# calls to "sleep" and "Time.now".
|
|
30
|
+
# Useful for unit testing Waiter.
|
|
31
|
+
attr_accessor :timer
|
|
32
|
+
|
|
33
|
+
# How long to wait between each iteration through the wait_until
|
|
34
|
+
# loop. In seconds.
|
|
35
|
+
attr_accessor :polling_interval
|
|
36
|
+
|
|
37
|
+
# Timeout for wait_until.
|
|
38
|
+
attr_accessor :timeout
|
|
39
|
+
|
|
40
|
+
@@default_polling_interval = 0.5
|
|
41
|
+
@@default_timeout = 60.0
|
|
42
|
+
|
|
43
|
+
def initialize(timeout=@@default_timeout,
|
|
44
|
+
polling_interval=@@default_polling_interval)
|
|
45
|
+
Kernel.warn "Using Watir::Waiter is DEPRECATED and will be removed in some newer version of Watir! Use Watir::Wait and Watir::ElementExtensions methods instead!"
|
|
46
|
+
@timeout = timeout
|
|
47
|
+
@polling_interval = polling_interval
|
|
48
|
+
@timer = TimeKeeper.new
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Execute the provided block until either (1) it returns true, or
|
|
52
|
+
# (2) the timeout (in seconds) has been reached. If the timeout is reached,
|
|
53
|
+
# a TimeOutException will be raised. The block will always
|
|
54
|
+
# execute at least once.
|
|
55
|
+
#
|
|
56
|
+
# waiter = Waiter.new(5)
|
|
57
|
+
# waiter.wait_until {puts 'hello'}
|
|
58
|
+
#
|
|
59
|
+
# This code will print out "hello" for five seconds, and then raise a
|
|
60
|
+
# Watir::TimeOutException.
|
|
61
|
+
def wait_until # block
|
|
62
|
+
start_time = now
|
|
63
|
+
until yield do
|
|
64
|
+
if (duration = now - start_time) > @timeout
|
|
65
|
+
raise Watir::Exception::TimeOutException.new(duration, @timeout),
|
|
66
|
+
"Timed out after #{duration} seconds."
|
|
67
|
+
end
|
|
68
|
+
sleep @polling_interval
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Execute the provided block until either (1) it returns true, or
|
|
73
|
+
# (2) the timeout (in seconds) has been reached. If the timeout is reached,
|
|
74
|
+
# a TimeOutException will be raised. The block will always
|
|
75
|
+
# execute at least once.
|
|
76
|
+
#
|
|
77
|
+
# Waiter.wait_until(5) {puts 'hello'}
|
|
78
|
+
#
|
|
79
|
+
# This code will print out "hello" for five seconds, and then raise a
|
|
80
|
+
# Watir::TimeOutException.
|
|
81
|
+
|
|
82
|
+
# IDEA: wait_until: remove defaults from Waiter.wait_until
|
|
83
|
+
def self.wait_until(timeout=@@default_timeout,
|
|
84
|
+
polling_interval=@@default_polling_interval)
|
|
85
|
+
waiter = new(timeout, polling_interval)
|
|
86
|
+
waiter.wait_until { yield }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
private
|
|
90
|
+
def sleep seconds
|
|
91
|
+
@timer.sleep seconds
|
|
92
|
+
end
|
|
93
|
+
def now
|
|
94
|
+
@timer.now
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end # module
|