Faster development of Calabash tests
While creating the page object classes in our Calabash mobile test suites at JUST EAT, we found ourselves repeating a lot of actions when waiting for, scrolling to and interacting with elements on the screen. We abstracted these actions into a library to avoid this unnecessary duplication of code and made these actions agnostic to screen size. This library has now been published as a ruby gem called calabash-page-objects.
Why use this?
Dealing with small screens
Sometimes you have to scroll to elements on small screens but not on larger screens. We initially used if-statements dealing with an environment variable for ‘small screen’ inside your test code – not good!
We wrote a method to scroll to an element if it wasn’t immediately there. This method was then included in many of the methods available to our elements; touching, inputting text, asserting presence etc.
Multiple scrollable views
When attempting to use Calabash’s default scroll method, we noticed that sometimes it didn’t appear to scroll the view we wanted if there were multiple scrollable views on the screen.
After looking into the Calabash methods, we noticed that you could perform scroll actions on locators. We wrapped up this method in the gem too so that we could pass both the element we’re searching for and the view it belongs in into all the helper methods. This became the ‘parent’ parameter that the gem methods can optionally take.
How to use?
The calabash-page-objects gem exposes two element classes, one for iOS the other for Android. They are implemented in the same way regardless of the platform under test. These element classes have methods for, waiting for them to be visible, waiting for them to disappear, touching them, etc. These methods all take variables in a consistent format.
require 'calabash-page-objects' class HomeScreen def initialize @my_element = IElement.new("* id:'something'") @form_scrollview = IElement.new("* id:'something_else'") end def some_method @calabash_query = @my_element.screen_query @my_element.when_visible(30) @my_element.prod @my_element.when_not_visible(30) @element_present? = @my_element.present?(timeout: 2, scroll: true) @my_element.input('[email protected]', parent: @form_scrollview) @my_element.check @my_checkbox.uncheck @ischecked? = @my_checkbox.checked? @element_text = @my_element.text end end
See the project on Github for more information, and a more detailed description of the methods and parameters. Feel free to fork it and contribute too.