Skip to content
Harry Tran edited this page May 31, 2019 · 3 revisions

Welcome to the Appom wiki where you'll find lots of additional information about Appom. You can find Appom list functions and some note about Appium.

Race conditions and implicit waits

To use our example of finding elements: our code usually implicitly assumes that the element will be present before we try to find it. So that to make sure we can find elements successfully we always specify waiting time. Example:

# We have to sleep fixed timeout to make sure the screen is displayed
sleep 3 
# Call function email to get element from Appium server first
email = @driver.find_element(:accessibility_id, 'email_text_field')
# After getting element we can take action
email.send_keys('duchoang.vp@gmail.com')

Because the designers of Selenium were well aware of the element finding race conditions, a long time ago they added the ability in the Selenium (and we copied it with the Appium) server for the client to set an "implicit wait timeout". To resolve that problem we can find element with implicit waits

# Declare a wait instance
wait = Selenium::WebDriver::Wait.new(timeout: 20)
# Wait will try get element before timeout.
email = wait.until { @driver.find_element(:accessibility_id, 'email_text_field') }
email.send_keys('duchoang.vp@gmail.com')

With implicit waits we avoid specifying waiting time.

Implicit waits in Appom

To avoid depending on Selenium we implemented Wait class ourselves.

Default Appom implicit wait time is 20 seconds. But we can configure by

Appom.configure do |config|
  config.max_wait_time = 30
end

Section and Sections

Section is defined as a special element within a page. Sections can contain element, elements or even other section.

class PersonalitySection < Section
  element :character_header, 'id', 'com.hoangtaiki:id/character_header'
  element :character_description, 'id', 'com.hoangtaiki:id/character_description'
  element :character_image, 'id', 'com.hoangtaiki:id/character_image'
  element :badge_image, 'id', 'com.hoangtaiki:id/badge_image'
end

And we can define a section element inside a Page

class ProfileScreen < Page
  element :back_button, 'id', 'com.hoangtaiki:id/back_button'
  element :star_button, 'id', 'com.hoangtaiki:id/star_button'
  element :avatar_image, 'id', 'com.hoangtaiki:id/avatar_image'

  section :section_emotional, PersonalitySection, 'id', 'com.hoangtaiki:id/section_emotional'
  section :section_extroversion, PersonalitySection, 'id', 'com.hoangtaiki:id/section_extroversion
end

Sections is an array section with same selector.

Helpers function

1. Existence and nonexistence checker (Element and Section)

To determine the existence of an element

has_title_label

This function use implicit waits and try to find the element until time out. This function will return true if the element is existence and Raise if the element is nonexistence.

To determine the nonexistence of an element

has_no_title_label

This function use implicit waits and check until the element does not exist. This function will return true if the element is nonexistence and Raise if the element is existence.

3. Enable and disable checker (Element and Section)

Wait until an element is enable

title_label_enable

Wait until an element is disable

title_label_disable

4. Wait and find until elements is not empty (Elements and Sections)

elements :cells, 'id', 'com.hoangtaiki:id/cell'

Wait and find until elements is not empty

get_all_cells

This function use implicit waits and find until cells is not empty.