This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
119 / 137
Aug 2016

Hi @pushpank

Can you please share the steps to run appium script parallel without using selenium grid infrastructure.

Thanks
Ravi Kumar

Hi @bhaskar,

After doing everything as I found in the discussions, I was able to launch android app in multiple devices in parallel. But after that, only one device was able to finish the rest of the automation, other devices got stuck right after launching app.

P.S.: I was able to launch apps using session overriding, otherwise I was not able to launch apps in parallel even though different servers were running.

Thanks,
Minar

9 days later

You can use parallel thread .
First you have to run appium server then auto connect android device ,
write code parallel thread to run multi android devices .
Tommorow i will share u sample code .

Thanks & Regards
Pushpank kaushik

1 month later

hi puspank,

Can i have the sample code,even my app is also getting hang after launch in one of the devices

13 days later

I tried this, with Appium 1.5.3 and java client 1.4.1, it works but not consistently. I saw lot of instruments error.

Another point is I had to Synchronise lot of my methods that made parallel execution slow.

15 days later
8 days later

Hello..
I have successfully configure the setup for parallel execution but while executing the demo it is running in one device...

Try with specifying two different test tags by using TestNG xml file and provide udids for the capabilities too.
Use Grid concept as well.

Need help on Selenium Grid: I am trying executes script on different mobile emulators but i can't succeed . I have tried different tutorials but unable to succeed.

@TuHuynh: Tried but doesn't work. Other script are runnung fine. I have use following procedure
1)Started Hub
2)Started Node
3)try to execute script

Let me know if i am missing anything

I am trying demo example:
Code 1:- CalcExample .java

package example;
import java.io.File;
import libs.BaseTest;
import org.openqa.selenium.By;
public class CalcExample extends BaseTest{

public CalcExample(){
}

public CalcExample(int deviceNum) {
    super(deviceNum);
}

public void performOperations() {

    try
    {
        driver.findElement(By.id("com.android2.calculator3:id/cling_dismiss")).click();
        driver.findElement(By.id("com.android2.calculator3:id/digit5")).click();
        driver.findElement(By.id("com.android2.calculator3:id/plus")).click();
        driver.findElement(By.id("com.android2.calculator3:id/digit9")).click();
        driver.findElement(By.id("com.android2.calculator3:id/equal")).click();
        String num = driver.findElement(By.xpath("//android.widget.EditText[@index=0]")).getText();
        System.out.println("Result : "+num);
        driver.closeApp();
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

public void run(){
    File app = new File("C:\\AndroidCalculator.apk");
    String appPath = app.getAbsolutePath();
    createDriver(appPath); // create devices
    performOperations(); // user function
}

public static void main(String[] args) {
    // Create object
    CalcExample calc = new CalcExample();
    calc.execute();
}

}

Code 2:-

package libs;
import libs.DeviceConfiguration;
import io.appium.java_client.android.AndroidDriver;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class BaseTest implements Runnable{
public AndroidDriver driver;
protected BaseTest[] deviceThreads;
protected int numOfDevices;
protected String deviceId;
protected String deviceName;
protected String osVersion;
protected String port;
protected Thread t;
protected int deviceCount;

AppiumManager appiumMan = new AppiumManager();
static Map<String, String> devices = new HashMap<String, String>();
static DeviceConfiguration deviceConf = new DeviceConfiguration();

public BaseTest(){
    try {
        devices = deviceConf.getDivces();
        deviceCount = devices.size()/3;
    }catch (Exception e) {
        e.printStackTrace();
    }
}

public BaseTest(int i){
    int deviceNumber = (i+1);
    this.deviceId = devices.get("deviceID"+deviceNumber);
    this.deviceName = devices.get("deviceName"+deviceNumber);
    this.osVersion = devices.get("osVersion"+deviceNumber);
}

public void createDriver(){
    try    {
        port = appiumMan.startAppium();             // Start appium server              

        // create appium driver instance
        DesiredCapabilities capabilities = DesiredCapabilities.android();
        capabilities.setCapability("deviceName", deviceName);
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability(CapabilityType.VERSION, osVersion);
        capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");
        capabilities.setCapability("udid", deviceId);

        this.driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),capabilities);
    }
    catch(Exception e){
        e.printStackTrace();
    }
}

public void createDriver(String appPath){
    try    {
        port = appiumMan.startAppium();             // Start appium server              

        // create appium driver instance
        DesiredCapabilities capabilities = DesiredCapabilities.android();
        capabilities.setCapability("deviceName", deviceName);
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability(CapabilityType.VERSION, osVersion);
        capabilities.setCapability("app", appPath);
        capabilities.setCapability("udid", deviceId);

        this.driver = new AndroidDriver(new URL("http://127.0.0.1:"+port+"/wd/hub"),capabilities);
    }
    catch(Exception e){
        e.printStackTrace();
    }
}

public void destroyDriver()
{
    driver.quit();
    try {
        deviceConf.stopADB();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
public void start(){
    if (t == null){
      t = new Thread(this);
      t.start ();
    }
}

public void run(){
}

public  <c> void execute()
{
    Class<?> c;
    try {
        int startMethod = 0;
        String className = this.getClass().toString();
        System.out.println("class : "+className);
        className = className.replace("class ", "");
        System.out.println("class : "+className);
        // Get extended class name
        c = Class.forName(className);
        System.out.println("class : "+c);

        // Get start method
        Method[] m = c.getMethods();
        System.out.println("methods: "+m.length);
        for(int i=0;i<m.length;i++)    {
            //System.out.println("methods: "+m[i]);
            if(m[i].toString().contains("start")){
                startMethod=i;
                break;
            }
        }
        System.out.println("methods: "+m[startMethod]);
        // get constructor
        Constructor<?> cons = c.getConstructor(Integer.TYPE);
        System.out.println("cons: "+cons);

        System.out.println("deviceCount: "+deviceCount);
        // Create array of objects
        Object obj =  Array.newInstance(c, deviceCount);
        for (int i = 0; i < deviceCount; i++) {
            Object val = cons.newInstance(i);
            Array.set(obj, i, val);
        }

        for (int i = 0; i < deviceCount; i++) {
            Object val = Array.get(obj, i);
            m[startMethod].invoke(val);
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

}

1 month later

Hi

I am new to this topic , if any mistake pls lead me to the correct way!

I am using IDE as android studio for appium and I am using TestNG for parallel execution,

While creating class how do a can create testngclasses in android studio and the xml file for exacting the rest parallel

Once I created the same with option in android studio

But second time the option is not appearing for tesstng class creation

Pls help....

Thank you

"the xml file for exacting the rest parallel" this statement is " the xml file for executing the test parallely" ..by mistake it is typed like "the xml file for exacting the rest parallel"

14 days later
7 months later

@bhaskar @pushpank @Sumona @Arvind_Patel1 I’m trying to setup Appium parallel run with Selenium grid setup and facing below issues, please clarify how did you solve those

  1. Single Test class having multiple test cases, how do you pass same instance of driver across test cases ? In my case there are failures as random drivers are used to execute set of test cases on particular device

  2. multiple test cases across multiple test class, again same problem same driver is not used for same device. driver keeps on changing

how do you make sure one driver is used for one device only ?

Thanks & Regards,
Vikram