Test Automation

Running Appium UI tests in an Azure Pipeline


Running Appium UI tests in an Azure Pipeline is a challenging activity. This guide describes how to run Appium UI tests from Azure DevOps. Following are the required phases of the process. Feel free to contact me if you have any queries related to the steps given below. Also do visit this blog to get detailed knowledge of the CI CD process.

Creating your maven project

Using IntelliJ, creating a new project using Maven, and then adding required dependencies in pom.xml, my project looks like this:

Note: Place your APK file in the source file and rename the required settings accordingly.

Explanation: There are three classes inside of my projects, LaunchAppServer, which contains code to launch the Appium server, Tests class contains the tests and, Util class which contains thread. For sleep function, you can also place other such settings in this class. Also, I am using Junit as TestNG is not supported by App Center. I have also added an extra setting in the pom.xml as by default Junit generates reports in XML.

Also, import the required package in the class, My import packages are given below, some of them are not in use but I have not removed it.

Note: I am not following Page Object Model in the project, you must restructure the code accordingly for it.

Running your tests

As it is a maven project you can easily run the project using the below commands

Mvn clean
Mvn compile
Mvn test

Note: Before running make sure your pom.xml is correct Maven is installed on your project, Emulator is up and running and the Appium server is installed via npm. Once you are able to get tests from maven locally then the following are the changes you need to add in your project for running it on device on the App Center from CI CD in Azure DevOps.

Test Preparation | Running Appium UI tests in an Azure Pipeline

Carefully follow the below link mentioned in the link below.

Link: https://docs.microsoft.com/en-us/appcenter/test-cloud/frameworks/appium/

Following are the major changes you will find in the link above

Changes to the build system

  1. Add repository and dependency.
  2. Add upload profile.

Note: if you get an issue while adding this section in the pom.xml then compare it with the pom.xml of my project.

Changes to the tests

  1. Add imports.
  2. Instantiate the TestWatcher
  3. Update your driver declaration
  4. Update your driver instantiations

Making the above changes will give you a tough time, especially configuring pom.xml and downloading dependencies in it. You can use my project as a sample project and compare your pom.xml or any other configuration with it.

Preparing upload folder for the app Centre

Now if you have successfully followed the above steps then you will be able to prepare upload package using the command given below,

mvn -DskipTests -P prepare-for-upload package.

Link: https://docs.microsoft.com/en-us/appcenter/test-cloud/frameworks/appium/

See snap below.

Explanation: After executing this command, if your pom.xml was properly configured it will package your project in the target/upload folder that will contains three main items which are

  •  Your test classes.
  •  All dependencies used in the project.        
  •  Pom.xml

As shown below.

Note: Make sure you have commented APK file code and launching app center code, as this is not needed while running the script from the CI/CD, as APK will be generated in CI part of the pipeline from the code when it is built, and Appium is already running in the App Center Environment. Once you get this package then you can run these tests on device from app center

appcenter test run appium --app "APP_ID" --devices "DEVICE_SET_ID" --app-path PATH_TO_FILE.apk --test-series "main" --locale "en_US" --build-dir target/upload

Note: ignore this command if you do not understand it, late in the document we will do the same task from CI-CD.

Cloning your Repo from azure DevOps locally

Clone your Project source code locally, Add the target/upload folder in it and push it to Azure DevOps. Now Test project is also part of our project source code. See snap below.

Configuring App Centre

You also need to few configurations on app Centre which are as below. Add app in App Centre see snap below.

Select your app and click on setting. Create API token as shown below and copy it on safe location. This token will be required while creating app service connection in Azure DevOps that will be used in setting up App Center Test in CI/CD. 

Next step is to create Group, this is the group with whom the apk will be shared, this id will be needed while configuring app Centre distribute in CI/CD. Once the group is created, click it, and copy its ID by clicking the setting icon. Now Select Test runs on left side, select your testing device by clicking on start testing your app, select your device and in configuration, leave the test series as master, test framework as Appium. Now from the left side select test and then click on run test, select device, and create it.

 9. Setting up CI CD in Azure DevOps:

Now login on Azure DEVOPS and select your project, click setting and create a service connection, during installation it will ask for API token which we have already created in above step. Now click the repository of the project and create pipeline on it, I have created classical pipeline, CI/CD is achieved in the same pipeline, last two steps are for executing the scripts from the pipeline, snapshot of all the steps are shown below with required configuration, I am not going into detail to describe each step, but it will build your code, deploy APK on the app Centre, upon which your Appium tests will be executed, App Centre will prepare a report of the test which will look like :

Summarize what you have learned:

So now you will be able to apply same steps to configure CI CD for your android or IOS project with Appium UI Tests.  Microsoft documentation that might help you in applying this guide.

Link: https://docs.microsoft.com/en-us/appcenter/test-cloud/vsts-plugin

Rashid Ali

I am an IT professional with 10 years of experience in the field of Software development. My track record of satisfied clients speaks to my proficiency in delivering top-notch services in QA manual and Automation, IT support services, Blogging , and On-page SEO.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Back to top button