android / testing-samples

A collection of samples demonstrating different frameworks and techniques for automated testing
Apache License 2.0
9.15k stars 3.61k forks source link

Native NullReferenceException thrown on ByMatcher.java:142 when using Android 4.4.x devices. #134

Open serg64 opened 7 years ago

serg64 commented 7 years ago

Hi everyone,

I'm trying to include an Android 4 device for my Automation suite, but for some reason I'm seeing NullReference exceptions when interacting with certain textboxes in an app under test but ONLY when using pre-Android 5 devices.

The stack traces I'm seeing are as follows:

java.lang.NullPointerException at android.support.test.uiautomator.ByMatcher.findMatches(ByMatcher.java:142) at android.support.test.uiautomator.ByMatcher.findMatches(ByMatcher.java:111) at android.support.test.uiautomator.ByMatcher.findMatches(ByMatcher.java:96) at android.support.test.uiautomator.UiDevice.findObjects(UiDevice.java:171)

when using FindObjects method to look for the textbox in question or:

java.lang.NullPointerException at android.support.test.uiautomator.ByMatcher.findMatches(ByMatcher.java:142) at android.support.test.uiautomator.ByMatcher.findMatches(ByMatcher.java:111) at android.support.test.uiautomator.ByMatcher.findMatch(ByMatcher.java:72) at android.support.test.uiautomator.UiDevice.hasObject(UiDevice.java:154) at android.support.test.uiautomator.Until$2.apply(Until.java:55) at android.support.test.uiautomator.Until$2.apply(Until.java:52) at android.support.test.uiautomator.WaitMixin.wait(WaitMixin.java:40) at android.support.test.uiautomator.WaitMixin.wait(WaitMixin.java:34) at android.support.test.uiautomator.UiDevice.wait(UiDevice.java:187)

when using phone.wait(Until.hasObject(By.res(identifier)), timer); for example.

Any clues on how to bypass this issue? I'm not sure if our App developers are doing something strange with these textboxes or early Android versions are just poorly supported by UiAutomator.

Bald-e commented 7 years ago

I too am running into this issue, it seems very random (but only on API 19 and 18). I have a set of 20 tests that all use phone.wait(Until.hasObject(By.text("string")), TIMER); , and sometimes they all pass (about a quarter of the time) but most of the time one (or more) of the tests will throw a null pointer exception. My production machine seems to favor the first half of the tests and runs the second half fine, while our pipeline runners favor the second half and run the first half fine. I am having to implement a try-catch-retry block everywhere that i use wait(Until . If this does not work, we are going to have to ditch UIAutomator :( .