Connecting appium server to selenium grid for android

Hi I Have done it , refer video. it may help

Chreerrrrsss :smiley:

Not a reply to a specific thread. Just be aware that the -bp (bootstrap port) is critical on the node setup for running in parallel. Without this setting, the nodes will error when receiving requests from the hub. Spent way too many hours working on a solution when running without the bp set.

1 Like

Nodes are successfully registered with Hub BUT script is always execute on one device only.

Following are the JSON
1:
{
“capabilities”:
[
{
“browserName”: “android”,
“version”: “4.4.2”,
“maxInstances”: 5,
“platform”: “ANDROID”,
“deviceName”: “226CF65ED0ABE221”
}
],
“configuration”:
{
“nodeTimeout”:120,
“cleanUpCycle”:2000,
“timeout”:2000000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4723/wd/hub”,
“maxSession”: 20,
“port”: 4723,
“host”: “127.0.0.1”,
“register”: true,
“registerCycle”: 5000,
“hub”: “127.0.0.1:4441/grid/register”,
“hubPort”: 4441,
“hubHost”: “localhost”,
“role”: “node”
}
}

2:
{
“capabilities”:
[
{
“browserName”: “android”,
“version”: “4.4.2”,
“maxInstances”: 5,
“platform”: “ANDROID”,
“deviceName”: “9EDCBB229B2DD02D”
}
],
“configuration”:
{
“nodeTimeout”:120,
“cleanUpCycle”:2000,
“timeout”:2000000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:3300/wd/hub”,
“maxSession”: 20,
“port”: 3300,
“host”: “127.0.0.1”,
“register”: true,
“registerCycle”: 5000,
“hub”: “127.0.0.1:4441/grid/register”,
“hubPort”: 4441,
“hubHost”: “localhost”,
“role”: “node”
}
}

Script capabilities:
For node 1:
@Parameters(value={“device_id1”, “device_id2”})
@BeforeSuite//The annotated method will be run before all tests in this suite have run.
public static WebDriver atStart(@Optional(“nnn”) String device_id1, String device_id2) throws InterruptedException, IOException
{

        System.out.println("in Samsung galaxy: "+device_id1);
        if ("226CF65ED0ABE221".equals(device_id1))//FOR SAMSUNG GALAXY NOTE
        {
            capabilities=new DesiredCapabilities();
           
            File app = new File(applicationPath);
            capabilities.setCapability("automationName", "Appium");
            capabilities.setCapability(CapabilityType.BROWSER_NAME, "android");
            capabilities.setCapability("deviceName", device_id1);
            //capabilities.setCapability("udid", device_id);
            capabilities.setCapability("platformVersion", "4.4.2");
            capabilities.setCapability(CapabilityType.PLATFORM,"ANDROID");
            capabilities.setCapability("platformName", "ANDROID");
            capabilities.setCapability("app", app.getAbsolutePath());
            capabilities.setCapability("appPackage", "com.avaamo.android.staging"); 
            capabilities.setCapability("appActivity", "com.avaamo.android.ui.LandingActivity"); 
            //setting new command timeout for selenium server
            capabilities.setCapability("newCommandTimeout", "2000000");//33.33 mins
            
        }

For Node 2:
if(“9EDCBB229B2DD02D”.equals(device_id2))
{
capabilities=new DesiredCapabilities();

            File app1 = new File(applicationPath);
            capabilities.setCapability("automationName", "Appium");
            capabilities.setCapability(CapabilityType.BROWSER_NAME,"android");
            capabilities.setCapability("deviceName",device_id2);
            //capabilities.setCapability("udid",device_id);
            capabilities.setCapability("platformVersion", "4.4.2");
            capabilities.setCapability(CapabilityType.PLATFORM,"ANDROID");
            capabilities.setCapability("platformName","ANDROID");
            capabilities.setCapability("app", app1.getAbsolutePath());
            capabilities.setCapability("appPackage", "com.avaamo.android.staging"); 
            capabilities.setCapability("appActivity", "com.avaamo.android.ui.LandingActivity"); 
            
            //setting new command timeout for selenium server
            capabilities.setCapability("newCommandTimeout", "2000000");//33.33 mins
        }

return driver = new AndroidDriver(new URL(“http://127.0.0.1:4441/wd/hub”), capabilities);

@Hassan_Radi @Appium_Master @rgonalo Can any one please suggest?

You are trying to select the node with deviceName, but the hub does not use this capability.
The hub only reads browserName, version, platform and applicationName. The other capabilities (deviceName, platformVersion, platformName, …) are Appium capabilities, not used by the hub.

In your case, you could use “applicationName” capability instead of “deviceName”:

Add the capability to each node JSON:

"applicationName": "226CF65ED0ABE221"
"applicationName": "9EDCBB229B2DD02D"

And add the capability to each test:

capabilities.setCapability("applicationName", device_id1);
capabilities.setCapability("applicationName", device_id2);
1 Like

Thanks @rgonalo !

I updated the files as you suggested.
Still the script is running on one device only. (for device id 1)
I cross checked the device ids and both are correct.
Can you please suggest?

Json file 1 configuration part:
{
“capabilities”:
[
{
“browserName”: “android”,
“version”: “4.4.2”,
“maxInstances”: 5,
“platform”: “ANDROID”,
“applicationName”: “226CF65ED0ABE221”
}
],

Json file 2 configuration part:
{
“capabilities”:
[
{
“browserName”: “android”,
“version”: “4.4.2”,
“maxInstances”: 5,
“platform”: “ANDROID”,
“applicationName”: “9EDCBB229B2DD02D”
}
],

Added
capabilities.setCapability(“applicationName”, device_id1);
capabilities.setCapability(“applicationName”, device_id2);
to the script.

@Appium_Master @rgonalo @Hassan_Radi Can you please help in?

I changed the port of a node that is not running and re run the script and unfortunately the script run on the same node that is not specified for.
The same node run on 4723 and 3000 ports though the json files are different for each.
I had started the nodes from cmd prompt. but later only changed jsons and restated appium gui (did not closed and reopened the appium GUI)

Surprising that hub only executes the script on one node though connected to both.

Appium log from the node where script is executed:
info: → POST /wd/hub/session {“desiredCapabilities”:{“app”:“D:\APKs\Automated_Projects\abc_staging.apk”,“appPackage”:“com.avaamo.android.staging”,“appActivity”:“com.avaamo.android.ui.LandingActivity”,“newCommandTimeout”:“2000000”,“platformVersion”:“4.4”,“automationName”:“Appium”,“browserName”:“Android”,“platformName”:“Android”,“deviceName”:“30345C56DC2000EC”,“applicationName”:“2636B827A05E6BB3”,“platform”:“ANDROID”}}

info: Client User-Agent string: Apache-HttpClient/4.3.4 (java 1.5)
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : applicationName, platform
info: [debug] Using local app from desired caps: D:\APKs\Automated_Projects\abc_staging.apk

I am sure something small is mismatched but I crosschecked the node files and the capabilities provided in script too.

hi @Appium_Master
my machine ip is like 192.168.X.X but public ip 125.X.X.X is mapped to my machine.if i am hosting any website in that machine, i can access that web page by typing public ip url(125.X.X.X/mywebsite).but when i mentioning public ip in my appium script it is saying like invalid address of the remote server. how to run my script in that machine from any where in the world or any network or any ip segment.How can i achive this?

Can anyone help here?

unable to download node.txt…that you have given.
Please Help.Thanks,
Ajit.

The Appium server seems to have removed the file or maybe it is experiencing some technical issue. Please copy/paste the next few lines in a text file:

{
“capabilities”:
[
{
“browserName”: “ANDROID”,
“device”: “LG Nexus5”,
“version”:“4.4.2”,
“maxInstances”: 1,
“platform”:“ANDROID”
}
],
“configuration”:
{
“cleanUpCycle”:2000,
“timeout”:10000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://localhost:4723/wd/hub”,
“maxSession”: 1,
“port”: 4723,
“host”: “localhost”,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4444,
“hubHost”: “localhost”
}
}

@Arvind_Patel @Hassan_Radi
I have configured my android devices to selenium grid with ports 4728 and 4730 below

node1.json
{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“5.0.1”,
“maxInstances”: 3,
“platform”:“ANDROID”,
“deviceName”:“ZX1D63ZXZ6”
}
],
“configuration”:
{

“nodeTimeout”:120,
“port”:4730,
“hubPort”:4444,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4730/wd/hub”,
“hub”: “127.0.0.1:4444/grid/register”,
“hubHost”:“127.0.0.1”,
“nodePolling”:2000,
“registerCycle”:10000,
“register”:true,
“cleanUpCycle”:2000,
“timeout”:30000,
“maxSession”:1

}
}

node2.json
{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“5.1”,
“maxInstances”: 3,
“platform”:“ANDROID”,
“deviceName”:“0aee8e8b02e4223e”
}
],
“configuration”:
{
“nodeTimeout”:120,
“port”:4728,
“hubPort”:4444,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4728/wd/hub”,
“hub”: “127.0.0.1:4444/grid/register”,
“hubHost”:“127.0.0.1”,
“nodePolling”:2000,
“registerCycle”:10000,
“register”:true,
“cleanUpCycle”:2000,
“timeout”:30000,
“maxSession”:1
}
}

My selenium grid hub is running on port 4444 And my appiium is on 4723 port

grid_configuration.json
{
“capabilities”:
[
{
“browserName”: “ANDROID”,
“version”:“5.0.1”,
“maxInstances”: 1,
“platform”:“ANDROID”
}
],
“configuration”:
{
“cleanUpCycle”:2000,
“timeout”:30000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4723/wd/hub”,
“host”: “127.0.0.1”,
“port”: “4723”,
“maxSession”: 1,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4444,
“hubHost”: “127.0.0.1”
}
}

This is my JSON . I have added this grid_config.json file path to appium setting to Selenium Grid Configuration file.

Now my two android devices are running on different port, right?

This is my java code

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;

//import java.net.ServerSocket;

public class sample_test extends initializtion{

AppiumDriver d1,d2;
@Test
public void two_driver(){

	DesiredCapabilities capabilities1= new DesiredCapabilities();
	capabilities1.setCapability("deviceName","Nexus");
	capabilities1.setCapability("platformVersion", "5.1");
	capabilities2.setCapability("appPackage",package name);          
	capabilities2.setCapability("appActivity", main activity);
	capabilities1.setCapability("udid", "0aee8e8b02e4223e");
	
	// capabilities.setCapability("appActivity", "com.whatsapp.Main");
	try {
		d1 = new AndroidDriver(new URL("http://127.0.0.1:4728/wd/hub"), capabilities1);
	} catch (MalformedURLException e) {
		// TODO Auto-generated catch block
		System.out.println("Not able to start application");
		e.printStackTrace();
	}
	d1.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	
	
	
	DesiredCapabilities capabilities2= new DesiredCapabilities();
	capabilities2.setCapability("deviceName","Moto G 2");
	capabilities2.setCapability("platformVersion", "5.0.1");
	//capabilities.setCapability("app",app.getAbsolutepath());
	capabilities2.setCapability("appPackage",package name);          
	capabilities2.setCapability("appActivity", main activity);
	capabilities2.setCapability("udid", "ZX1D63ZXZ6");
	

	try {
		d2= new AndroidDriver(new URL("http://127.0.0.1:4730/wd/hub"), capabilities1);
	} catch (MalformedURLException e) {
		// TODO Auto-generated catch block
		System.out.println("Not able to start application");
		e.printStackTrace();
	}
	d2.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	
}

}

But my application is running on only one device , why?
What went wrong here?

ok. got it … seems like that i messed up with driver capabilities here.
Thanks this tutorial help me a lot

Hi @cool18ap

Can you please share what fixed the problem and files in details that you implemented?

I am facing the same problem.

Thanks!

Hello , @Nitin_Thite i have created new driver for another device for another port
The issue in this line

d2= new AndroidDriver(new URL(“http://127.0.0.1:4730/wd/hub”), capabilities1);

I assigned capabilities of first driver to second.That was very silly mistake otherwise it was working fine

Has anyone tried using cucumber-jvm/junit/spring to run parallel tests? I have an existing framework that i would like to enhance with parallel test capability.

Hello,

  I successfully configured my selenium grid with appium. I successfully created to driver for two different android devices . Lets say d1 and d2 . now i want to maintain sink in between them means my driver does some operation using d1 and then after completing that another operation on driver d2. When i am doing operation on d2 another driver d1 should be ideal
  But when i am doing operation on 2nd driver then on first device the app is in background after switching to first device    

it gives me error that session is not valid.please help me out here, what should i do? should i implement multi-threading ? or is there any way to put first driver on ideal state while second is doing that operation ?

Has anyone managed to distribute the tests across available devices? This is a native grid functionality, but it doesnt seem to work well with Appium (as you can only run one device per session). A solution, preferably in java, would be helpful - or pointers, I am looking into it myself but seem to be stuck.

Hi Karthi,

Can you please provide me the steps to find my divece connected in grid console. I am trying for past theree days and i can’t able to see my device connected in the grid console. I followed the same steps but the command used,
node appium -a 192.168.48.71 -p 4723 --udid 4d00ce6e4a625139 -bp 5522 --nodeconfig C:/Program Files/Appium/nodeconfig.json
is not working. From which location we need to run this command. Please help me.

Regards,
B.Krishnaswamy.

Hi rgonalo,

Can you please provide me the steps to find my divece connected in
grid console. I am trying for past theree days and i can’t able to see
my device connected in the grid console. I followed the same steps but
the command used,
node appium -a 192.168.48.71 -p 4723 --udid 4d00ce6e4a625139 -bp 5522 --nodeconfig C:/Program Files/Appium/nodeconfig.json
is not working. From which location we need to run this command. Please help me.

Please tell me the correct steps from starting the selenuim server. Please tell the correct file path from which the command need to be execcuted.

Regards,
B.Krishnaswamy.

Hi @vasanthKS,
Checkout my video, may be it will resolve your issue


Thanks
Srikanth