使用 android espresso 自动深度链接

Dar*_*han 5 android deep-linking android-espresso

我想编写浓缩咖啡脚本来测试深度链接,但不知道如何开始。寻找能够帮助我获得更多想法的解决方案,可能是有关如何开始的分步过程。

例如:我正在寻找一种场景,例如您在 Gmail 中获得一个链接,点击该链接应将哪个用户定向到移动应用程序。我如何开始使用浓缩咖啡测试类似的东西?

提前致谢。

gor*_*sbm 5

从活动规则开始

 @Rule
 public ActivityTestRule<YourAppMainActivity> mActivityRule =
            new ActivityTestRule<>(YourAppMainActivity.class, true, false);
Run Code Online (Sandbox Code Playgroud)

然后你需要一些东西来解析链接中的 uri 并返回意图

String uri = "http://your_deep_link_from_gmail"; 
private Intent getDeepLinkIntent(String uri){
        Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(uri))
                .setPackage(getTargetContext().getPackageName());


        return intent;
    }
Run Code Online (Sandbox Code Playgroud)

然后您希望活动规则启动意图

Intent intent = getDeepLinkIntent(deepLinkUri);
mActivityRule.launchActivity(intent);
Run Code Online (Sandbox Code Playgroud)

  • 我相信这总是会启动您的活动,即使您提供的深层链接是错误的,因为如果意图的组件为空, testrule.launchActivity 会将您的组件添加到意图中:( (2认同)