How to Get Started with Appium (sample included)

Everything About Appium Test Automation

Dear Testdroiders,

In case you’re interested to start testing your Android & iOS apps and games with Appium, here are the basic steps to get you up and running with it on real devices at Testdroid Cloud. Just follow these steps, with provided sample and test scripts, and you’ll see how easy it actually is.

Testdroid + Appium + Real Devices = Awesome Combo

Setting up your machine

Testdroid Appium sample TestScripts are available in Python, Java and Ruby. Appium tests are executed remotely from user’s own machine, and the tests are executed on Testdroid Cloud in real time. To run the Python scripts locally from your machine, follow the instruction below on setting up your machine.

OS X / Linux

Ensure that Python 2.7.x or later is installed (pre-installed on OS X)​
$ python --version​

Install Python if not installed (Linux only)
$ sudo apt-get install python2.7

Check if Python ‘pip’ module is already installed
$ pip --version

Install pip if not installed (OS X)
$ curl https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py > get-pip.py
$ sudo python get-pip.py
$ rm get-pip.py

Install pip if not installed (Linux)
$ sudo apt-get install python-pip

​Install Python ‘selenium’ module
$ sudo pip install selenium

Verify that ‘selenium’ is installed
$ pip freeze | grep -i selenium

Windows

Ensure that Python 2.7.x or later is installed
$ python --version

If not installed, download and run setup from python.org download centre
To add Python environment variables, go to System properties > Advanced System Settings > Environment Variables > System Variables > Edit ‘Path’, and insert “C:Python27;C:Python27Scripts” in the end (Assuming you have installed Python at default location). Make sure to restart the command prompt for new environment variables to come in effect.

Check if Python ‘pip’ module is already installed
$ pip --version

Install pip if not installed
$ curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py > get-pip.py
$ python get-pip.py
$ del get-pip.py

Install Python ‘selenium’ module
$ pip install selenium

Running the TestScript

Download the Testdroid Appium Sample TestScripts and sample applications archive, which includes sample iOS and Android apps the tests are written for. Navigate to the downloaded scripts directory via command line. There are three sample TestScripts:

1. testdroid_ios.py (for iOS)
2. testdroid_android.py (for Android version >= 17)
3. testdroid_selendroid.py (for Android version < 17)

Step 0: Upload the app

Before proceeding with running the TestScript, you need to upload the .ipa/.apk to Testdroid Cloud via HTTP POST. Below is an example using cURL.

OS X / Linux
$ curl -s --user username@example.com:pas$w0rd -F myAppFile=@"/absolute/path/to/app/BitbarIOSSample.ipa" "http://appium.testdroid.com/upload"

Windows
$ cd C:pathtodirectorycontainingtheapplication
$ curl -s --user username@example.com:pas$w0rd -F myAppFile=@"BitbarIOSSample.ipa" "http://appium.testdroid.com/upload"

On successful upload, you would get a JSON response with status:0, and a unique identifier to the uploaded app.
{
    “status”: 0,
    “sessionId”: “abcdefg-1234-5678-abcd-111122223333”,
    “value”: {
        “message”: “Uploads Successful”,
        “uploadCount”: 1,
        “rejectCount”: 0,
        “expiresIn”: 1800,
        “uploads”: {
            “myAppFile“: “abcdefg-1234-5678-abcd-111122223333/BitbarIOSSample.ipa
        },
        “rejects”: {}
    }
}

Step 1: Set credentials and other parameters

Open the TestScript testdroid_ios.py in any text editor. Set the screenshotDir to path where you want the screenshots to be saved in at your machine. Set your credentials against testdroid_username and testdroid_password in Desired Capabilities. Set the myAppFile identifier from Step 0 against testdroid_app in Desired Capability. Details on all testdroid_ Desired Capabilities can be found here, but you can use default values for now.

Step 2: Run the TestScript

$ python testdroid_ios.py

The output should look like:

webdriverrequest

Step 3 (optional): Upload your Test Suite output to Cloud
If your test suite generates a JUnit XML results file, you can upload the XML to Cloud. Doing this will show the test-cases and their statuses on the Web UI, and let you download test reports.

> Add the testdroid_junitWaitTime Desired Capability in your TestScript.
> Get Appium sessionId from your script (after the WebDriver connection has been established) using: driver.session_id()
> After your test run has finished, and JUnit XML has been generated, use Curl to upload the XML to Cloud:

$ curl -s -F result=@"/absolute/file/path/TestOutput.xml" "http://appium.testdroid.com/upload/result?sessionId=<sessionId>"

Step 4: Get results from Testdroid Cloud
The screenshots are available locally on your machine inside the directory you specified in Step 1.
Log into https://cloud.testdroid.com and navigate to project name as defined in testdroid_project Desired Capability to get the following log files.
1. Appium server log
2. Logcat / Instruments log

  • Mark Steve

    Your post is highly valuable because the way you have explained is quite simple & easy to understand plus it can also help young developers. The main part of your blog are the steps that you have mentioned.
    event management applications

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close