Server Side Appium

Server side Appium testing is when you upload your existing Appium tests to Bitbar Cloud and then either using the API or the cloud UI select and start test execution on multiple devices. The benefits of this approach are, you do not need to modify your Appium tests, execution of tests can be parallelised on multiple devices and you are informed when the execution is finished.

The below used sample code can be dowloaded from our git repository.

Running Sample in Cloud

Packaging The Tests

All needed files for testing need to be uploaded to cloud as zip package. This package can contain test files, data files and needs to have a Shell script to launch test execution at the root level of the package.

The above sample has the following content:

$ ls -lrt
-rwxr-xr-x  1 user  staff    60 Feb 28 16:31 requirements.txt
-rw-r--r--  1 user  staff  4667 Mar  9 15:38 TestdroidAppiumTest.py
-rw-r--r--  1 user  staff  2687 Mar 13 11:04 BitbarSampleAppTest.py
-rwxr-xr-x  1 user  staff  1263 Mar 14 16:10 run-tests_ios.sh
-rwxr-xr-x  1 user  staff  1382 Mar 14 16:11 run-tests_android.sh

Depending whether you are testing iOS or Android, you’ll need to rename run-tests_android.sh or run-tests_ios.sh to run-tests.sh depending which environment you want to test.

For the sake of this example, let’s decide we want to run an Android test, so we need to rename run-tests_android.sh to run-tests.sh.

$ cp run-tests_android.sh run-tests.sh

Now creating the test zip (called here test.zip) for upload is done as:

$ zip -r tests.zip *
  adding: BitbarSampleAppTest.py (deflated 67%)
  adding: TestdroidAppiumTest.py (deflated 70%)
  adding: requirements.txt (deflated 2%)
  adding: run-tests.sh (deflated 47%)
  adding: run-tests_android.sh (deflated 47%)
  adding: run-tests_ios.sh (deflated 44%)

Note, the run-tests.sh needs to always be at the root of the package.

Creating Project On Bitbar Cloud

  • Create a new Appium Server side project (either iOS or Android)

Project types

  • Create a new test run for this new project
  • Upload tested application (apk/ipa) in the “Application” step
  • Upload the above created zip using the “Upload test file” step
  • Choose the device group to use or create a new group for this run
  • Select optional advanced options
  • Start testrun

Once the test execution has finished, test results become available in cloud.

Additional Considerations

To get all your test artifacts presented in Bitbar Cloud you should take the following additional steps into consideration.

  • In run-tests.sh make sure that the ${TEST} variable points to correct file name. This is the name of the main Python test script file.
  • To get screenshots and test results visible in the cloud, make sure your test scripts store screenshots in a “screenshots” directory at the root of the test files directory.
  • Also if your tests create JUnit result files, name them as TEST-all.xml and locate it at the root of the test files directory

After a test run of this sample test the output should look like so.

$ ls -lrt
-rw-rw-r-- 1 user staff    4667 Jun  8 01:05 TestdroidAppiumTest.py
-rwxrwxr-x 1 user staff    1263 Jun  8 01:05 run-tests_ios.sh
-rwxrwxr-x 1 user staff    1382 Jun  8 01:05 run-tests_android.sh
-rwxr-xr-x 1 user staff      60 Jun  8 01:05 requirements.txt
-rw-rw-r-- 1 user staff    2687 Jun  8 01:05 BitbarSampleAppTest.py
-rwxrwxr-x 1 user staff    1382 Jun  8 01:06 run-tests.sh
-rw-rw-r-- 1 user staff 1595408 Jun  8 01:09 get-pip.py
-rw-rw-r-- 1 user staff    5572 Jun  8 01:09 TestdroidAppiumTest.pyc
drwxrwxr-x 2 user staff    4096 Jun  8 01:09 screenshots
-rw-rw-r-- 1 user staff    3129 Jun  8 01:09 TEST-all.xml
drwxrwxr-x 2 user staff    4096 Jun  8 01:09 test-reports

Running Sample Locally

This example works for both Android and iOS devices. Depending which you want to test, rename run-tests_android.sh or run-tests_ios.sh to run-tests.sh.

To get started you need to have curl, unzip, appium and adb for Android or Xcode for iOS installed on your test machine. Rest of the required dependencies are listed in the requirements.txt file of this sample directory. The run-test.sh takes care of installing the remaining tools and libraries.

Changing Settings

  • Launch Appium server as normally when running local Appium tests. Appium for iOS needs device ID in launch parameters

  • In run-tests.sh comment out, remove the lines or parameterise to fit your local environment needs the lines between

    ##### Cloud testrun dependencies start

    ##### Cloud testrun dependencies end.

  • run-tests.sh assumes the tested apk/ipa is named as application.apk or application.ipa and is located at the root of the working directory. Alternatively update run-tests.sh to use some other path.

  • Launch tests by running the run-tests.sh script.

Java Based Sample

There is also a Java based sample at https://github.com/bitbar/testdroid-samples/tree/master/appium/sample-scripts/java. The README has a more detailed explanation about the repository structure and how to use it.