这是当今最常见的测试方案,因为许多应用程序都在使用自动完成文本框/自动填充文本框。如果您尚未遇到此问题,则可以在开始在位置填充中键入内容时签出google map应用程序,然后显示匹配结果的下拉列表,您可以从列表中选择任何一个继续。关于需要从自动完成文本框中选择结果的测试用例。
让我们看看下面的谷歌地图示例,让我们编写Espresso测试用例来处理“自动完成文本框”值选择。
测试方案-
1.键入位置名称。
2.检查是否显示匹配结果列表。
3.单击任一匹配结果。
测试用例 -
1.在下面的示例测试案例中,我们使用的是Junit Testing Framework。
2.通过使用以下命令定义应用程序的主要活动 @Rule Annotation.
3.我们使用inRoot()和decor View在Main活动窗口中选择一个窗口。
4.首先,我们在位置字段中输入“禁令”,然后检查是否显示了前两个建议。
5.然后,我们单击“最佳”建议。
@RunWith(AndroidJUnit4.class) @LargeTest public class MultiWindowTest { @Rule public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>( MainActivity.class); private MainActivity mActivity = null; @Before public void setActivity() { mActivity = mActivityRule.getActivity(); } @Test public void testAutoCompleteTextView() { // Type "ban" to trigger two suggestions. onView(withId(R.id.auto_complete_text_view)) .perform(typeText("ban"), closeSoftKeyboard()); // Check that both suggestions are displayed. onView(withText("Bangalore")) .inRoot(withDecorView(not(is(mActivity.getWindow().getDecorView())))) .check(matches(isDisplayed())); onView(withText("bangalore central mall")) .inRoot(withDecorView(not(is(mActivity.getWindow().getDecorView())))) .check(matches(isDisplayed())); } // Tap on a suggestion. onView(withText("Bangalore")) .inRoot(withDecorView(not(is(mActivity.getWindow().getDecorView())))) .perform(click()); // By clicking on the auto complete term, the text should be filled in. onView(withId(R.id.auto_complete_text_view)) .check(matches(withText("Bangalore"))); } }
我希望这篇文章可以帮助您解决自动填充文本框测试问题。如果您觉得它有用,请与您的朋友分享,并在下面的评论部分中给我反馈或建议。
谢谢你的这篇文章,它是唯一对我有用的代码。
回复 删除互联网上唯一可用的代码。非常感谢!我在这个问题上苦苦挣扎了两个小时,终于从您那里得到了简单易用的解决方案。
回复 删除