问题描述
我想为具有深层链接情况的Android应用编写测试使用UI测试框架(Espresso)-仅使用ACTION_VIEW意向启动应用程序,并在打开的屏幕上检查所有视图.
I would like to write tests for Android app with deep link cases using UI testing framework (Espresso) - launch app using only ACTION_VIEW intent and check all views on opened screen.
但是看起来Espresso(甚至是意式浓缩咖啡)没有此功能,并且需要定义Activity类.
But looks like Espresso (even espresso-intents) doesn't have this functionality, and require to define Activity class.
我尝试过这种方法,但无法正常工作,因为两次启动应用程序-使用AppLauncherActivity(Espresso要求)进行标准启动,并通过深层链接启动.
I tried this way, but it doesn't work properly, because launched app twice - standard launch using AppLauncherActivity (required by Espresso) and launch via deep link.
@RunWith(AndroidJUnit4.class)
public class DeeplinkAppLauncherTest {
@Rule
public ActivityTestRule<AppLauncherActivity> activityRule = new ActivityTestRule<>(AppLauncherActivity.class);
@Test
public void testDeeplinkAfterScollDownAndBackUp() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("myapp://search/777"));
activityRule.launchActivity(intent);
onView(withId(R.id.search_panel)).check(matches(isDisplayed()));
}
}
我想仅使用深层链接而不标准启动来启动测试应用程序.你知道怎么做吗?
I would like to launch testing app using only deep link without standard launch.Do you know, how to do it?
推荐答案
我发现了一个选择-只是为现有意图添加了深层链接打开参数并使用标准活动启动:
I found one option - just added deep link opening parameters for existed intent and use standard activity launch:
@Rule
public ActivityTestRule<AppLauncherActivity> activityRule = new ActivityTestRule<AppLauncherActivity>(AppLauncherActivity.class){
@Override protected Intent getActivityIntent() {
Intent intent = super.getActivityIntent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse("myapp://search/777"));
return intent;
}
};
这篇关于如何为Android中的深层链接编写测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!