Integrating UI tests with Appium on Buddybuild

In this post I’ll show how your mobile tests can be added in the continuous integration process and give quick feedback about the health of app after each push in the repository


What is Buddybuild?

Briefly, Buddybuild is a continuous integration tool for iOS applications, so if your team develops iOS apps and needs to implement a continuous integration process, Buddybuild can help with this.

How does everything happen?

Whenever a developer send a commit to the project repository, Buddybuild automatically prepares the build environment, clone the app source code from your repository, resolve the app dependencies and perform build steps. This is the default process, but we want to customize this process to run our UI tests with Appium, then we should modify the buddybuild_postbuild.sh file (because all command lines within this file will only run when Buddybuild has already built all of your app)

Storing the app ID folder and building the app on the simulator

Basically when you build and run the app locally in XCode, the app path is like this: Users/[your_username]/Library/Developer/Xcode/DerivedData/[app_ID_folder]/Build/Products/Debug-iphonesimulator/[app_name].app

App path in XCode

based on this, we need to store the folder of the app ID that Buddybuild generated, so we need to add this line in our file:

$BUDDYBUILD_APP_ID is the variable that returns the ID of the app that was generated.

Now we need to build the app for a simulator, so the next step is to add this:

$BUDDYBUILD_SCHEME is the variable that returns the scheme used for the current build
$APP_ID_FOLDER is the variable we defined in the previous steps to store the folder of the app ID
-destination In this parameter you can define any simulator

Installing dependencies on the server and starting Appium

Time to install all dependencies for the project. In my case, I’m using Appium with Ruby and RSpec, but if you’re using Appium with another language and framework, install all dependencies of your project.

Already with Appium installed on the server, we need to start Appium in the background

So far so good! We already know what folder our app was built in, we already installed some dependencies on the server and Appium is already running in the background

The next step here is to store the full path of the app (as XCode does, remember?) in a variable and export it.

$APP_PATH is storing the app ID folder along with the rest of the path until you get to your .app file

Updating app path to desired capabilities

As we already have the full path that the app is located on Buddybuild, we will set the variable that is storing the path ($APP_PATH) to our file where are the desired capabilities of the Appium (In my case, spec_helper.rb).

Remembering that this variable you need to add to your test repository file, not to buddybuild_postbuild file

Clone the project and run our tests

We are in the final steps. Here in the company we have the separate test repository of the app repository, so we need to add a git clone in our buddybuild_postbuild file and also add the dependencies of the project

Add the command line to run your test scenarios

and kill the Appium process after all the tests run

Now you can see the tests results accessing the Buddybuild logs :)

Obviously we can export the result to a report in AWS S3 or even create a new tab in each Buddybuild build to better visualize the results, but this will be in another post.

Finally, our complete buddybuild_postbuild file will look like this: