Class: TestCentricity::ScreenSection
- Includes:
- Test::Unit::Assertions
- Defined in:
- lib/testcentricity/app_core/screen_sections_helper.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#list_index ⇒ Object
Returns the value of attribute list_index.
-
#locator ⇒ Object
Returns the value of attribute locator.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#parent_list ⇒ Object
Returns the value of attribute parent_list.
Class Method Summary collapse
- .alert(element_name, locator) ⇒ 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
- #click ⇒ Object
- #disabled? ⇒ Boolean
- #double_tap ⇒ Object
- #enabled? ⇒ Boolean
- #exists? ⇒ Boolean
- #get_item_count ⇒ Object
- #get_list_items ⇒ Object
- #get_locator ⇒ Object
- #get_name ⇒ Object
- #get_object_type ⇒ Object
- #height ⇒ Object
- #hidden? ⇒ Boolean
-
#initialize(name, parent, locator, context) ⇒ ScreenSection
constructor
A new instance of ScreenSection.
- #populate_data_fields(data, wait_time = nil) ⇒ Object
- #set_list_index(list, index = 1) ⇒ Object
- #set_parent(parent) ⇒ Object
- #tap ⇒ Object
- #verify_ui_states(ui_states) ⇒ Object
- #visible? ⇒ Boolean
- #wait_until_exists(seconds = nil) ⇒ Object
- #wait_until_gone(seconds = nil) ⇒ Object
- #wait_until_hidden(seconds = nil) ⇒ Object
- #wait_until_visible(seconds = nil) ⇒ Object
- #width ⇒ Object
- #x_loc ⇒ Object
- #y_loc ⇒ Object
Constructor Details
#initialize(name, parent, locator, context) ⇒ ScreenSection
Returns a new instance of ScreenSection.
13 14 15 16 17 18 19 20 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 13 def initialize(name, parent, locator, context) @name = name @parent = parent @locator = locator @context = context @parent_list = nil @list_index = nil end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 7 def context @context end |
#list_index ⇒ Object
Returns the value of attribute list_index.
11 12 13 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 11 def list_index @list_index end |
#locator ⇒ Object
Returns the value of attribute locator.
8 9 10 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 8 def locator @locator end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 7 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 9 def parent @parent end |
#parent_list ⇒ Object
Returns the value of attribute parent_list.
10 11 12 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 10 def parent_list @parent_list end |
Class Method Details
.alert(element_name, locator) ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 173 def self.alert(element_name, locator) define_method(element_name) do ivar_name = "@#{element_name}" ivar = instance_variable_get(ivar_name) return ivar if ivar instance_variable_set(ivar_name, TestCentricity::AppAlert.new(element_name, self, locator, :page)) end end |
.button(element_name, locator) ⇒ Object
93 94 95 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 93 def self.(element_name, locator) define_element(element_name, TestCentricity::AppButton, locator) end |
.buttons(element_hash) ⇒ Object
97 98 99 100 101 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 97 def self.(element_hash) element_hash.each do |element_name, locator| (element_name, locator) end end |
.checkbox(element_name, locator) ⇒ Object
123 124 125 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 123 def self.checkbox(element_name, locator) define_element(element_name, TestCentricity::AppCheckBox, locator) end |
.checkboxes(element_hash) ⇒ Object
127 128 129 130 131 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 127 def self.checkboxes(element_hash) element_hash.each do |element_name, locator| checkbox(element_name, locator) end end |
.element(element_name, locator) ⇒ Object
83 84 85 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 83 def self.element(element_name, locator) define_element(element_name, TestCentricity::AppUIElement, locator) end |
.elements(element_hash) ⇒ Object
87 88 89 90 91 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 87 def self.elements(element_hash) element_hash.each do |element_name, locator| element(element_name, locator) end end |
.image(element_name, locator) ⇒ Object
163 164 165 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 163 def self.image(element_name, locator) define_element(element_name, TestCentricity::AppImage, locator) end |
.images(element_hash) ⇒ Object
167 168 169 170 171 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 167 def self.images(element_hash) element_hash.each do |element_name, locator| image(element_name, locator) end end |
.label(element_name, locator) ⇒ Object
133 134 135 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 133 def self.label(element_name, locator) define_element(element_name, TestCentricity::AppLabel, locator) end |
.labels(element_hash) ⇒ Object
137 138 139 140 141 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 137 def self.labels(element_hash) element_hash.each do |element_name, locator| label(element_name, locator) end end |
.list(element_name, locator) ⇒ Object
143 144 145 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 143 def self.list(element_name, locator) define_element(element_name, TestCentricity::AppList, locator) end |
.lists(element_hash) ⇒ Object
147 148 149 150 151 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 147 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
182 183 184 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 182 def self.section(section_name, obj, locator = 0) define_element(section_name, obj, locator) end |
.sections(section_hash) ⇒ Object
186 187 188 189 190 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 186 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
153 154 155 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 153 def self.selectlist(element_name, locator) define_element(element_name, TestCentricity::AppSelectList, locator) end |
.selectlists(element_hash) ⇒ Object
157 158 159 160 161 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 157 def self.selectlists(element_hash) element_hash.each do |element_name, locator| selectlist(element_name, locator) end end |
.switch(element_name, locator) ⇒ Object
113 114 115 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 113 def self.switch(element_name, locator) define_element(element_name, TestCentricity::AppSwitch, locator) end |
.switches(element_hash) ⇒ Object
117 118 119 120 121 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 117 def self.switches(element_hash) element_hash.each do |element_name, locator| switch(element_name, locator) end end |
.textfield(element_name, locator) ⇒ Object
103 104 105 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 103 def self.textfield(element_name, locator) define_element(element_name, TestCentricity::AppTextField, locator) end |
.textfields(element_hash) ⇒ Object
107 108 109 110 111 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 107 def self.textfields(element_hash) element_hash.each do |element_name, locator| textfield(element_name, locator) end end |
.trait(trait_name, &block) ⇒ Object
79 80 81 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 79 def self.trait(trait_name, &block) define_method(trait_name.to_s, &block) end |
Instance Method Details
#click ⇒ Object
193 194 195 196 197 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 193 def click section = find_section section_not_found_exception(section) section.click end |
#disabled? ⇒ Boolean
228 229 230 231 232 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 228 def disabled? section = find_section section_not_found_exception(section) section.enabled? end |
#double_tap ⇒ Object
208 209 210 211 212 213 214 215 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 208 def double_tap section = find_section section_not_found_exception(section) x = section.location.x y = section.location.y tap_action = Appium::TouchAction.new.double_tap(element: section, x: x, y: y) tap_action.perform end |
#enabled? ⇒ Boolean
222 223 224 225 226 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 222 def enabled? section = find_section section_not_found_exception(section) section.enabled? end |
#exists? ⇒ Boolean
217 218 219 220 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 217 def exists? section = find_section section != nil end |
#get_item_count ⇒ Object
53 54 55 56 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 53 def get_item_count raise 'No parent list defined' if @parent_list.nil? @parent_list.get_item_count end |
#get_list_items ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 58 def get_list_items items = [] (1..get_item_count).each do |item| set_list_index(nil, item) items.push(get_value) end items end |
#get_locator ⇒ Object
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 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 22 def get_locator if @locator.zero? && defined?(section_locator) my_locator = section_locator else my_locator = @locator end locators = [] if @context == :section && !@parent.nil? locators.push(@parent.get_locator) end if @parent_list.nil? locators.push(my_locator) else locators.push(@parent_list.get_locator) if @list_index.nil? locators.push(my_locator) else list_key = my_locator.keys[0] list_value = "#{my_locator.values[0]}[#{@list_index}]" locators.push( { list_key => list_value } ) end end locators end |
#get_name ⇒ Object
71 72 73 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 71 def get_name @name end |
#get_object_type ⇒ Object
67 68 69 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 67 def get_object_type :section end |
#height ⇒ Object
285 286 287 288 289 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 285 def height section = find_section section_not_found_exception(section) section.size.height end |
#hidden? ⇒ Boolean
242 243 244 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 242 def hidden? !visible? end |
#populate_data_fields(data, wait_time = nil) ⇒ Object
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 362 def populate_data_fields(data, wait_time = nil) timeout = wait_time.nil? ? 5 : wait_time data.each do |data_field, data_param| unless data_param.blank? # make sure the intended UI target element is visible before trying to set its value data_field.wait_until_visible(timeout) if data_param == '!DELETE' data_field.clear else case data_field.get_object_type when :checkbox data_field.set_checkbox_state(data_param.to_bool) when :textfield data_field.clear data_field.set("#{data_param}\t") end end end end end |
#set_list_index(list, index = 1) ⇒ Object
48 49 50 51 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 48 def set_list_index(list, index = 1) @parent_list = list unless list.nil? @list_index = index end |
#set_parent(parent) ⇒ Object
75 76 77 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 75 def set_parent(parent) @parent = parent end |
#tap ⇒ Object
199 200 201 202 203 204 205 206 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 199 def tap section = find_section section_not_found_exception(section) x = section.location.x y = section.location.y tap_action = Appium::TouchAction.new.tap(element: section, x: x, y: y) tap_action.perform end |
#verify_ui_states(ui_states) ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 304 def verify_ui_states(ui_states) ui_states.each do |ui_object, object_states| object_states.each do |property, state| puts "#{ui_object.get_name} - #{property} = #{state}" if ENV['DEBUG'] case property when :class actual = ui_object.get_attribute(:class) when :exists actual = ui_object.exists? when :enabled actual = ui_object.enabled? when :disabled actual = ui_object.disabled? when :visible actual = ui_object.visible? when :hidden actual = ui_object.hidden? when :checked actual = ui_object.checked? when :selected actual = ui_object.selected? when :value actual = ui_object.get_value when :caption actual = ui_object.get_caption when :name actual = ui_object.tag_name when :placeholder actual = ui_object.get_placeholder when :readonly actual = ui_object.read_only? when :maxlength actual = ui_object.get_max_length when :items actual = ui_object.get_list_items when :itemcount actual = ui_object.get_item_count when :width actual = ui_object.width when :height actual = ui_object.height when :x actual = ui_object.x_loc when :y actual = ui_object.y_loc end error_msg = "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) #{property} property to" ExceptionQueue.enqueue_comparison(state, actual, error_msg) end end rescue ObjectNotFoundError => e ExceptionQueue.enqueue_exception(e.) ensure ExceptionQueue.post_exceptions end |
#visible? ⇒ Boolean
234 235 236 237 238 239 240 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 234 def visible? if exists? section.displayed? else false end end |
#wait_until_exists(seconds = nil) ⇒ Object
246 247 248 249 250 251 252 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 246 def wait_until_exists(seconds = nil) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { exists? } rescue raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless exists? end |
#wait_until_gone(seconds = nil) ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 254 def wait_until_gone(seconds = nil) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { !exists? } rescue raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if exists? end |
#wait_until_hidden(seconds = nil) ⇒ Object
270 271 272 273 274 275 276 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 270 def wait_until_hidden(seconds = nil) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { hidden? } rescue raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if visible? end |
#wait_until_visible(seconds = nil) ⇒ Object
262 263 264 265 266 267 268 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 262 def wait_until_visible(seconds = nil) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { visible? } rescue raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless visible? end |
#width ⇒ Object
279 280 281 282 283 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 279 def width section = find_section section_not_found_exception(section) section.size.width end |
#x_loc ⇒ Object
291 292 293 294 295 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 291 def x_loc section = find_section section_not_found_exception(section) section.location.x end |
#y_loc ⇒ Object
297 298 299 300 301 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 297 def y_loc section = find_section section_not_found_exception(section) section.location.y end |