Issue
I'm unable to find an element (UiObject2
) using UiAutomator within my androidTest. I obtained UiDevice instance and try to find the object with this:
MY_UI_DEVICE.findObject(By.res(CURRENT_PACKAGE, id));
CURRENT_PACKAGE
is the package of my app MY_UI_DEVICE.getCurrentPackageName()
. I tried also with this one:
MY_UI_DEVICE.wait(Until.findObject(By.res(CURRENT_PACKAGE, id)), 10000);
I can see the app is waiting for 10 seconds on the right screen (where the desired object persists), but after timeout it fails to find it and test fails. It always fails on emulator (API 23), but rarely works good on a real device (API 25).
When I debug the code I could see that manually I could obtain the right element by calling sequence of getChild(index)
methods on AccessibilityNodeInfo
but in the runtime it still fails even the app is waiting on the right screen where I expect the specific element.
I was playing with different UiDevice's functions, but none of the helped and I'm out of ideas, so any help will be appreciated.
Solution
There were 2 issues with my tests:
- The first problem was in getting / initialising
UiDevice
instance in static block (as a static field in util class). I moved it into@Before
and it helped to resolve the issue partially. - Another problem was occurring while searching for an element using a package name obtained from the
UiDevice
. I replaced getting package withInstrumentationRegistry.getTargetContext().getPackageName();
as it's done in google samples.
Answered By - Luke
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.