Appium Parallel Execution

I found out some reference links to follow, I will give a try first then come back to you if I face any issue.

Thanks man.

Just FYI I have tried to run same set of tests on iOS Simulator and Real device connected to same machine at the same time.

1 Like

@pavan_appium @TuHuynh
Iā€™m starting the grid and registering the appium instance in java code using the below snippet:

@BeforeSuite
public void startgrid() throws IOException, InterruptedException{
Runtime.getRuntime().exec(ā€œjava -jar /Users/dd/Selenium/selenium-server-standalone-2.53.1.jar -role hub http://127.0.0.1:4444/gridā€);
Thread.sleep(50000);
Runtime.getRuntime().exec(ā€œappium -a 127.0.0.1 -p 4723 --no-reset --bootstrap-port 4730 -U device111 --nodeconfig /Users/dd/workspace/SampleAutomation/jsonFiles/node_config_1.jsonā€);
Runtime.getRuntime().exec(ā€œappium -a 127.0.0.1 -p 4725 --no-reset --bootstrap-port 4730 -U device222 --nodeconfig /Users/dd/workspace/SampleAutomation/jsonFiles/node_config_3.jsonā€);
Thread.sleep(50000);
}

First time when I run the test , grid is starting and the two appium instances are getting registered and test runs as I expected. Next time when I do mvn test it is showing the following execption
org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: ā€˜2.53.0ā€™, revision: ā€˜35ae25b1534ae328c771e0856c93e187490ca824ā€™, time: '2016-03-15 10:43:46ā€™

Can u say how to stop the grid once the test is completed ?

I think you just need to kill appium is ok.

Taskkill /F /IM node.exe

Am I right @pavan_appium ?

in @afterSuite we need to give this command??

With me, yes, and I used below method:

==

public static void stopServer() {
    CommandLine command = new CommandLine("cmd");
    command.addArgument("/c");
    command.addArgument("Taskkill /F /IM node.exe");

    try {
        DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
        DefaultExecutor executor = new DefaultExecutor();
        executor.setExitValue(1);
        executor.execute(command, resultHandler);
        Thread.sleep(5000);

        System.out.println("------> Appium server stopped.");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

}

@TuHuynh
what u have specifed is for Windows machine ?? Iā€™m using mac and wat about it?

And I also tried

@AfterSuite
public void appstop() throws IOException {
Runtime.getRuntime().exec(ā€œkillall nodeā€);
}

This also didnt work out.

Sorry for late reply.
Yes you need to kill Appium as initiating new session is a bit issue with current build
if you have to kill appiumon mac then use command ā€œpkill -f appium (or node)ā€

can i gve this in aftersuite as I mentioned below?
@AfterSuite
public void appstop() throws IOException {
Runtime.getRuntime().exec(ā€œpkill -f appiumā€);
}

@pavan_appium: Hi Pavan, I am trying selenium grid but couldnā€™t succeed in it. I have referred so many tutorials till stuck in itā€¦ Please share any document which describe step by step process for implementation for selenium grid. I want to implement it for IOS and Android platform. Thanks in Advance.


In screenshot no 1. how to procced next step
In Screenshot no. 2 , while executing code , it displayed error

Please set ANDROID_HOME env variable correctly so that adb command runs correctly.

@pavan_appium:- i have set env variable fot ANDROID_HOME

let me know if any issue in screenshot

Did you add ANDROID_HOME in PATH Variable too ?

yes

Please give a try with setting ANDROID_HOME in your Eclipse

In [Run configuration] please set as attached pic.

@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();
    }
    
}

}

@pavan_appium @TuHuynh
I m trying to send the emailable-report.html through mail . I configured in jenkins also but once the test is completed Iā€™m getting the following lines.

Email was triggered for: Always
Sending email for trigger: Always
Sending email to: [email protected]
Connection error sending email, retrying once more in 10 secondsā€¦
Connection error sending email, retrying once more in 10 secondsā€¦
Failed after second try sending email

I configured using editable-email notification . I dont know whats the problem once I completed the test . Pls help me to solve this issue.

can anyone provide suggestion on the above issue??

this link is not working as getting below error when clicked on it

PAGE NOT FOUND
Error 404
Sorry, the page you were looking for at this URL was not found.

Search this site on Google

configuring appium node servers with selenium grid
SEARCH GOOGLE
Ā© 2017 Zymr, Inc.

I have been trying since weeks to do parallel execution but failedā€¦the complete details of my issue are present in the below linkā€¦can you please help me to solve this issueā€¦Appium Parallel Execution