Appium grid: Parallel Execution, Script runs only on one device

Hi All,

Tried to setup appium grid and node. but script runs only on first device. Can anyone help me here. ? Please provide a solution for this.

Thank you in advance.

Here are the details of my configurations.

nodeconfg.json:

{
“capabilities”:
[
{

“deviceName”:“Nexus 6P API 33”,
“platformVersion”:“13.0”,
“maxInstances”: 1,
“platformName”:“Android”

}
],
“configuration”:
{
“cleanUpCycle”:2000,
“timeout”:20000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4724/wd/hub”,
“maxSession”: 1,
“port”: 4724,
“host”: “127.0.0.1”,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4444,
“hubHost”: “127.0.0.1”
}
}

nodeconfig1.json:

{
“capabilities”:
[
{

“deviceName”: “pixel 4a”,
“platformVersion”:“13.0”,
“maxInstances”: 1,
“platform”:“Android”
}
],
“configuration”:
{
“cleanUpCycle”:2000,
“timeout”:10000,
“proxy”: “org.openqa.grid.selenium.proxy.DefaultRemoteProxy”,
“url”:“http://127.0.0.1:4727/wd/hub”,
“maxSession”: 1,
“port”: 4727,
“host”: “127.0.0.1”,
“register”: true,
“registerCycle”: 5000,
“hubPort”: 4444,
“hubHost”: “127.0.0.1”
}
}

Base file:

package testng;

import java.io.File;
import java.net.MalformedURLException;

import java.net.URL;
import java.time.Duration;

import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;

import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import io.appium.java_client.service.local.AppiumServiceBuilder;

public class base {

public AndroidDriver driver;

public AppiumDriverLocalService service;
public WebDriverWait wait;


@BeforeClass
@Parameters({"deviceName", "platformVersion"})
public void ConfigureAppium(String deviceName, String platformVersion) throws MalformedURLException
{
	
	
	
	
    System.out.println("     \n");
    System.out.println("------------------\u001B[34mTEST RESULTS--------------------");

    System.out.println("\u001B[32m"); 
    
    System.out.println("\b1. Appium Server Started - PASS\n");
    
    
    
    DesiredCapabilities caps = new DesiredCapabilities();
  //  caps.setCapability("Udid", "emulator-5554");
    caps.setCapability("deviceName", deviceName);
    caps.setCapability("platformVersion", platformVersion);
    caps.setCapability("platformName", "Android");
    caps.setCapability("automationName", "UiAutomator2");
   // adb shell dumpsys window | grep -E 'mCurrentFocus'
    caps.setCapability("app", "");
    caps.setCapability("appPackage", "");
    caps.setCapability("appActivity","");
    caps.setCapability("skipUnlock","true");
    caps.setCapability("noReset","true");
    
    
  driver = new AndroidDriver(new URL("http://127.0.0.1:4444/wd/hub"),caps);
    
   
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(50000000));

    
	
	System.out.println("2. ioki App Installed on device - PASS\n");




	
//	driver = new AndroidDriver(new URL(" http://0.0.0.0:4723"),options);
	driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(500));


 
	

	

}

@AfterClass
public void tearDown() {
	
     driver.quit();
	
	//Stop server
	//service.stop();
	System.out.println("\u001B[32m"); 
	System.out.println("14. Appium Server Stopped - PASS\n");
	
	
}

}

Testng xml file:

Cmds used:

Hub: java -jar path to/selenium-server-standalone-3.141.59.jar -role hub
appium server 1: appium --session-override --nodeconfig path to/nodeconfig.json -p 4724 --base-path /wd/hub
appium server 2: appium --session-override --nodeconfig path to/nodeconfig1.json -p 4727 --base-path /wd/hub

and next i am passing my test scripts file.

  1. Hub configuration is done successfully with 2 nodes
  2. Script runs only on one device.

Logs:

Appium server 1:
g] [Logcat] Stopping logcat capture
[debug] [ADB] Removing forwarded port socket connection: 8200
[debug] [ADB] Running ‘/users/veenasonar/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp:8200’
[AndroidUiautomator2Driver@f1b4 (29cd95c2)] Restoring hidden api policy to the device default configuration
[debug] [ADB] Running ‘/users/veenasonar/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell ‘settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy’’
[debug] [AppiumDriver@a529] Event ‘quitSessionFinished’ logged at 1697628671043 (13:31:11 GMT+0200 (Central European Summer Time))
[debug] [AppiumDriver@a529] Received response: null
[debug] [AppiumDriver@a529] But deleting session, so not returning
[debug] [AppiumDriver@a529] Responding to client with driver.deleteSession() result: null
[HTTP] <-- DELETE /wd/hub/session/29cd95c2-43f5-43cf-aa3f-178eadf13006 200 226 ms - 14
[HTTP]
[debug] [Instrumentation] .
[debug] [Instrumentation] Time: 24.075
[debug] [Instrumentation]
[debug] [Instrumentation] OK (1 test)
[debug] [Instrumentation] The process has exited with code 0
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[debug] [AppiumDriver@a529] Calling AppiumDriver.getStatus() with args: []

Appium server 2:

] [AndroidUiautomator2Driver@177d (d79f5078)] Checking whether app is actually present
[debug] [AndroidUiautomator2Driver@177d (d79f5078)] Deleting UiAutomator2 session
[debug] [AppiumDriver@2d59] Event ‘newSessionStarted’ logged at 1697628639664 (13:30:39 GMT+0200 (Central European Summer Time))
[debug] [AppiumDriver@2d59] Encountered internal error running command: Error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. Read https://developer.android.com/studio/command-line/variables for more details
[debug] [AppiumDriver@2d59] at requireSdkRoot (/Users/veenasonar/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-adb/lib/helpers.js:81:11)
[debug] [AppiumDriver@2d59] at Function.createADB (/Users/veenasonar/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-adb/lib/adb.js:80:37)
[debug] [AppiumDriver@2d59] at Object.createBaseADB (/Users/veenasonar/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/android-helpers.js:131:20)
[debug] [AppiumDriver@2d59] at Object.getDeviceInfoFromCaps (/Users/veenasonar/.appium/node_modules/appium-uiautomator2-driver/node_modules/appium-android-driver/lib/android-helpers.js:222:29)
[debug] [AppiumDriver@2d59] at AndroidUiautomator2Driver.startUiAutomator2Session (/Users/veenasonar/.appium/node_modules/appium-uiautomator2-driver/lib/driver.js:349:40)
[debug] [AppiumDriver@2d59] at AndroidUiautomator2Driver.createSession (/Users/veenasonar/.appium/node_modules/appium-uiautomator2-driver/lib/driver.js:240:18)
[debug] [AppiumDriver@2d59] at AppiumDriver.createSession (/usr/local/lib/node_modules/appium/lib/appium.js:346:35)

It will not work. This variable should be ThreadLocal variable.

@Aleksei Thank you for the response. i will write threadlocaldriver class and check it.