Connecting appium server to selenium grid for android


#1

hi,

Is there a way to integrate appium with selenium grid?

i am executing my scripts on android devices.using windows 7 and java.

any inputs would be highly appreciated.

Thanks and regards,
M.Karthik


Appium parallel execution in android devices
Running multiple instances of Appium server for Android and IOS device
Parellel testing on multiple android devices
Parallel Script Execution using Appium
How to test with multiple devices around 30 device parallel?
Calling scenario
#2

I have not used it before, so I am not sure if it would actually work or not :smile:, but there is a Serer configuration specifically for that:

–node-config —> Configuration JSON file to register appium with selenium grid

Give it a try and let me know how it works.


#3

@Hassan_Radi,

i was able to see that mobile device got registered as node to grid and the same showed up in grid console. But the problem is when i tried to execute the script it failed saying that appium could not be started at 4723. in my code i am launching the appium server and then actions are performed on the device. I think there is a problem as node is already launched at the same port as per the nodeconfig.json.


#4

Hi All,

Any one has any breakthrough on this? Any suggestions?

Thanks and regards,
M.Karthik


#5

Hey, I got to the same point where my node is configured with Appium server and selendroid standalone both are registered to the selenium grid. The problem is like described - both the appium and selendroid are using the same port which eventually returns an error because they are using the same port… I am still struggling to figure this out, but I will be happy if any one gots through this issue by now and can commit.


#6

Try to launch Appium in other port with -p option:
node . --nodeconfig appium_node.json -p 4725

You must also change ‘url’ and ‘port’ parameters in the node config file (appium_node.json) with the new port value:
“url”:“http://host_name_appium_server_or_ip-address_appium_server:4725/wd/hub”,
“port”: 4725,

You can see more config parameters in http://appium.io/slate/en/master/?java#selenium-grid


#7

I have configured appium with selenium grid and works fine.
only you have to start new node for each device and register it with grid server.
Start server: java -jar selenium-server-standalone-2.43.0.jar -role hub
Register node: appium -p -U --nodecofig


#8

Even I am stuck on the last step in launching Appium Grid on 2 Android devices that are connected to the same Windows 7 machine. Your inputs will really help in moving forward:

Steps that I have done so far:

Clonned the Appium and started the server on 2 different ports
Created 2 different json files for each port and started Appium server using these files
Now trying to deploy the selendroid test app on both device at same
time.
One one device it’s being added successfully but on other it error’s out with a message

“uiautomator quit before it successfully launched”

Although the Grid console shows both port connected for DefaultRemoteProxy (version : 1.2.0)
id : http://127.0.0.1:4730, OS : ANDROID and the second one id : http://127.0.0.1:4728, OS : ANDROID

node1.json

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

node2.json

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

Let me know if I am missing something or any more configuration required?

Thanks in Advance


#9

Hi Team,

Any help in the same as the hub is listening to both Ports and both devices are connected to one machine but while executing the code when I run it serially it gets executed on one device only and when I run the code parallelly then it throws exception for “uiautomator quit before it successfully launched”

Thanks


#10

My Json looks like

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“4.4”,
“maxInstances”: 3,
“platform”:“ANDROID”,
“deviceName”:“emulator-5554”
}],

"configuration":

{
“nodeTimeout”:120,
“port”:4723,
“hubPort”:4444,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4723/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
}
}

i used 3 more json file(only node url and device changed ) for more devices and working fine with me


#11

Hi

here is the link that explains about the grid configuration along with the screenshots of the grid setup

Thanks
Sravan


#12

Even i was stuck on same issue for long.

you might creating new driver instance for each node so iit’ll will stop existing running session when new session request open with new instance.
thats why you are not able to run session parallel on both devices.

Solution:

  1. Take parameter from xml file and set capability as per device
  2. Define appium with grid server url (hub url and port)

!! Happy testing …


#13

Even I am facing the same issue. My node config files are:

file 1

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“4.4.2”,
“maxInstances”: 3,
“platform”:“ANDROID”,
“deviceName”:“emulator-5554”
}
],
“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
}
}

File 2

{
“capabilities”:
[
{
“browserName”: “Android”,
“version”:“4.4.2”,
“maxInstances”: 3,
“platform”:“ANDROID”,
“deviceName”:“emulator-5556”
}
],
“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

}
}

Code Written:

public static AndroidDriver driver=null;

@Test(dataProvider="getData")
public void searchTest(String b) throws MalformedURLException, InterruptedException{
	
	if(driver==null){
	
	DesiredCapabilities cap = null;
	
	System.out.println(b);
		if(b.equals("mobile1")){
			
	
		cap	= new DesiredCapabilities();
		cap.setCapability(CapabilityType.BROWSER_NAME, "");
		cap.setCapability("deviceName","emulator-5556");
		cap.setCapability("platformVersion", "4.4.2");
		cap.setCapability("platformName","Android");
		
		cap.setCapability("appPackage",
					"com.android.contacts");
		cap.setCapability("appActivity",
					"com.android.contacts.activities.DialtactsActivity");
	
	}else if(b.equals("mobile2")){
		
		cap	= new DesiredCapabilities();
		
		cap.setCapability(CapabilityType.BROWSER_NAME, "");
		cap.setCapability("deviceName","emulator-5554");
		cap.setCapability("platformVersion", "4.4.2");
		cap.setCapability("platformName","Android");
	      
		cap.setCapability("appPackage",
				"com.android.contacts");
	cap.setCapability("appActivity",
				"com.android.contacts.activities.DialtactsActivity");
		
	}
	
		driver = new AndroidDriver(new URL("http://localhost:4444/wd/hub"), cap);
	driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
	driver.quit();
	}
}

@DataProvider(parallel=true)
public Object[][] getData(){
	
	Object data[][] = new Object[2][1];
	
	data[0][0] = "mobile1";
	
	data[1][0] = "mobile2";
	
	return data;
	
	
}

Every time the code is being executed on a single device where as I have connected two real device with same machine and started the hub as well on same machine:

Hub Started with:

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

Started node 1:

C:\Users\ishita\Desktop\Appium\Appium2\node_modules\appium\bin>node appium --nodeconfig c:/softwares/jars/appiumnode1.json -p 4728

Started node 2:

C:\Users\Selenium\Desktop\Appium\Appium\node_modules\appium\bin>node appium --nodeconfig c:/softwares/jars/appiumnode2.json -p 4730

Please suggest me the fix as I need to submit a POC on the same UGENTLY !!!

Thanks for the help.

Ishita


#14

Config. looks fine. Try to run and pass parameter from xml file and make parallel=tests
like:
suite name=“VK Suite” parallel=“tests” thread-count=“5” verbose="1

test name=“firstTest on fiest mobile”
parameter name=“DeviceID” value=“TA9asdsda33071OQ”
classes
class
name=“vKSocialSite.VKTest”
classes
test
test name="firstTest on second mobile "
parameter name=“DeviceID” value=“AN45577”
classes
class
name=“sof_app.SOFTest”
classes
test
suite

<> </> syntex removed


#15

Hi,

I am trying to run two scripts on different mobile(Nexus and Samsung).

I have 2 nodeconfig.json files each having the config of devices. I am starting 2 appium servers with different node config specified in general settings. When i check the grid console i see that both the devices are appearing as Node.

In testng.xml i have specified different tests. When they are executed sequentially all the scripts are executed on a single mobile even though desired capabilities mentioned in the test script are different.

I am currently using :
appium: 1.2.0.0
OS windows
Android devices: Nexus and Samsung
Device OS: 5.0 and 4.3

Please let me know if i am missing any thing which is making the script to run on same device even though the desired capabilities mentioned are different in each test script.

JSON:

File 1:
{
“capabilities”:
[
{
“browserName”: “chrome”,
“version”: “4.3”,
“maxInstances”: 1,
“platform”: “ANDROID”,
“deviceName”: “m0”
}
],
“configuration”:
{
“nodeTimeout”:120,
“port”:4723,
“hubPort”:4444,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4723/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
}
}

File 2:
{
“capabilities”:
[
{
“browserName”: “chrome”,
“version”: “5.0”,
“maxInstances”: 1,
“platform”: “ANDROID”,
“deviceName”: “hammerhead”
}
],
“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
}
}

I have attached the test scripts and testng.xml info.txt (7.3 KB) for reference. Any help would be appriciated.

Thanks and regards,
M.Karthik


#16

@Hassan_Radi, @Arvind_Patel,

Any suggestions on this?

Thanks and regards,
M.Karthik


#17

Hi All,

Configuration to run test parallel on multiple device:

Prerequisite: 1. Start selenium grid on 127.0.0.1
2. Register multiple appium node on grid with different port

XML file:

suite name=“Logintestsuite:” parallel=“tests” thread-count=“5” verbose="1

test name=“firstTest on fiest mobile”
parameter name=“DeviceID” value=“TA9asdsda33071OQ”
classes
class
name=“package.testfilename”
classes
test
test name="firstTest on second mobile "
parameter name=“DeviceID” value=“AN45577”
classes
class
name=“package.testfilename”
classes
test
suite

<> </> syntex removed

Test File:

package arvind;

public class LoginTest{

public String appionlicatPath = "//....apk";

public String emulator_device_1 ="emulator-5554";
public String emulator_device_2 ="emulator-5556";
public String MobileDevice_1 ="D1";
public String MobileDevice_2 ="D2";
public static  DesiredCapabilities capabilities = new DesiredCapabilities(); 

	

@Parameters("DeviceID")
@BeforeTest
public void startAppium(String DeviceID) throws MalformedURLException, InterruptedException{
	
	if(DeviceID.equalsIgnoreCase("mobile1")){
		setcapabilities(appionlicatPath, MobileDevice_1,"Appium");
	         }
	
	if(DeviceID.equalsIgnoreCase("mobile2")){
		setcapabilities(appionlicatPath, MobileDevice_2,"Appium");
	         }
	
	if(DeviceID.equalsIgnoreCase("first")){
		setcapabilities(appionlicatPath, emulator_device_1,"Appium");
	         }
		
	if(DeviceID.equalsIgnoreCase("second")){
		setcapabilities(appionlicatPath, emulator_device_1,"Appium");
	         }
	if(DeviceID.equalsIgnoreCase("chrome")){
		setChromeCapabilities(emulator_device_1,"Appium");
	         }
	
	
	
	driver =  new AndroidDriver(new URL("http://127.0.0.1:4444/wd/hub"),capabilities);
	driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
	
	
}

@ AfterTest(alwaysRun= true)
public void tearDown(){
	driver.quit();
}

   @Test()
   public void loginTest() throws InterruptedException{
 Thread.sleep(10000L);
   homepage.loginButton();
   registerpage.login("[email protected]", "abcd");
   Assert.assertTrue("User not loggedIn", homepage.isTestPresent("Log Out"));	


public void setcapabilities(String apppath,String device,String automation){
	File app = new File(apppath); 
	capabilities.setCapability("deviceName", device);
	capabilities.setCapability("automationName",automation);
	capabilities.setCapability("appium-version", "1.2.2");
	capabilities.setCapability("platformName", "Android");
	capabilities.setCapability("platformVersion", "4.4.2");			
        capabilities.setCapability("app", app.getAbsolutePath());
    
}

hope this is helpful for appium grid setup.
Question welcomed :smile:


#18

Hi @Arvind_Patel,

I tried below mentioned steps:

1)Launch grid at localhost:4444
2)Launch appium with nodeConfig.json and start it i.e. appium started at 127.0.0.1:4723
3)Launch appium with nodeConfig1.json and start it i.e. appium started at 127.0.0.1:4728

Prepare testng.xml as shown below:

suite name=“Suite” parallel=“tests” thread-count=“5” verbose=“1”
test name=“Test1”
parameter name=“Device_ID” value=“085d3b920c928938”
classes
class name=“Test.ZoomPinch”
classes
test
test name=“Test2”
parameter name=“Device_ID” value=“4df70d325d884031”
classes
class name=“Test.Calculator”
classes
test
suite

Have beforemethod parametarized:

@Parameters (“Device_ID”)
@BeforeMethod
public void setUp(String device)throws MalformedURLException {
System.out.println(device);
switch(device)
{
case “4df70d325d884031”:
capabilities = new DesiredCapabilities();
//capabilities.setCapability(CapabilityType.BROWSER_NAME, “Android”);
//capabilities.setCapability(“deviceName”, “Default”);
capabilities.setCapability(CapabilityType.VERSION, “4.3”);
capabilities.setCapability(“browserName”, “chrome”);
//capabilities.setCapability(CapabilityType.PLATFORM, “Android”);
capabilities.setCapability(“deviceName”, “m0”);
capabilities.setCapability(“platformName”, “Android”);
//capabilities.setCapability(capabilityName, value)
//capabilities.setCapability(“appPackage”, “com.google.android.apps.maps”);
//capabilities.setCapability(“appActivity”, “com.google.android.maps.MapsActivity”);
break;
default: System.out.println(“no mob exists…”);
break;
}
//driver= new AppiumDriver(new URL(“http://127.0.0.1:4723/wd/hub”), cap); // (you can get it from
// apk info app)

                    driver   = new AppiumDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
}

@Parameters(“Device_ID”)
@BeforeMethod
public void setup(String device)throws Exception
{
switch(device)
{
case “085d3b920c928938”:
capabilities = new DesiredCapabilities();
//capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);
//capabilities.setCapability(“browserName”, “Chrome”);
capabilities.setCapability(CapabilityType.VERSION, “5.0”);
capabilities.setCapability(“deviceName”, “hammerhead”);
capabilities.setCapability(“platformName”, “Android”);
capabilities.setCapability(“appPackage”, “com.davemorrissey.labs.subscaleview.sample”);
capabilities.setCapability(“appActivity”, “com.davemorrissey.labs.subscaleview.sample.MainActivity”);
break;
default:System.out.println(“no mob…exists”);
break;
}
driver= new AppiumDriver(new URL(“http://127.0.0.1:4723/wd/hub”), capabilities);

      //driver = new AppiumDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
}

When executed, out of 2 tests 1 of them fail…
when only Test2 is executed, even though device id is mentioned it is getting executed on another device.

Please suggest what needs to be done…

Thanks and regards,
M.Karthik


#19

Hi @karthik_holla,

You are launching the second test directly on the first appium server (port 4723):

You must use the hub url:

driver = new AppiumDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

And the hub will redirect your test to the properly appium server depending on “browserName”, “version” and “platform” capabilities.


#20

@rgonalo sorry…my mistake…thank you for correcting me… :slight_smile: will try this and verify…


Has anyone successfully run test scripts parallel in two or more Android devices?