Running Appium for iOS tests on Jenkins

What are we going to do?

This post will show the steps of running iOS tests on Jenkins

Since Appium works as selenium grid server it makes sense to have it always running on the Jenkins node ready to be used by our tests. Assume that the iOS app that we’re testing is already in the workspace. In a future post I will explain how to get it from a remote location.

We can use Xcode cli tools to create, boot and restart iOS simulators. To list available device types and runtimes :

xcrun simctl list devicetypes runtimes

These come with Xcode installation, from here we can choose a combination of device type and runtime to create a new simulator:

== Device Types ==
iPhone 6s (
iPhone 6s Plus (
iPhone 7 (
iPhone 7 Plus (
== Runtimes ==
iOS 9.3 (9.3 - 13E233) (
iOS 10.2 (10.2 - 14C89) (

To create an iPhone 7s with iOS 10.2:

xcrun simctl create

Appium will take care of booting the simulator and installing the app.

Now we need to run the Appium server on the Jenkins node, Next ssh into the node and run the server, we assume that Appium has installed as a node module:

node_modules/.bin/appium --address --port 4723

Lets look at the steps for the Jenkins job:

Create a new job , the first step is to clone from your test repository:

source code step on jenkins

Make sure you have set up proper credentials and read permissions for that repository.

Our test repository file should be configurable through environment variables:

'IOS': {
    'automationName': 'XCUITest',
    'platformName': 'iOS',
    'platformVersion': os.environ.get('IOS_PLATFORM_VERSION', '9.3'),
    'deviceName': os.environ.get('IOS_DEVICE_NAME', 'iPhone 6s'),
    'newCommandTimeout': 180,
    'app': os.environ.get('IOS_APP_PATH', 'apps/')

Add a step to inject environment variables to override (in case that is needed) the default values:

Injecting environment variables step in jenkins

We need to add a step Execute shell to install the python requirements and run our tests:

execute shell step in jenkins

We are passing a user variable called profile to run our tests, we use it to differentiate platforms for the test run. For more information on how to set this up, refer to this post.

Behave can export a jUnit xml report for us that Jenkins can use to publish our test results. Enable this results with the flag --junit

Now we add a post build action to publish the jUnit results:

Screen Shot 2017-04-17 at 12.43.54 AM

And that’s it! We now should be able to run the Jenkins job and get test results.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s