Appium Parallel Tests on Multiple Emulators

Appium Parallel Tests on Multiple Emulators article, I will explain how to set up and then run your Appium Tests on multiple virtual devices. I will show this on MAC operating system but on Windows also the settings are similar and for Windows settings, you can check this article. Let’s get started!

Appium Setup on MAC and Windows

First, we need to install all required tools on our operating system. In other articles, I shared these steps in detail and I want to share with you these articles.

Appium Mac Setup: https://www.swtestacademy.com/how-to-install-appium-on-mac/

Appium Windows Setup: https://www.swtestacademy.com/appium-tutorial/

Install Selenium Grid and Do Configurations

After the installation of appium and its required tools, now we should install Selenium Grid and prepare our configuration JSON files. For this, we need to download the Selenium Grid jar file and save in a directory. Then, I will share the configuration JSON files with you. For more detailed instructions, I will share Selenium Grid articles for mac and windows.

Selenium Grid For Mac: https://www.swtestacademy.com/selenium-grid-on-mac/

Selenium Grid For Windows: https://www.swtestacademy.com/selenium-grid/

For this example, I will do the tests on a MAC machine, and I will use Android Studio for emulators. I will create two emulator devices for the Android 11 platform version. One of them is Pixel XL and the other is Pixel 4. For virtual device creation, you can check here.

android virtual devices

And for their Node config files, I used the below JSONs you can put these JSON files in selenium standalone jar’s director.

selenium grid directory

Pixel-4 JSON Config

{
  "capabilities": [
    {
      "deviceName": "Pixel 4 API 30",
      "platformName": "Android",
      "browserName": "Pixel 4 API 30",
      "platformVersion": "11",
      "maxInstances": 1
    }
  ],
  "configuration": {
    "cleanUpCycle": 2000,
    "timeout": 30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url": "http://127.0.0.1:4000/wd/hub",
    "host": "127.0.0.1",
    "port": 4000,
    "maxSession": 1,
    "register": true,
    "registerCycle": 5000,
    "hubPort": "4444",
    "hubHost": "127.0.0.1"
  }
}

Pixel-XL JSON Config

{
  "capabilities": [
    {
      "deviceName": "Pixel XL API 30",
      "platformName": "Android",
      "browserName": "Pixel XL API 30",
      "platformVersion": "11",
      "maxInstances": 1
    }
  ],
  "configuration": {
    "cleanUpCycle": 2000,
    "timeout": 30000,
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "url": "http://127.0.0.1:4001/wd/hub",
    "host": "127.0.0.1",
    "port": 4001,
    "maxSession": 1,
    "register": true,
    "registerCycle": 5000,
    "hubPort": "4444",
    "hubHost": "127.0.0.1"
  }
}

Startgrid.command File

#! /bin/bash
osascript -e 'tell app "Terminal"
    do script "cd /Users/onur/OneDrive/swtestacademy/new-articles/selenium-server/ && 
    java -jar selenium-server-standalone.jar -role hub"
end tell'

If we run the startgrid.command file as shown below, the Selenium Grid will start on another terminal window. On windows also you can simply run the below command:

java -jar selenium-server-standalone.jar -role hub

selenium grid run on mac

Start Multiple Appium Servers

Now, we should run two appium servers. On the mac, you need to go to the Applications directory and right-click appium and click duplicate to create one more appium application. 

how to run two appium server on mac

After this step, you can run these two appium applications by clicking them.

When the appium desktop applications will be ready, you need to configure them as shown below.

For Pixel-4

appium desktop settings

For Pixel-XL

Here, we should point our config files and in our config files we defined the port for each device, we should also write these ports in Server Port fields as shown in the above screenshots.

After these steps, we can run the selenium servers. They will look like below. They should both registered the Selenium Grid Hub.

appium servers

Also, we can check this on Selenium Grid Console, by visiting this link: http://localhost:4444/grid/console

selenium grid console

Start Virtual Devices a.k.a Emulators

Then, we should start our emulators and also install the application which we want to test. For application installation, please check this article.

android emulators

Parallel Mobile Appium Test Project with TestNG

Now we are ready to run our tests. We should write this code in a parallel test execution manner. We will use İsinOlsun application, and write a code for the following scenario:

  • Open the app.
  • Skip splash screen
  • Select “İs Ariyorum” (It means I am looking for a job.)
  • Then, accept notifications.
  • Then, click the second job in the job list.
  • Assert that we are on job’s detail page.
  • Wait for a while
  • Then, close the app. I do not want to apply for a job :-) It is a simple scenario.

It is a very basic scenario. Our main purpose is to set up our wireless device lab and run them in parallel. After this step, you can extend this project.

Project Structure

I do not want to copy and paste each test class’s code here. Rather than this, I will share the GitHub project below. You can fork the repo and modify it based on your needs. If you have any questions related to the test codes, please write a comment. Also if you like this article please share your comments with us.

GitHub Project

https://github.com/swtestacademy/appium-parallel-tests/tree/appium-parallel-tests-with-emulators

Youtube Demo Video

I hope you have enjoyed this article and it is helpful for you. If you like it, please share your feedback in the comment section.

Thanks for reading,
Onur Baskirt

5 thoughts on “Appium Parallel Tests on Multiple Emulators”

  1. Where can we get the app com.isinolsun.app? And please help me to understand what is referring to “new-articles/selenium-server/” from the below line?
    do script “cd /Users/onur/OneDrive/swtestacademy/new-articles/selenium-server/

    Reply
  2. Hey Onur, thanks for much this helpful tutorial. After implementing, seems like my tests are running twice on each device. Example I have 4 test cases and 2 devices, all 4 test cases are running on each device. It looks like the tests are not distributed. Do you know what could’ve caused this? Thanks

    Reply
    • Hi fatin, I did not face that issue when I was running the tests. Maybe it is about the version of one library in the automation project. If I have time, I will try to run them on my machine and let u know. Have a great day!

      Reply
      • Got it. I’ll try to check the dependencies version and play around with it. Thanks Onur! It’s difficult to find proper reading materials for native parallel mobile automation, so I very much appreciate the tutorials you provided and your help.

        Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.