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, class_name) ⇒ 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, 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, 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, context) @name = name @parent = parent @context = context @parent_list = nil @list_index = nil @locator = 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
169 170 171 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 169 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
89 90 91 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 89 def self.(element_name, locator) class_eval(%(def #{element_name};@#{element_name} ||= TestCentricity::AppButton.new("#{element_name}", self, #{locator}, :section);end)) end |
.buttons(element_hash) ⇒ Object
93 94 95 96 97 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 93 def self.(element_hash) element_hash.each do |element_name, locator| (element_name, locator) end end |
.checkbox(element_name, locator) ⇒ Object
119 120 121 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 119 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
123 124 125 126 127 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 123 def self.checkboxes(element_hash) element_hash.each do |element_name, locator| checkbox(element_name, locator) end end |
.element(element_name, locator) ⇒ Object
79 80 81 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 79 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
83 84 85 86 87 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 83 def self.elements(element_hash) element_hash.each do |element_name, locator| element(element_name, locator) end end |
.image(element_name, locator) ⇒ Object
159 160 161 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 159 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
163 164 165 166 167 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 163 def self.images(element_hash) element_hash.each do |element_name, locator| image(element_name, locator) end end |
.label(element_name, locator) ⇒ Object
129 130 131 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 129 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
133 134 135 136 137 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 133 def self.labels(element_hash) element_hash.each do |element_name, locator| label(element_name, locator) end end |
.list(element_name, locator) ⇒ Object
139 140 141 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 139 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
143 144 145 146 147 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 143 def self.lists(element_hash) element_hash.each do |element_name, locator| list(element_name, locator) end end |
.section(section_name, class_name) ⇒ Object
173 174 175 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 173 def self.section(section_name, class_name) class_eval(%(def #{section_name};@#{section_name} ||= #{class_name}.new("#{section_name}", self, :section);end)) end |
.sections(section_hash) ⇒ Object
177 178 179 180 181 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 177 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
149 150 151 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 149 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
153 154 155 156 157 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 153 def self.selectlists(element_hash) element_hash.each do |element_name, locator| selectlist(element_name, locator) end end |
.switch(element_name, locator) ⇒ Object
109 110 111 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 109 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
113 114 115 116 117 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 113 def self.switches(element_hash) element_hash.each do |element_name, locator| switch(element_name, locator) end end |
.textfield(element_name, locator) ⇒ Object
99 100 101 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 99 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
103 104 105 106 107 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 103 def self.textfields(element_hash) element_hash.each do |element_name, locator| textfield(element_name, locator) end end |
.trait(trait_name, &block) ⇒ Object
75 76 77 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 75 def self.trait(trait_name, &block) define_method(trait_name.to_s, &block) end |
Instance Method Details
#click ⇒ Object
184 185 186 187 188 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 184 def click section = find_section section_not_found_exception(section) section.click end |
#disabled? ⇒ Boolean
219 220 221 222 223 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 219 def disabled? section = find_section section_not_found_exception(section) section.enabled? end |
#double_tap ⇒ Object
199 200 201 202 203 204 205 206 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 199 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
213 214 215 216 217 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 213 def enabled? section = find_section section_not_found_exception(section) section.enabled? end |
#exists? ⇒ Boolean
208 209 210 211 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 208 def exists? section = find_section section != nil end |
#get_item_count ⇒ Object
49 50 51 52 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 49 def get_item_count raise 'No parent list defined' if @parent_list.nil? @parent_list.get_item_count end |
#get_list_items ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 54 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 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 22 def get_locator @locator = section_locator locators = [] if @context == :section && !@parent.nil? locators.push(@parent.get_locator) end if @parent_list.nil? locators.push(@locator) else locators.push(@parent_list.get_locator) if @list_index.nil? locators.push(@locator) else list_key = @locator.keys[0] list_value = "#{@locator.values[0]}[#{@list_index}]" locators.push( { list_key => list_value } ) end end locators end |
#get_name ⇒ Object
67 68 69 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 67 def get_name @name end |
#get_object_type ⇒ Object
63 64 65 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 63 def get_object_type :section end |
#height ⇒ Object
277 278 279 280 281 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 277 def height section = find_section section_not_found_exception(section) section.size.height end |
#hidden? ⇒ Boolean
233 234 235 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 233 def hidden? !visible? end |
#populate_data_fields(data, wait_time = nil) ⇒ Object
395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 395 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.set("#{data_param}\t") end end end end end |
#set_list_index(list, index = 1) ⇒ Object
44 45 46 47 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 44 def set_list_index(list, index = 1) @parent_list = list unless list.nil? @list_index = index end |
#set_parent(parent) ⇒ Object
71 72 73 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 71 def set_parent(parent) @parent = parent end |
#tap ⇒ Object
190 191 192 193 194 195 196 197 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 190 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
298 299 300 301 302 303 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 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 298 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 :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 if state.is_a?(Hash) && state.length == 1 error_msg = "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) #{property} property to" state.each do |key, value| case key when :lt, :less_than ExceptionQueue.enqueue_exception("#{error_msg} be less than #{value} but found '#{actual}'") unless actual < value when :lt_eq, :less_than_or_equal ExceptionQueue.enqueue_exception("#{error_msg} be less than or equal to #{value} but found '#{actual}'") unless actual <= value when :gt, :greater_than ExceptionQueue.enqueue_exception("#{error_msg} be greater than #{value} but found '#{actual}'") unless actual > value when :gt_eq, :greater_than_or_equal ExceptionQueue.enqueue_exception("#{error_msg} be greater than or equal to #{value} but found '#{actual}'") unless actual >= value when :starts_with ExceptionQueue.enqueue_exception("#{error_msg} start with '#{value}' but found '#{actual}'") unless actual.start_with?(value) when :ends_with ExceptionQueue.enqueue_exception("#{error_msg} end with '#{value}' but found '#{actual}'") unless actual.end_with?(value) when :contains ExceptionQueue.enqueue_exception("#{error_msg} contain '#{value}' but found '#{actual}'") unless actual.include?(value) when :not_contains, :does_not_contain ExceptionQueue.enqueue_exception("#{error_msg} not contain '#{value}' but found '#{actual}'") if actual.include?(value) when :not_equal ExceptionQueue.enqueue_exception("#{error_msg} not equal '#{value}' but found '#{actual}'") if actual == value when :like, :is_like actual_like = actual.delete("\n") actual_like = actual_like.delete("\r") actual_like = actual_like.delete("\t") actual_like = actual_like.delete(' ') actual_like = actual_like.downcase expected = value.delete("\n") expected = expected.delete("\r") expected = expected.delete("\t") expected = expected.delete(' ') expected = expected.downcase ExceptionQueue.enqueue_exception("#{error_msg} be like '#{value}' but found '#{actual}'") unless actual_like.include?(expected) when :translate expected = I18n.t(value) ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) translated #{property} property") end end else ExceptionQueue.enqueue_assert_equal(state, actual, "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) #{property} property") end end end rescue ObjectNotFoundError => e ExceptionQueue.enqueue_exception(e.) ensure ExceptionQueue.post_exceptions end |
#visible? ⇒ Boolean
225 226 227 228 229 230 231 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 225 def visible? if exists? section.displayed? else false end end |
#wait_until_exists(seconds = nil) ⇒ Object
237 238 239 240 241 242 243 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 237 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
245 246 247 248 249 250 251 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 245 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
261 262 263 264 265 266 267 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 261 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
253 254 255 256 257 258 259 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 253 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
271 272 273 274 275 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 271 def width section = find_section section_not_found_exception(section) section.size.width end |
#x_loc ⇒ Object
283 284 285 286 287 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 283 def x_loc section = find_section section_not_found_exception(section) section.location.x end |
#y_loc ⇒ Object
289 290 291 292 293 |
# File 'lib/testcentricity/app_core/screen_sections_helper.rb', line 289 def y_loc section = find_section section_not_found_exception(section) section.location.y end |