在我的测试中,在一次操作之后,有两种可能的视图可以出现并且它们都是正确的.如何检查是否显示其中一个视图.对于我可以检查的单个视图是Displayed().但如果其他视图可见则会失败.如果显示这两个视图中的任何一个,我想通过测试.
onMyButton.perform(click());
onMyPageOne.check(matches(isDisplayed())); //view 1
or
onMyPageTwo.check(matches(isDisplayed())); //view 2
Run Code Online (Sandbox Code Playgroud)
之后,执行单击MyButton,预计会出现任何一个视图(1或2),但不会同时出现.不确定哪一个会被显示.如何检查是否显示其中任何一个?
我正在使用Espresso进行一些简单的测试。其中之一是关于单击视图并检查是否显示对话框。
我的问题是有时有效,有时无效。仅当我在检查对话框之前先入睡时,它才始终有效。有没有不使用睡眠的解决方案?
这是我的代码(非常简单):
onView(withId(R.id.forgot_password)).perform(click());
// only works if use Thread.sleep(ms) here
onView(withText(R.string.reset_password)).check(matches(isDisplayed()));
Run Code Online (Sandbox Code Playgroud)
编辑:
我正在显示带有静态助手的对话框,但是简化了。而且我不在中间执行任何后台任务。
最终的TextInputDialog textInputDialog = new
TextInputDialog.Builder(context)
.setTitle(titleId)
.setInputType(inputType)
.setHint(hintId)
.setPreFilledText(preFilledText)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(positiveButtonId, onTextSubmittedListener)
.create();
textInputDialog.show(textInputDialog);
Run Code Online (Sandbox Code Playgroud)
谢谢!