testcentricity_web 4.3.1 → 4.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -12
- data/LICENSE.md +1 -1
- data/README.md +1794 -697
- data/lib/devices/devices.yml +144 -216
- data/lib/testcentricity_web/browser_helper.rb +33 -4
- data/lib/testcentricity_web/data_objects/environment.rb +96 -13
- data/lib/testcentricity_web/exception_queue_helper.rb +5 -6
- data/lib/testcentricity_web/version.rb +1 -1
- data/lib/testcentricity_web/web_core/page_object.rb +53 -49
- data/lib/testcentricity_web/web_core/page_objects_helper.rb +20 -11
- data/lib/testcentricity_web/web_core/page_section.rb +31 -34
- data/lib/testcentricity_web/web_core/webdriver_helper.rb +379 -252
- data/lib/testcentricity_web/web_elements/audio.rb +6 -4
- data/lib/testcentricity_web/web_elements/button.rb +7 -4
- data/lib/testcentricity_web/web_elements/checkbox.rb +149 -147
- data/lib/testcentricity_web/web_elements/file_field.rb +38 -36
- data/lib/testcentricity_web/web_elements/image.rb +75 -70
- data/lib/testcentricity_web/web_elements/label.rb +6 -4
- data/lib/testcentricity_web/web_elements/link.rb +15 -13
- data/lib/testcentricity_web/web_elements/list.rb +171 -169
- data/lib/testcentricity_web/web_elements/media.rb +384 -379
- data/lib/testcentricity_web/web_elements/radio.rb +135 -133
- data/lib/testcentricity_web/web_elements/range.rb +16 -29
- data/lib/testcentricity_web/web_elements/select_list.rb +247 -245
- data/lib/testcentricity_web/web_elements/table.rb +575 -573
- data/lib/testcentricity_web/web_elements/textfield.rb +143 -139
- data/lib/testcentricity_web/web_elements/ui_element.rb +1171 -0
- data/lib/testcentricity_web/web_elements/video.rb +39 -37
- data/lib/testcentricity_web/world_extensions.rb +37 -4
- data/lib/testcentricity_web.rb +4 -23
- metadata +27 -79
- data/lib/testcentricity_web/web_elements/ui_elements_helper.rb +0 -1148
@@ -1,195 +1,197 @@
|
|
1
1
|
module TestCentricity
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
2
|
+
module Elements
|
3
|
+
class List < UIElement
|
4
|
+
attr_accessor :list_item
|
5
|
+
attr_accessor :selected_item
|
6
|
+
|
7
|
+
def initialize(name, parent, locator, context)
|
8
|
+
super
|
9
|
+
@type = :list
|
10
|
+
list_spec = {
|
11
|
+
selected_item: 'li.selected',
|
12
|
+
list_item: 'li'
|
13
|
+
}
|
14
|
+
define_list_elements(list_spec)
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
17
|
+
def define_list_elements(element_spec)
|
18
|
+
element_spec.each do |element, value|
|
19
|
+
case element
|
20
|
+
when :list_item
|
21
|
+
@list_item = value
|
22
|
+
when :selected_item
|
23
|
+
@selected_item = value
|
24
|
+
else
|
25
|
+
raise "#{element} is not a recognized list element"
|
26
|
+
end
|
25
27
|
end
|
26
28
|
end
|
27
|
-
end
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
30
|
+
# Select the specified item in a list object. Accepts a String or Integer.
|
31
|
+
#
|
32
|
+
# @param item [String, Integer] text or index of item to select
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
# province_list.choose_item(2)
|
36
|
+
# province_list.choose_item('Manitoba')
|
37
|
+
#
|
38
|
+
def choose_item(item)
|
39
|
+
obj, = find_element
|
40
|
+
object_not_found_exception(obj, nil)
|
41
|
+
if item.is_a?(Integer)
|
42
|
+
obj.find(:css, "#{@list_item}:nth-of-type(#{item})", visible: true, wait: 2).click
|
43
|
+
elsif item.is_a?(String)
|
44
|
+
items = obj.all(@list_item).collect(&:text)
|
45
|
+
sleep(2) unless items.include?(item)
|
46
|
+
obj.first(:css, @list_item, text: item).click
|
47
|
+
end
|
46
48
|
end
|
47
|
-
end
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
50
|
+
# Hover over the specified item in a list object. Accepts a String or Integer.
|
51
|
+
#
|
52
|
+
# @param item [String, Integer] text or index of item to hover over
|
53
|
+
# @example
|
54
|
+
# province_list.hover_item(2)
|
55
|
+
# province_list.hover_item('Manitoba')
|
56
|
+
#
|
57
|
+
def hover_item(item)
|
58
|
+
obj, = find_element
|
59
|
+
object_not_found_exception(obj, nil)
|
60
|
+
if item.is_a?(Integer)
|
61
|
+
obj.find(:css, "#{@list_item}:nth-of-type(#{item})", visible: true, wait: 2).hover
|
62
|
+
elsif item.is_a?(String)
|
63
|
+
items = obj.all(@list_item).collect(&:text)
|
64
|
+
sleep(2) unless items.include?(item)
|
65
|
+
obj.first(:css, @list_item, text: item, wait: 2).hover
|
66
|
+
end
|
65
67
|
end
|
66
|
-
end
|
67
68
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
69
|
+
# Return array of strings of all items in a list object.
|
70
|
+
#
|
71
|
+
# @return [Array]
|
72
|
+
# @example
|
73
|
+
# nav_items = nav_list.get_options
|
74
|
+
#
|
75
|
+
def get_list_items(element_spec = nil)
|
76
|
+
define_list_elements(element_spec) unless element_spec.nil?
|
77
|
+
obj, = find_element
|
78
|
+
object_not_found_exception(obj, nil)
|
79
|
+
items = obj.all(@list_item, visible: true, minimum: 0, wait: 2).collect(&:text)
|
80
|
+
|
81
|
+
items.map!{ |item| item.delete("\n") }
|
82
|
+
items.map!{ |item| item.delete("\r") }
|
83
|
+
items.map!{ |item| item.delete("\t") }
|
84
|
+
items.map!{ |item| item.strip }
|
85
|
+
end
|
85
86
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
87
|
+
def get_list_item(index, visible = true)
|
88
|
+
items = visible ? get_list_items : get_all_list_items
|
89
|
+
item = items[index - 1]
|
90
|
+
item.delete!("\n")
|
91
|
+
item.delete!("\r")
|
92
|
+
item.delete!("\t")
|
93
|
+
item.strip!
|
94
|
+
end
|
94
95
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
96
|
+
# Return the number of items in a list object.
|
97
|
+
#
|
98
|
+
# @return [Integer]
|
99
|
+
# @example
|
100
|
+
# num_nav_items = nav_list.get_item_count
|
101
|
+
#
|
102
|
+
def get_item_count
|
103
|
+
obj, = find_element
|
104
|
+
object_not_found_exception(obj, nil)
|
105
|
+
obj.all(@list_item, visible: true, minimum: 0, wait: 2).count
|
106
|
+
end
|
106
107
|
|
107
|
-
|
108
|
+
alias item_count get_item_count
|
108
109
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
110
|
+
def get_all_list_items(element_spec = nil)
|
111
|
+
define_list_elements(element_spec) unless element_spec.nil?
|
112
|
+
obj, = find_element
|
113
|
+
object_not_found_exception(obj, nil)
|
114
|
+
obj.all(@list_item, visible: :all).collect(&:text)
|
115
|
+
end
|
115
116
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
117
|
+
def get_all_items_count
|
118
|
+
obj, = find_element
|
119
|
+
object_not_found_exception(obj, nil)
|
120
|
+
obj.all(@list_item, visible: :all).count
|
121
|
+
end
|
121
122
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
123
|
+
# Return text of first selected item in a list object.
|
124
|
+
#
|
125
|
+
# @return [String]
|
126
|
+
# @example
|
127
|
+
# current_selection = nav_list.get_selected_item
|
128
|
+
#
|
129
|
+
def get_selected_item
|
130
|
+
obj, = find_element
|
131
|
+
object_not_found_exception(obj, nil)
|
132
|
+
obj.first(:css, @list_item, minimum: 0) ? obj.first(:css, @selected_item).text : nil
|
133
|
+
end
|
133
134
|
|
134
|
-
|
135
|
+
alias selected? get_selected_item
|
135
136
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
137
|
+
def verify_list_items(expected, enqueue = false)
|
138
|
+
actual = get_list_items
|
139
|
+
if enqueue
|
140
|
+
ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list #{object_ref_message}")
|
141
|
+
else
|
142
|
+
assert_equal(expected, actual, "Expected list #{object_ref_message} to be #{expected} but found #{actual}")
|
143
|
+
end
|
142
144
|
end
|
143
|
-
end
|
144
145
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
146
|
+
def get_list_row_locator(row)
|
147
|
+
case @locator_type
|
148
|
+
when :xpath
|
149
|
+
"#{@locator}/#{@list_item}[#{row}]"
|
150
|
+
when :css
|
151
|
+
"#{@locator} > #{@list_item}:nth-of-type(#{row})"
|
152
|
+
end
|
151
153
|
end
|
152
|
-
end
|
153
154
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
155
|
+
# Wait until the list's item count equals the specified value, or until the specified wait time has expired. If the wait
|
156
|
+
# time is nil, then the wait time will be Capybara.default_max_wait_time.
|
157
|
+
#
|
158
|
+
# @param value [Integer or Hash] value expected or comparison hash
|
159
|
+
# @param seconds [Integer or Float] wait time in seconds
|
160
|
+
# @example
|
161
|
+
# search_results_list.wait_until_item_count_is(10, 15)
|
162
|
+
# or
|
163
|
+
# search_results_list.wait_until_item_count_is({ greater_than_or_equal: 1 }, 5)
|
164
|
+
#
|
165
|
+
def wait_until_item_count_is(value, seconds = nil, post_exception = true)
|
166
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
167
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
168
|
+
wait.until { compare(value, get_item_count) }
|
169
|
+
rescue
|
170
|
+
if post_exception
|
171
|
+
raise "Value of List #{object_ref_message} failed to equal '#{value}' after #{timeout} seconds" unless get_item_count == value
|
172
|
+
else
|
173
|
+
get_item_count == value
|
174
|
+
end
|
173
175
|
end
|
174
|
-
end
|
175
176
|
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
177
|
+
# Wait until the list's item count changes to a different value, or until the specified wait time has expired. If the
|
178
|
+
# wait time is nil, then the wait time will be Capybara.default_max_wait_time.
|
179
|
+
#
|
180
|
+
# @param seconds [Integer or Float] wait time in seconds
|
181
|
+
# @example
|
182
|
+
# search_results_list.wait_until_value_changes(5)
|
183
|
+
#
|
184
|
+
def wait_until_item_count_changes(seconds = nil, post_exception = true)
|
185
|
+
value = get_item_count
|
186
|
+
timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds
|
187
|
+
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
|
188
|
+
wait.until { get_item_count != value }
|
189
|
+
rescue
|
190
|
+
if post_exception
|
191
|
+
raise "Value of List #{object_ref_message} failed to change from '#{value}' after #{timeout} seconds" if get_item_count == value
|
192
|
+
else
|
193
|
+
get_item_count == value
|
194
|
+
end
|
193
195
|
end
|
194
196
|
end
|
195
197
|
end
|