Android Epresso:DatePicker点击确定添加一年而不是验证

在Google Espresso测试中,我试图点击DatePickerDialog的确定按钮。

但不是验证我的输入,它只是添加一年,不关闭对话框。

看来,点击是在年份栏的“+”按钮上完成的。 这是一个咖啡的错误还是我错过了什么?

这是我的浓咖啡代码(在Kotlin):

onView(allOf(iz(instanceOf(javaClass<Button>())), withText("OK"), isDisplayed()) as Matcher<View>).perform(click()) 

这可能不是完美的(因为我硬编码文本“OK”),但我设法做到这一点在我的测试使用这个片段:

 // Change the date of the DatePicker. Don't use "withId" as at runtime Android shares the DatePicker id between several sub-elements onView(withClassName(Matchers.equalTo(DatePicker.class.getName()))).perform(PickerActions.setDate(1989, 8, 25)); // Click on the "OK" button to confirm and close the dialog onView(withText("OK")).perform(click()); 

在某些版本的Android上,“确定”DatePickerDialog被替换为“Set”或“Done”。 尝试:

 onView(withId(android.R.id.button1)).perform(click()); 

这将点击对话框的正面按钮。 不管怎么叫。

将我的测试设备升级到4.4.4后,错误已经消失:这是一个Android <4.4的错误T_T