This is the first blog in our 37 Things You Should Know About Appium blog series, and we’ll naturally start with the basic things, getting environment set up, Appium pieces installed and running on your machine. Depending on which programming language you are using, we’ve tried to provide here everything, step-by-step, for those 4 main languages.
To get started, first download our Appium example. The example is available in C#, Python, Java and Ruby, and we’ll be using these as a basis for next examples. Okay, then depending on which programming language you will be using, select the appropriate client library as follows. Or you can download our free Appium beginner’s guide to access your local copy anytime.
Most of the Testdroid examples are located in our Github repositories. To make most out of the existing samples you should have Git installed. If you are new to Git, there is a very good guide on how to install Git on popular operating system here. Below is the abbreviated version of the installation procedures.
Mac OS X
Download the latest git command line tool from http://git-scm.com/download/mac install it using normal Mac installation procedure.
Use the following command to get Git installed on your Linux machine:
$ sudo apt-get install git
The easiest and most straight forward way is to install the Github Windows application.
Mac OS X and Linux
Our Python samples have been created with 2.7.x version in use, so best compatibility can be expected with the same. Check that newest Python 2.7.x version is installed by using the following command:
$ python --version
If not installed, you can install Python by using the following commands:
Linux: $ sudo apt-get install python2.7 OSX: $ brew install python
Brew is a handy package manager tool, similar to apt-get. If you don’t have it, check the brew website for its one-liner installation.
Then, check if ‘pip’ module is installed. Use the following command:
$ pip --version
If ‘pip’ is appropriately installed, you’ll see something like this:
pip 1.5.6 from /Library/Python/2.7/site-packages (Python 2.7)
If not, use the following command to install it:
Linux: $ sudo apt-get install python-pip OSX: $ sudo easy_install pip
Next, install the Selenium module for Python:
$ pip install selenium
And finally, verify that Selenium got installed:
$ pip list | grep selenium
Ensure that newest Python 2.7.x version is installed. Go to command line and use the following:
> python --version
If Python 2.7 or newer is not installed, download and run the setup from Python’s download center. To add Python into environment variables, go to Windows “System properties” → “Advanced System Settings” → “Environment Variables” → “System Variables” → choose “Path” and press “Edit…” and then insert (assuming you have installed Python in the default location)
;C:Python27;C:Python27Scripts at the end separating each path with semicolon ; . Make sure to re-launch the command prompt to bring new environment variables into effect.
Then, check whether Python’s pip module is already installed:
> pip --version
Install pip if it’s not already (we assume here that you have cURL installed. If not, check this out):
> 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’s Selenium module:
$ pip install selenium
Appium testing supports writing tests in multiple programming languages, including Java. Testing can be done against native or hybrid apps or responsive web pages on both iOS and Android devices. Only the test setups differ.
With Java, things are pretty simple and you only need to configure your test file accordingly. You can use SampleAppium(iOS)Test.java as an example/template.
In case you don’t have an IDE with Maven included and would like to launch the example from command line, you will need to make sure that Maven is properly installed. Here’s a link to the installation instructions.
Launch the AppiumTest.sln on Visual Studio and make sure that NUnit Test Adapter is installed through the Extension Manager. Use Test Explorer to run your tests.
$ nuget install Test123/packages.config -OutputDirectory packages
To build the package, simply use the following command on correct path:
First, install the latest stable release of Ruby:
$ curl -sSL https://get.rvm.io | bash -s stable $ rvm install ruby
Then, make sure RVM is using the correct Ruby by default:
$ rvm list $ rvm --default use 2.1.1
In case you have an old Ruby/RVM, you can upgrade those with the following commands:
$ rvm get head $ rvm autolibs homebrew $ rvm install ruby
Check that it’s installed properly by printing out the Ruby version:
$ ruby --version
Update RubyGems and Bundler:
$ gem update --system $ gem install --no-rdoc --no-ri bundler $ gem update $ gem cleanup
Check that RubyGems is >= 2.1.5
$ gem --version
Run bundler at the Ruby example directory to install dependencies:
$ bundle install
All Programming Languages: How to Configure Testdroid Specific Settings
If you used any of those example files as a template, add your Testdroid user credentials in this script. You can also use environmental variables TESTDROID_USERNAME and TESTDROID_PASSWORD to get your credentials used:
String testdroid_username = env.get("TESTDROID_USERNAME"); String testdroid_password = env.get("TESTDROID_PASSWORD");
Or alternatively, you can edit
testdroid_password in your source file:
capabilities.setCapability("testdroid_username", 'firstname.lastname@example.org'); capabilities.setCapability("testdroid_password", 'secretPassword123');
If you are new with desired capabilities or if you are looking for more information on how to use those efficiently, take a look at this article.
Also, if you want to run tests against your application, make sure to change a file path to your application binary (whether you are running against APK or IPA):
private static final String TARGET_APP_PATH = "../../../apps/builds/BitbarSampleApp.apk";
In addition, there are lots of possible ways to configure your test run for our devices. In order to do this, you need to configure those desired capabilities. We’ll get the bottom of this later in the blog series, but the current examples are as follows:
DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName", "Android"); capabilities.setCapability("testdroid_target", "Android"); capabilities.setCapability("deviceName", "Android Device"); capabilities.setCapability("testdroid_project", "LocalAppium"); capabilities.setCapability("testdroid_testrun", "Android Run 1"); // See available devices at: https://cloud.testdroid.com/#public/devices capabilities.setCapability("testdroid_device", "Samsung Galaxy Nexus GT-I9250 4.2.2"); capabilities.setCapability("testdroid_app", fileUUID);
In this Java example, you only really need to configure
testdroid_password, since sample application upload is included.
Running Your First Test
To upload your app file (either APK or IPA) to Testdroid Cloud, open and configure the
upload.py script. As we walked it through, you only need to configure your username (email) and password that you registered with to Testdroid Cloud. Also, you need to set the full path to your mobile app. This can be an Android or iOS application. Then execute this:
$ python upload.py
To run a test:
$ python testdroid_android.py
You can run test from your IDE or directly from command line using Maven:
> mvn clean test -Dtest=SampleAppiumTest
or to be more precise:
> mvn clean test -Dtest=com.testdroid.appium.android.sample.SampleAppiumTest
or run all the tests:
> mvn clean test
To run tests, either launch them in Visual Studio via the Text Explorer or use the nunit console command:
$ nunit-console Test123/bin/Debug/TestdroidAndroidSample.dll
Run the tests with rspec:
$ rspec testdroid_android.rb
There’s a myriad of different ways you can setup, build and run your Appium tests. The ones provided here were just one example of how things can be done. Stay tuned – more good stuff about Appium is coming out in few days!
Happy Appium Testing!
Learn all the basics about Appium, how to set it up and how to use it for mobile app testing.Download