作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
在 Google Espresso 测试中,我试图点击 DatePickerDialog 的 OK 按钮。
但它并没有验证我的输入,它只是增加了一年并且不会关闭对话框。
点击似乎是在年份列的“+”按钮上完成的。这是 Espresso 错误还是我遗漏了什么?
这是我的 Espresso 代码(在 Kotlin 中):
onView(allOf(iz(instanceOf(javaClass<Button>())), withText("OK"),
isDisplayed()) as Matcher<View>).perform(click())
最佳答案
它可能并不完美(因为我对文本“OK”进行了硬编码),但我设法在我的测试中使用以下代码 fragment 做到了这一点:
// 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());
关于安卓 Espresso : DatePicker Click on OK add a year instead of validate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30597680/
我是一名优秀的程序员,十分优秀!