Espresso:与 Play Store Popup 互动
Espresso: Interact with Play Store Popup
在我正在开发的应用中,有一个按钮可以打开应用的 Google Play 商店页面。使用 Espresso,我想检查是否打开了正确的页面。
// this is the code I already have
onView(withId(R.id.SettingsButton)).perform(click());
onView(withId(R.id.RateAppButton)).perform(scrollTo(),click());
// now the Play Store should be opened (like a popup)
现在我想知道显示的应用程序标题是否包含正确的应用程序名称,以及它是否是实际的 Play 商店页面。由于 Espresso 在某种程度上不与此视图中的按钮交互,我有哪些选项?
如何使用这个新视图?
正如您正确提到的那样,espresso 只能与您自己的包装进行交互。
要与其他应用程序或 android 系统 UI 交互(例如权限对话框),您必须使用 ui-automator。
ui-automator 如果将它与 espresso 结合使用效果很好,您只需在应用程序中使用 espresso 打开 playstore link,然后使用 ui-automator 检查新屏幕(以及按系统后退按钮 return 到您的应用程序)。
例如,您可以使用类似这样的方法来检查是否出现了正确的标题:
UiObject titleLabel = mDevice.findObject(new UiSelector().text("Your Title"));
if(!titleLabel.exists())
{
throw new RuntimeException("wrong title!");
}
查看此 blogpost 以获得更长的示例。
在我正在开发的应用中,有一个按钮可以打开应用的 Google Play 商店页面。使用 Espresso,我想检查是否打开了正确的页面。
// this is the code I already have
onView(withId(R.id.SettingsButton)).perform(click());
onView(withId(R.id.RateAppButton)).perform(scrollTo(),click());
// now the Play Store should be opened (like a popup)
现在我想知道显示的应用程序标题是否包含正确的应用程序名称,以及它是否是实际的 Play 商店页面。由于 Espresso 在某种程度上不与此视图中的按钮交互,我有哪些选项? 如何使用这个新视图?
正如您正确提到的那样,espresso 只能与您自己的包装进行交互。 要与其他应用程序或 android 系统 UI 交互(例如权限对话框),您必须使用 ui-automator。
ui-automator 如果将它与 espresso 结合使用效果很好,您只需在应用程序中使用 espresso 打开 playstore link,然后使用 ui-automator 检查新屏幕(以及按系统后退按钮 return 到您的应用程序)。
例如,您可以使用类似这样的方法来检查是否出现了正确的标题:
UiObject titleLabel = mDevice.findObject(new UiSelector().text("Your Title"));
if(!titleLabel.exists())
{
throw new RuntimeException("wrong title!");
}
查看此 blogpost 以获得更长的示例。