Leveraging Appium for Mobile Test Automation

By Quentin Thomas

Like many other tech companies we believe testing is essential to whether or not a product lives or dies. Development is happening today at a much faster pace than it was a few years ago, and because of this, our testing methods should develop just as quickly.

Our booking integration test is now fully automated along with countless others. With the following automation techniques in place it frees the QA team up to focus on more of our major corner cases and new features!

We spent several weeks researching and testing the best tools for the job and we finally found a reliable solution. Thanks to the engineers at Sauce Labs it is now possible to tackle the mobile automation world with precision and consistency.

Appium, which is one of the newest automation frameworks introduced to the open source community has become a valuable test tool for us at HotelTonight. The reason we chose this tool boils down to Appium’s philosophy.

“Appium is built on the idea that testing native apps shouldn’t require including an SDK or recompiling your app. And that you should be able to use your preferred test practices, frameworks, and tools”.

To keep up with our development team at HT we decided to implement a new automated tester we’ve named “Bertha”. Bertha is responsible for taking on all our automated testing tasks and it uses Appium to do so.

How this works

First, we needed to configure Appium to have the proper capabilities. Here is the RSpec config helper.

RSpec.configure do |config|
  config.color_enabled = true
  config.include Helpers
  config.before(:all) do
    options = {
      caps: {
        platformName: 'iOS',
        app: APP_PATH,
        platformVersion: '7.1',
        deviceName: 'iPhone Simulator',
        locationServicesEnabled: false,
        autoAcceptAlerts: 'true'
      } ,
      app_name: 'HT Test',
      launchTimeout: 20000,
    Appium.promote_appium_methods Object

  config.after(:all) do

To configure Appium with RSpec we pass in the capabilities we want our application to be launched with. In our case, an important capability we gave Appium is the autoAcceptAlert option.

We have a constant called APP_PATH, which holds the location for the built version of our test app on Bertha. This is found at /Library/Developer/Xcode/DerivedData/ after we have built our iOS app.

After the test suite is configured we still need a way to logically drive the testing activity. This is where we really utilize the power of the RSpec framework. Here is what the booking_spec.rb file looks like.

feature 'Booker Joe creates a Booking' do
  scenario 'books a hotel in Denver' do
    search_for 'Denver'
    sign_in_as 'booker_joe'

    choose 'Warwick Denver Hotel'

    expect(reservation_info).to be_present?

The booking flow test is designed to be really straight forward as all good tests should be. Anyone should be able to look at it and follow the exact business logic being tested. Notice all test functions are modular. Modular test functions allow us to build automated tests quickly especially since most of the functions will be reused across multiple tests. Design once and reuse over and over again!

We use the ruby library appium_lib to talk to Appium. This library comes jam-packed with really slick ways to design test strategies around mobile apps.

Tracing the H is a really cool animation gesture we have in our app. Below is an example of what it looks like doing this gesture manually.

Trace the HBed animation

Now that we’re using Appium, this action is automated with the code below.

def trace_the_H
  execute_script('target.frontMostApp().mainWindow().elements()["signature panel"].dragInsideWithOptions({startOffset:{x:0.02, y:0.06}, endOffset:{x:0.03, y:0.93}, duration:0.1});')

Our trace_the_H function is making use of a javascript function called dragInsideWithOptions, which is a part of the UI Automation library designed by Apple. Appium allows us to call these functions within our tests with the execute_script method!

Let us know what you think!

Written by Quentin Thomas

Read more posts by Quentin, and follow Quentin on Twitter.

Interested in building something great?

Join us in building the worlds most loved hotel app.
View our open engineering positions.