在运行Espresso测试时如何禁用代码中的动画 [英] How to disable animations in code when running Espresso tests

本文介绍了在运行Espresso测试时如何禁用代码中的动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在运行Espresso测试时设法通过代码禁用了动画吗?我一直在尝试遵循此网页中的说明(链接到此处):
https://code.google.com/p/android-test-kit/wiki/DisablingAnimations

Has anybody managed to disable animations through code when running Espresso tests? I've been trying to follow the instructions in this webpage (linked to from here):
https://code.google.com/p/android-test-kit/wiki/DisablingAnimations

不幸的是,它似乎不起作用,因为我一直看到此权限错误:

Unfortunately it does not appear to be working, as I keep seeing this permissions error:

04-27 15:48:28.694      303-342/system_process W/PackageManager﹕ Not granting permission android.permission.SET_ANIMATION_SCALE to package com.cookbrite.dev (protectionLevel=50 flags=0x18be46)

我真的希望避免重新配置设备/仿真器.我们经常在本地运行单个测试,如果我不得不继续切换设置,这会令我烦恼.

I was really hoping to avoid reconfiguring my device/emulators. We frequently run individual tests locally and it will annoy me if I have to keep toggling settings.

我注意到其他一些开发人员抱怨这行不通,所以我可能并不孤单:
https://groups.google.com/forum/#!msg/android-test-kit-discuss/TCil7kMQRTM/QK1qCjzM6KQJ

I noticed some other developers complaining that this doesn't work, so I might not be alone:
https://groups.google.com/forum/#!msg/android-test-kit-discuss/TCil7kMQRTM/QK1qCjzM6KQJ

推荐答案

我终于可以使用它了.以下是要点,列出了所需的步骤:
https://gist.github.com/daj/7b48f1b8a92abf960e7b

I finally got this to work. Here is a Gist listing the required steps:
https://gist.github.com/daj/7b48f1b8a92abf960e7b

我错过的关键步骤是运行adb授予权限:

The key step that I had missed was running adb to grant the permission:

adb shell pm grant com.mypackage android.permission.SET_ANIMATION_SCALE    

仅向清单添加权限并运行反射步骤似乎还不够.

Adding the permission to the manifest and running the reflection steps did not seem to be enough on their own.

这篇关于在运行Espresso测试时如何禁用代码中的动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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