在Android上使用UiAutomator测试React Native

在Android上使用UiAutomator测试React Native,android,react-native,android-uiautomator,Android,React Native,Android Uiautomator,我正在尝试使用UiAutomator在Android上使用react本机应用程序执行测试。我从移植Google示例中的精确代码开始: 以下是示例中的设置代码: @Before public void startMainActivityFromHomeScreen() { // Initialize UiDevice instance mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation

我正在尝试使用UiAutomator在Android上使用react本机应用程序执行测试。我从移植Google示例中的精确代码开始:

以下是示例中的设置代码:

@Before
public void startMainActivityFromHomeScreen() {
    // Initialize UiDevice instance
    mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());

    // Start from the home screen
    mDevice.pressHome();

    // Wait for launcher
    final String launcherPackage = mDevice.getLauncherPackageName();
    assertThat(launcherPackage, notNullValue());
    mDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)),
            LAUNCH_TIMEOUT);

    // Launch the app
    Context context = InstrumentationRegistry.getContext();
    final Intent intent = context.getPackageManager()
            .getLaunchIntentForPackage(BASIC_SAMPLE_PACKAGE);
    // Clear out any previous instances
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    context.startActivity(intent);

    // Wait for the app to appear
    mDevice.wait(Until.hasObject(By.pkg(BASIC_SAMPLE_PACKAGE).depth(0)),
            LAUNCH_TIMEOUT);
}
它可以启动应用程序,但当它到达mDevice.wait()时,我会得到一个NPE:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.accessibility.AccessibilityNodeInfo.isVisibleToUser()' on a null object reference
   mDevice.wait(Until.hasObject(By.desc("get started")), LAUNCH_TIMEOUT);
同样,当我用我自己的替代方案代替等待时,我也会得到一个NPE:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.view.accessibility.AccessibilityNodeInfo.isVisibleToUser()' on a null object reference
   mDevice.wait(Until.hasObject(By.desc("get started")), LAUNCH_TIMEOUT);
我在书中看到了一些建议,但没有什么不同

react native中是否存在导致此问题的固有因素