Run automated tests in parallel on desktop and mobile browser

39 Views Asked by At

We have couple of applications which are desktop(PC) , Mobile applications, so planned to create unique test automation framework in java

we have created a framework to support both desktop and mobile platforms using below tech stack

Selenium webdriver, appium, java client, testNG, allure , java 17

but i am facing issues while running tests in parallel , only one tests run on desktop browser the other tests open in mobile but it sits in idle state without running tests

baseTests.java

 Boolean isMobile= (Boolean) deviceInfo.get("isMobile");
    
 Boolean isHeadLess = (Boolean) deviceInfo.get("isHeadless");
    
 if (Objects.isNull(DriverManager.getDriver())) {
    
     if (isMobile) {
        serverManager.startServer();
        deviceName = deviceInfo.getString("devicename");
    
        String avd = deviceInfo.getString("avd");
    
        String udid = deviceInfo.getString("udid");
    
        String platformVersion = deviceInfo.getString("platformVersion");
    
        Boolean isEmulator = (Boolean) deviceInfo.get("isEmulator");
    
        URL url = new ServerManager().getServer().getUrl();
    
        RemoteWebDriver driver=DriverFactory.initializeMobileDriver(MobilePlatformName.valueOf(platformType.toUpperCase()), deviceName, udid, isEmulator, isHeadLess,browserName, url);
    } else {
     RemoteWebDriver driver=DriverFactory.initializeWebDriver(WebBrowserName.valueOf(browserName.toUpperCase()), isHeadLess);
}
}

here i am using 'RemoteWebDriver' to refer both selenium webdriver and appium driver

DriverManager.java

     private static final ThreadLocal<RemoteWebDriver>          threadLocalDriver = new ThreadLocal<>();
    
         public static synchronized RemoteWebDriver getDriver() {
    
            return threadLocalDriver.get();
    
          }
    
   public static synchronized void setAppiumDriver(RemoteWebDriver driver) {
    if (Objects.nonNull(driver)) {
        threadLocalDriver.set(driver);
    }
  }
public static synchronized void unload() {
threadLocalDriver.remove();
}

Testsclass.java

public class SearchTest extends BaseTest{

public test(){

driver= DriverManager.getDriver();

if (PlatformUtils.isMobile(driver)) {

googleSearch()

Else{

googleSearch()

}

}

}

If I use

if (PlatformUtils.isMobile(driver)) {

googleSearch()

Else{

googleSearch()
} 

This way tests run on both the platforms but

If I use simply

googleSearch()

Then both desktop and mobile browser will open but only one test run on desktop but mobile tests just stay idle without moving

Is it right the way using of remotewedriver to refer both selenium web drover and appium driver ?

If I use above way so that I can use common driver and common code to tests ,instead of using different appium driver and selenium driver separately

Can someone help me to get the correct approach to handle both mobile and desktop(pc) ?

0

There are 0 best solutions below