我正在为我的应用程序写一个Espresso测试,并试图在我的应用程序中打开相机后自动点击快门按钮。点击使用UIAutomator的相机快门
我在Android模拟器中使用Espresso和UIAutomator。我设法在UIAutomatorViewer中转储这个UI。
我想不通为什么我无法点击使用UIAutomator使用此代码快门按钮:
public void clickCameraShutterButton() throws UiObjectNotFoundException
{
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
UiSelector shutterSelector = new UiSelector().resourceId("com.android.camera:id/shutter_button");
UiObject shutterButton = device.findObject(shutterSelector);
shutterButton.click();
}
相机只是坐在那里,和快门键被按下从来没有。这是我在Android Studio显示器中获得的堆栈跟踪:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.app.Activity.findViewById(int)' on a null object reference
任何意见,将不胜感激。