如何验证重定向到 Google Play 商店 [英] How to verify redirection to Google Play Store

查看:82
本文介绍了如何验证重定向到 Google Play 商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Robotium,我如何检查重定向到 Google Play 商店?

Using Robotium, how do I check the redirection to Google Play Store?

步骤:

  1. 点击来自测试应用的列表视图中的链接.
  2. 验证它是否重定向到 Google Play 商店.

我注意到当 Google Play 商店打开时,我的测试应用实际上也在下面打开.(我把所有的意见都打印出来了)

I noticed that while Google Play Store is open, my test app is actually open underneath also. (I printed out all the views)

因此,我不能执行断言来自测试应用程序的 xyz 视图不存在".

Therefore, I cannot do "assert xyz view from test app does NOT exist".

如何检查重定向到 Google Play?

How do I check the redirection to Google Play?

推荐答案

有可能吗?不幸的是,robotium 很难轻松地做到这一点,这是因为 Robotium 跟踪当前活动的方式,如果您使用的是直接检测,那么就像在您单击之前设置一个意图过滤器一样简单查看/执行启动 Play 商店的操作,然后您可以断言您的过滤器实际上已被命中(这证明如果您没有过滤器,实际上会启动 google Play 商店).

Is it possible? sort of, unfortunately robotium makes it very hard to do so easily, this is because of the way that robotium tracks what the current activity is, if you was using straight instrumentation it would be as easy as having an intent filter set up before you click the view/perform action that launches the play store, then you can assert that your filter has in fact been hit (which proves that the google play store would in fact be launched if you did not have the filter).

但是,当您使用机器人时,您不能那么容易地做到这一点,因为机器人已经有一个匹配所有内容的意图过滤器,所以这意味着您将不得不用反射做一些可怕的事情.

As you are using robotium though, you cannot do this so easily as robotium has already got an intent filter up that matches everything so this means you are going to have to do some horribleness with reflection.

您需要做的是:

获取名为 mActivityMonitors 的检测类的私有成员,在此活动监视器列表中,您会发现其中有一个,这将是 Robotiums 活动监视器,将其保存在某处,然后将其从列表中删除.

Get Hold of the private member of the instrumentation class called mActivityMonitors, in this list of activity monitors you will find there is one inside of it, this will be robotiums activity monitor, save this somewhere then remove it from the list.

然后你需要添加你自己的,它看起来像测试 googleplay 的发布(我建议在 android api 文档网站上阅读 Intent 过滤器)

You will then need to add your own it will look something like to test googleplay launches (i suggest reading about Intent filters on the android api documents site)

Instrumentation inst = getInstrumentation();
IntentFilter intentFilter = new IntentFilter(Intent.ACTION_View);

ActivityMonitor monitor = inst.addMonitor(intentFilter, null, true); //true is imporant it blocks the activity from launching so that your test can continue.

assertEquals(0, monitor.getHits());

//do action that fires activity

assertEquals(1, monitor.getHits());
inst.removeMonitor(monitor);

您现在需要阅读您之前删除的活动监视器,以便 Robotium 继续按预期工作.我不是在一台可以实际测试这一切的机器上,但我以前使用过这种技术.

You will now need to readd the activity monitor you removed earlier so that robotium continues to work as expected. I am not on a machine that i can actually test this all on but i have used this technique before.

这篇关于如何验证重定向到 Google Play 商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆