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
def self.alert(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppAlert.new(“#element_name”, self, ##locator, :page);end)) end.
-
.button(element_name, locator) ⇒ Object
def self.button(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppButton.new(“#element_name”, self, ##locator, :section);end)) end.
- .buttons(element_hash) ⇒ Object
-
.checkbox(element_name, locator) ⇒ Object
def self.checkbox(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppCheckBox.new(“#element_name”, self, ##locator, :section);end)) end.
- .checkboxes(element_hash) ⇒ Object
-
.element(element_name, locator) ⇒ Object
def self.element(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppUIElement.new(“#element_name”, self, ##locator, :section);end)) end.
- .elements(element_hash) ⇒ Object
-
.image(element_name, locator) ⇒ Object
def self.image(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppImage.new(“#element_name”, self, ##locator, :section);end)) end.
- .images(element_hash) ⇒ Object
-
.label(element_name, locator) ⇒ Object
def self.label(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppLabel.new(“#element_name”, self, ##locator, :section);end)) end.
- .labels(element_hash) ⇒ Object
-
.list(element_name, locator) ⇒ Object
def self.list(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppList.new(“#element_name”, self, ##locator, :section);end)) end.
- .lists(element_hash) ⇒ Object
- .section(section_name, class_name, locator = 0) ⇒ Object
- .sections(section_hash) ⇒ Object
-
.selectlist(element_name, locator) ⇒ Object
def self.selectlist(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppSelectList.new(“#element_name”, self, ##locator, :section);end)) end.
- .selectlists(element_hash) ⇒ Object
-
.switch(element_name, locator) ⇒ Object
def self.switch(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppSwitch.new(“#element_name”, self, ##locator, :section);end)) end.
- .switches(element_hash) ⇒ Object
-
.textfield(element_name, locator) ⇒ Object
def self.textfield(element_name, locator) class_eval(%(def #element_name;@#element_name ||= TestCentricity::AppTextField.new(“#element_name”, self, ##locator, :section);end)) end.
- .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
def self.alert(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppAlert.new("#{element_name}", self, #{locator}, :page);end))
end
258 259 260 261 262 263 264 265 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 258 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
def self.button(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppButton.new("#{element_name}", self, #{locator}, :section);end))
end
106 107 108 109 110 111 112 113 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 106 def self.(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::AppButton.new(element_name, self, locator, :section)) end end |
.buttons(element_hash) ⇒ Object
115 116 117 118 119 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 115 def self.(element_hash) element_hash.each do |element_name, locator| (element_name, locator) end end |
.checkbox(element_name, locator) ⇒ Object
def self.checkbox(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppCheckBox.new("#{element_name}", self, #{locator}, :section);end))
end
163 164 165 166 167 168 169 170 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 163 def self.checkbox(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::AppCheckBox.new(element_name, self, locator, :section)) end end |
.checkboxes(element_hash) ⇒ Object
172 173 174 175 176 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 172 def self.checkboxes(element_hash) element_hash.each do |element_name, locator| checkbox(element_name, locator) end end |
.element(element_name, locator) ⇒ Object
def self.element(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppUIElement.new("#{element_name}", self, #{locator}, :section);end))
end
87 88 89 90 91 92 93 94 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 87 def self.element(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::AppUIElement.new(element_name, self, locator, :section)) end end |
.elements(element_hash) ⇒ Object
96 97 98 99 100 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 96 def self.elements(element_hash) element_hash.each do |element_name, locator| element(element_name, locator) end end |
.image(element_name, locator) ⇒ Object
def self.image(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppImage.new("#{element_name}", self, #{locator}, :section);end))
end
239 240 241 242 243 244 245 246 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 239 def self.image(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::AppImage.new(element_name, self, locator, :section)) end end |
.images(element_hash) ⇒ Object
248 249 250 251 252 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 248 def self.images(element_hash) element_hash.each do |element_name, locator| image(element_name, locator) end end |
.label(element_name, locator) ⇒ Object
def self.label(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppLabel.new("#{element_name}", self, #{locator}, :section);end))
end
182 183 184 185 186 187 188 189 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 182 def self.label(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::AppLabel.new(element_name, self, locator, :section)) end end |
.labels(element_hash) ⇒ Object
191 192 193 194 195 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 191 def self.labels(element_hash) element_hash.each do |element_name, locator| label(element_name, locator) end end |
.list(element_name, locator) ⇒ Object
def self.list(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppList.new("#{element_name}", self, #{locator}, :section);end))
end
201 202 203 204 205 206 207 208 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 201 def self.list(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::AppList.new(element_name, self, locator, :section)) end end |
.lists(element_hash) ⇒ Object
210 211 212 213 214 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 210 def self.lists(element_hash) element_hash.each do |element_name, locator| list(element_name, locator) end end |
.section(section_name, class_name, locator = 0) ⇒ Object
267 268 269 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 267 def self.section(section_name, class_name, locator = 0) class_eval(%(def #{section_name};@#{section_name} ||= #{class_name}.new("#{section_name}", self, #{locator}, :section);end)) end |
.sections(section_hash) ⇒ Object
271 272 273 274 275 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 271 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
def self.selectlist(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppSelectList.new("#{element_name}", self, #{locator}, :section);end))
end
220 221 222 223 224 225 226 227 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 220 def self.selectlist(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::AppSelectList.new(element_name, self, locator, :section)) end end |
.selectlists(element_hash) ⇒ Object
229 230 231 232 233 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 229 def self.selectlists(element_hash) element_hash.each do |element_name, locator| selectlist(element_name, locator) end end |
.switch(element_name, locator) ⇒ Object
def self.switch(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppSwitch.new("#{element_name}", self, #{locator}, :section);end))
end
144 145 146 147 148 149 150 151 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 144 def self.switch(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::AppSwitch.new(element_name, self, locator, :section)) end end |
.switches(element_hash) ⇒ Object
153 154 155 156 157 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 153 def self.switches(element_hash) element_hash.each do |element_name, locator| switch(element_name, locator) end end |
.textfield(element_name, locator) ⇒ Object
def self.textfield(element_name, locator)
class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppTextField.new("#{element_name}", self, #{locator}, :section);end))
end
125 126 127 128 129 130 131 132 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 125 def self.textfield(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::AppTextField.new(element_name, self, locator, :section)) end end |
.textfields(element_hash) ⇒ Object
134 135 136 137 138 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 134 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
278 279 280 281 282 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 278 def click section = find_section section_not_found_exception(section) section.click end |
#disabled? ⇒ Boolean
313 314 315 316 317 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 313 def disabled? section = find_section section_not_found_exception(section) section.enabled? end |
#double_tap ⇒ Object
293 294 295 296 297 298 299 300 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 293 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
307 308 309 310 311 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 307 def enabled? section = find_section section_not_found_exception(section) section.enabled? end |
#exists? ⇒ Boolean
302 303 304 305 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 302 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
370 371 372 373 374 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 370 def height section = find_section section_not_found_exception(section) section.size.height end |
#hidden? ⇒ Boolean
327 328 329 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 327 def hidden? !visible? end |
#populate_data_fields(data, wait_time = nil) ⇒ Object
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 447 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
284 285 286 287 288 289 290 291 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 284 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
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 389 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
319 320 321 322 323 324 325 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 319 def visible? if exists? section.displayed? else false end end |
#wait_until_exists(seconds = nil) ⇒ Object
331 332 333 334 335 336 337 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 331 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
339 340 341 342 343 344 345 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 339 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
355 356 357 358 359 360 361 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 355 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
347 348 349 350 351 352 353 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 347 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
364 365 366 367 368 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 364 def width section = find_section section_not_found_exception(section) section.size.width end |
#x_loc ⇒ Object
376 377 378 379 380 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 376 def x_loc section = find_section section_not_found_exception(section) section.location.x end |
#y_loc ⇒ Object
382 383 384 385 386 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 382 def y_loc section = find_section section_not_found_exception(section) section.location.y end |