question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to run tests in parallel androidx.test.uiautomator.StaleObjectException

See original GitHub issue

The problem

I am trying to run the tests in parallel, the app launches and performs some actions but for a specific screen, the test fail in 1 device and continues correctly in the 2nd device, i get the following error:

androidx.test.uiautomator.StaleObjectException

Weird thing here is that if i change the TestNG tag parallel=tests by parallel=class or methods or anyother the execution does not fail, but the execution starts and finishes in 1 device and then it starts in the 2nd device, but i would like to start the execution parallelly in the two devices, as i said it only fails while trying to click 1 specific item on the screen Thanks in advanced!

Environment

  • Appium version (or git revision) that exhibits the issue: 1.15.1
  • Last Appium version that did not exhibit the issue (if applicable): 1.15.1
  • Desktop OS/version used to run Appium: macos mojave 10.14.5
  • Node.js version (unless using Appium.app|exe): 12.11.1
  • Npm or Yarn package manager: 6.12.0
  • Mobile platform/version under test: ANDROID
  • Real device or emulator/simulator: Xiaomi REdmi s2, Lg V20, Galaxy S9

Details

If necessary, describe the problem you have been experiencing in more detail.

Link to Appium logs

org.openqa.selenium.StaleElementReferenceException: androidx.test.uiautomator.StaleObjectException For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:17:03’ System info: host: ‘sprout24.local’, ip: ‘fe80:0:0:0:1064:76eb:12e1:5b9e%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.14.5’, java.version: ‘1.8.0_162’ Driver info: io.appium.java_client.android.AndroidDriver Capabilities {appActivity: com.xxxx.android.activ…, appPackage: com.xxxx.android, automationName: uiautomator2, clearSystemFiles: true, databaseEnabled: false, desired: {appActivity: com.xxxx.android.activ…, appPackage: com.xxxx.android, automationName: uiautomator2, clearSystemFiles: true, deviceName: LGH910532e4945, deviceReadyTimeout: 260, fullReset: false, newCommandTimeout: 6000, noReset: true, platformName: android, platformVersion: 7, skipDeviceInitialization: true, systemPort: 4733, udid: LGH910532e4945, uiautomator2ServerLaunchTimeout: 20000}, deviceApiLevel: 24, deviceManufacturer: LGE, deviceModel: LG-H910, deviceName: LGH910532e4945, deviceReadyTimeout: 260, deviceScreenDensity: 640, deviceScreenSize: 1440x2560, deviceUDID: LGH910532e4945, fullReset: false, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, newCommandTimeout: 6000, noReset: true, pixelRatio: 4, platform: LINUX, platformName: Android, platformVersion: 7.0, skipDeviceInitialization: true, statBarHeight: 96, systemPort: 4733, takesScreenshot: true, udid: LGH910532e4945, uiautomator2ServerLaunchTimeout: 20000, viewportRect: {height: 2296, left: 0, top: 96, width: 1440}, warnings: {}, webStorageEnabled: false} Session ID: e8ecd20f-032a-44a2-ad62-65b909ce895f at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:41) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285) at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45) at io.appium.java_client.MobileElement.execute(MobileElement.java:1) at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1) at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84) at PageObjects.HomeScreenInsta.clickFollowersBtn(HomeScreenInsta.java:56) at TestCases.GetAllUsers.getAllUserAccounts(GetAllUsers.java:71) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:584) at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:172) at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46) at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:804) at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:145) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128) at java.util.ArrayList.forEach(ArrayList.java:1257) at org.testng.TestRunner.privateRun(TestRunner.java:770) at org.testng.TestRunner.run(TestRunner.java:591) at org.testng.SuiteRunner.runTest(SuiteRunner.java:402) at org.testng.SuiteRunner.access$000(SuiteRunner.java:41) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:443) at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:67) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

This is my testng file

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" >
<suite name="Smoke" thread-count="2" parallel="tests">
    <listeners>
       <listener class-name="resources.Listeners"/>
       <!-- <listener class-name="resources.ExtentReporterNG" />-->
    </listeners>
<test name="LG_V20"  >
        <parameter name="deviceName" value="LGH910532e4945"></parameter>
        <parameter name="platformVersion" value="7"></parameter>
        <parameter name="port" value="4733"></parameter>
        <classes>
            <class name="TestCases.GetAllUsers">
              </class>
        </classes>
    </test>
    <test name="RedmiS2" >
        <parameter name="deviceName" value="ad789708"></parameter>
        <parameter name="platformVersion" value="9"></parameter>
        <parameter name="port" value="4734"></parameter>
        <classes>
            <class name="TestCases.GetAllUsers">
            </class>
        </classes>
    </test>
</suite>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
KazuCocoacommented, Nov 11, 2019
0reactions
hadrianjmnz90commented, Nov 12, 2019

I found the solution, public AndroidDriver<MobileElement> driver; was static, so i only removed the declaration, but anyways it was good to change the systemport and the appium port. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

androidx.test.uiautomator.StaleObjectException - Support
Hi Guys, I am getting stale element exception on android device. There is one spinner need to click on it new window will...
Read more >
StaleObjectException - Android Developers
Artifact: androidx.test.uiautomator:uiautomator ... A StaleObjectException exception is thrown when a UiObject2 is used after the underlying android.view.
Read more >
Unable to run parallel tests with Selenium Grid(Appium) in ...
I want to execute test script on multiple devices(Android). when i run my java class with JUnit i am able to execute in...
Read more >
Class androidx.test.uiautomator.StaleObjectException
A StaleObjectException exception is thrown when a UiObject2 is used after the underlying android.
Read more >
Appium Запуск тестов параллельно на iOS Android
StaleElementReferenceException: android.support.test.uiautomator. ... <suite name="Default Suite" verbose="1" parallel="tests"> <test ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found