Class: TestCentricity::ScreenObject
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.alert(element_name, locator) ⇒ Object
-
.alerts(element_hash) ⇒ Object
-
.button(element_name, locator) ⇒ Object
-
.buttons(element_hash) ⇒ Object
-
.checkbox(element_name, locator) ⇒ Object
-
.checkboxes(element_hash) ⇒ Object
-
.element(element_name, locator) ⇒ Object
-
.elements(element_hash) ⇒ Object
-
.image(element_name, locator) ⇒ Object
-
.images(element_hash) ⇒ Object
-
.label(element_name, locator) ⇒ Object
-
.labels(element_hash) ⇒ Object
-
.list(element_name, locator) ⇒ Object
-
.lists(element_hash) ⇒ Object
-
.section(section_name, obj, locator = 0) ⇒ Object
-
.sections(section_hash) ⇒ Object
-
.selectlist(element_name, locator) ⇒ Object
-
.selectlists(element_hash) ⇒ Object
-
.switch(element_name, locator) ⇒ Object
-
.switches(element_hash) ⇒ Object
-
.textfield(element_name, locator) ⇒ Object
-
.textfields(element_hash) ⇒ Object
-
.trait(trait_name, &block) ⇒ Object
Instance Method Summary
collapse
#populate_data_fields, #verify_ui_states
Constructor Details
Returns a new instance of ScreenObject.
9
10
11
12
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 9
def initialize
raise "Screen object #{self.class.name} does not have a page_name trait defined" unless defined?(page_name)
@locator = page_locator if defined?(page_locator)
end
|
Instance Attribute Details
#locator ⇒ Object
Returns the value of attribute locator.
7
8
9
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 7
def locator
@locator
end
|
Class Method Details
.alert(element_name, locator) ⇒ Object
108
109
110
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 108
def self.alert(element_name, locator)
define_screen_element(element_name, TestCentricity::AppAlert, locator)
end
|
.alerts(element_hash) ⇒ Object
112
113
114
115
116
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 112
def self.alerts(element_hash)
element_hash.each do |element_name, locator|
alert(element_name, locator)
end
end
|
28
29
30
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 28
def self.button(element_name, locator)
define_screen_element(element_name, TestCentricity::AppButton, locator)
end
|
32
33
34
35
36
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 32
def self.buttons(element_hash)
element_hash.each do |element_name, locator|
button(element_name, locator)
end
end
|
.checkbox(element_name, locator) ⇒ Object
58
59
60
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 58
def self.checkbox(element_name, locator)
define_screen_element(element_name, TestCentricity::AppCheckBox, locator)
end
|
.checkboxes(element_hash) ⇒ Object
62
63
64
65
66
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 62
def self.checkboxes(element_hash)
element_hash.each do |element_name, locator|
checkbox(element_name, locator)
end
end
|
.element(element_name, locator) ⇒ Object
18
19
20
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 18
def self.element(element_name, locator)
define_screen_element(element_name, TestCentricity::AppUIElement, locator)
end
|
.elements(element_hash) ⇒ Object
22
23
24
25
26
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 22
def self.elements(element_hash)
element_hash.each do |element_name, locator|
element(element_name, locator)
end
end
|
.image(element_name, locator) ⇒ Object
98
99
100
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 98
def self.image(element_name, locator)
define_screen_element(element_name, TestCentricity::AppImage, locator)
end
|
.images(element_hash) ⇒ Object
102
103
104
105
106
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 102
def self.images(element_hash)
element_hash.each do |element_name, locator|
image(element_name, locator)
end
end
|
.label(element_name, locator) ⇒ Object
68
69
70
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 68
def self.label(element_name, locator)
define_screen_element(element_name, TestCentricity::AppLabel, locator)
end
|
.labels(element_hash) ⇒ Object
72
73
74
75
76
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 72
def self.labels(element_hash)
element_hash.each do |element_name, locator|
label(element_name, locator)
end
end
|
.list(element_name, locator) ⇒ Object
78
79
80
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 78
def self.list(element_name, locator)
define_screen_element(element_name, TestCentricity::AppList, locator)
end
|
.lists(element_hash) ⇒ Object
82
83
84
85
86
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 82
def self.lists(element_hash)
element_hash.each do |element_name, locator|
list(element_name, locator)
end
end
|
.section(section_name, obj, locator = 0) ⇒ Object
118
119
120
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 118
def self.section(section_name, obj, locator = 0)
define_screen_element(section_name, obj, locator)
end
|
.sections(section_hash) ⇒ Object
122
123
124
125
126
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 122
def self.sections(section_hash)
section_hash.each do |section_name, class_name|
section(section_name, class_name)
end
end
|
.selectlist(element_name, locator) ⇒ Object
88
89
90
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 88
def self.selectlist(element_name, locator)
define_screen_element(element_name, TestCentricity::AppSelectList, locator)
end
|
.selectlists(element_hash) ⇒ Object
92
93
94
95
96
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 92
def self.selectlists(element_hash)
element_hash.each do |element_name, locator|
selectlist(element_name, locator)
end
end
|
.switch(element_name, locator) ⇒ Object
48
49
50
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 48
def self.switch(element_name, locator)
define_screen_element(element_name, TestCentricity::AppSwitch, locator)
end
|
.switches(element_hash) ⇒ Object
52
53
54
55
56
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 52
def self.switches(element_hash)
element_hash.each do |element_name, locator|
switch(element_name, locator)
end
end
|
.textfield(element_name, locator) ⇒ Object
38
39
40
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 38
def self.textfield(element_name, locator)
define_screen_element(element_name, TestCentricity::AppTextField, locator)
end
|
.textfields(element_hash) ⇒ Object
42
43
44
45
46
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 42
def self.textfields(element_hash)
element_hash.each do |element_name, locator|
textfield(element_name, locator)
end
end
|
.trait(trait_name, &block) ⇒ Object
14
15
16
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 14
def self.trait(trait_name, &block)
define_method(trait_name.to_s, &block)
end
|
Instance Method Details
#exists? ⇒ Boolean
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 142
def exists?
@locator.is_a?(Array) ? tries ||= 2 : tries ||= 1
if @locator.is_a?(Array)
loc = @locator[tries - 1]
find_element(loc.keys[0], loc.values[0])
else
find_element(@locator.keys[0], @locator.values[0])
end
true
rescue
retry if (tries -= 1) > 0
false
end
|
#load_page ⇒ Object
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
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 184
def load_page
if exists?
verify_page_exists
return
end
url = if page_url.include?("://")
page_url
elsif !Environ.current.deep_link_prefix.blank?
link_url = "#{Environ.current.deep_link_prefix}://#{page_url}"
if Environ.is_android?
$driver.execute_script(
'mobile:deepLink',
{
url: link_url,
package: Environ.current.android_app_id
}
)
verify_page_exists
return
else
link_url
end
end
if Environ.is_ios? && Environ.is_device?
$driver.execute_script('mobile: launchApp', { bundleId: 'com.apple.mobilesafari' })
unless $driver.is_keyboard_shown
begin
find_element(:accessibility_id, 'TabBarItemTitle').click
rescue
find_element(:xpath, '//XCUIElementTypeButton[@name="URL"]').click
end
end
wait_for_object(:xpath, '//XCUIElementTypeTextField[@name="URL"]', 5).send_keys("#{url}\uE007")
wait_for_object(:xpath, '//XCUIElementTypeButton[@name="Open"]', 10).click
else
$driver.get(url)
end
verify_page_exists
end
|
#navigate_to ⇒ Object
180
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 180
def navigate_to; end
|
#open_portal ⇒ Object
128
129
130
131
132
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 128
def open_portal
environment = Environ.current
Environ.portal_state = :open
end
|
#verify_page_exists ⇒ Object
134
135
136
137
138
139
140
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 134
def verify_page_exists
wait = Selenium::WebDriver::Wait.new(timeout: Environ.default_max_wait_time)
wait.until { exists? }
PageManager.current_page = self
rescue
raise "Could not find page_locator for screen object '#{self.class.name}' (#{@locator}) after #{Environ.default_max_wait_time} seconds"
end
|
#verify_page_ui ⇒ Object
182
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 182
def verify_page_ui; end
|
#wait_until_exists(seconds = nil, post_exception = true) ⇒ Object
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 156
def wait_until_exists(seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { exists? }
rescue
if post_exception
raise "Screen object #{self.class.name} not found after #{timeout} seconds" unless exists?
else
exists?
end
end
|
#wait_until_gone(seconds = nil, post_exception = true) ⇒ Object
168
169
170
171
172
173
174
175
176
177
178
|
# File 'lib/testcentricity/app_core/screen_object.rb', line 168
def wait_until_gone(seconds = nil, post_exception = true)
timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
wait = Selenium::WebDriver::Wait.new(timeout: timeout)
wait.until { !exists? }
rescue
if post_exception
raise "Screen object #{self.class.name} remained visible after #{timeout} seconds" if exists?
else
exists?
end
end
|