Appium: Parallel execution on multiple devices - Failed to click on one device while happens in the other

12 Views Asked by At

Handling the appium driver is done with ThreadLocal object and in the set method - appium driver is set.

> private static ThreadLocal<AppiumDriver> tlDriver = new ThreadLocal();
> 
> 
> public static synchronized void setTLDriver(AppiumDriver driver) {
> tlDriver.set(driver);
>     }
> 
> public static synchronized AppiumDriver getTLDriver() {
> return (AppiumDriver)tlDriver.get();
>     }

Note: Capabilities are all set. I don't see any issues with that.

TestNG.xml

<suite name="Parallel - Smoke Suite" verbose="1" parallel="tests" configfailurepolicy="continue">
<test name="Dispatch">
    <classes>
        <class name="xxxx"/> //Points to the runner file
    </classes>
</test>
<test name="Messaging">
    <classes>
        <class name="yyyy"/>
    </classes>
</test>

Methods defined in the TestNG annotations (@BeforeSuite, @BeforeTest, @BeforeClass, @Before & @Test) are all being executed properly. I believe those coding part is not required to be shared.

Note: I haven't mentioned the thread-count in the testng.xml file - I'm setting that dynamically based on the device count in the Listeners file.

When the test execution happens, driver instance is created 'AppiumDriverInstance.getInstance().setDriver("workflow");' and in the subsequent steps context class is called where the driver is passed to the page classes in the below way:

Context.class

public class Context {

    private final ALScreenObjectManager alScreenObjectManager;
  
    public Context() throws IOException {
        System.out.println("Context thread"+Thread.currentThread().getId());
        System.out.println("Context Driver:::"+AppiumDriverInstance.getTLDriver());
        this.alScreenObjectManager = new ALScreenObjectManager(AppiumDriverInstance.getTLDriver());
      
    }
    public ALScreenObjectManager getAlScreenObjectManager(){
        return alScreenObjectManager;
    }
}

PageObjectManager.class public class ALScreenObjectManager {

private final AppiumDriver driver;
private AppDrawerPage appDrawerPage;

public ALScreenObjectManager(AppiumDriver driver) {
    this.driver = driver;
}

public AppDrawerPage appDrawerPage() {

return (appDrawerPage == null) ? appDrawerPage = new AppDrawerPage(driver) : appDrawerPage;

}

Now, when the control comes to executing each steps from the BDD, first two steps take for example: swiping clearning notifications actions are all done. But when the step to click on a icon, it happens in one device but fails to click on the other. I have cross verified with the locators, its the same.

Below is the step method that fails and throws 'Failed to click on the mobile element'

@Given("Driver launches app") public void driverLaunchesApp() throws IOException {

    testContext.getAlScreenObjectManager().appDrawerPage().tapAppName(Constant.APP_NAME);
}

public void tapAppName(String appName) {

    appiumCommandsBasePage.clickCommands().clickElement(By.xpath(this.appNameXpath.replace("{%s}", appName)));
}

public void clickElement(By mobileElement) { try {

        this.appiumDriver.findElement(mobileElement).click();
        LoggingManager.logger.info("Clicked the mobile element " + mobileElement + " element");
    } catch (Exception var3) {
       
        LoggingManager.logger.error(var3);
        Fail.fail("Failed to click the  " + mobileElement + " " + "element");
    }

}

Note: When I give the drive.findElement(mobileElemet).click(); - it performs the taps in both the device.

Driver flow is not happening correctly. But don't know why and where the issue occurs.

I tried handling the pageObjectManager.class by creating ThreadLocal object for each class as the current implementation is done in tertinary way.

other approach that I tried is: just directly passing the driver to the page ie. return new AppDrawerPage(driver). Still didnt help.

Note: Server is started only in 4723 port to run the tests in the connected devices.

From the logs I could see - two drivers are created 'AndroidDriver: on ANDROID (525c4d9a-552b-4e9b-970d-dd6ed3af1e86)' and 'AndroidDriver: on ANDROID (e8de588a-9128-428d-81d7-da7e84903b98)' . Device assigned with 'AndroidDriver: on ANDROID (525c4d9a-552b-4e9b-970d-dd6ed3af1e86)' driver runs throughout.But the driver with 'AndroidDriver: on ANDROID (e8de588a-9128-428d-81d7-da7e84903b98)' doesn't click on the visible element. And from the logs, it points the device in which execution is running well , I mean driver suddenly starts looking for the element in the other device and the below logs is shown. Capabilities {appium:adbPort: 5037, appium:appActivity: com.trimble.ttm.routemanife..., appium:appPackage: com.trimble.ttm.routemanifest, appium:autoGrantPermissions: true, appium:automationName: uiautomator2, appium:chromeDriverPort: 62047, appium:clearDeviceLogsOnStart: true, appium:databaseEnabled: false, appium:desired: {adbPort: 5037, appActivity: com.trimble.ttm.routemanife..., appPackage: com.trimble.ttm.routemanifest, autoGrantPermissions: true, automationName: uiautomator2, chromeDriverPort: 62047, clearDeviceLogsOnStart: true, deviceName: androidDevice, mjpegServerPort: 62045, nativeWebScreenshot: true, newCommandTimeout: 600, orientation: LANDSCAPE, platformName: ANDROID, systemPort: 62046, udid: R52R70JCTEB}, appium:deviceApiLevel: 33, appium:deviceManufacturer: samsung, appium:deviceModel: SM-T570, appium:deviceName: R52R70JCTDB, appium:deviceScreenDensity: 320, appium:deviceScreenSize: 1920x1200, appium:deviceUDID: R52R70JCTDB, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:mjpegServerPort: 62045, appium:nativeWebScreenshot: true, appium:networkConnectionEnabled: true, appium:newCommandTimeout: 600, appium:orientation: LANDSCAPE, appium:pixelRatio: 2, appium:platformVersion: 13, appium:statBarHeight: 48, appium:systemPort: 62046, appium:takesScreenshot: true, appium:udid: R52R70JCTEB, appium:viewportRect: {height: 1152, left: 0, top: 48, width: 1920}, appium:warnings: {}, appium:webStorageEnabled: false, platformName: ANDROID} Session ID: 525c4d9a-552b-4e9b-970d-dd6ed3af1e86

0

There are 0 best solutions below