gpt4 book ai didi

安卓 Espresso : DatePicker Click on OK add a year instead of validate

转载 作者:太空狗 更新时间:2023-10-29 15:45:42 28 4
gpt4 key购买 nike

在 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com