问题描述
在我的仪器测试我想测试的东西在风景和肖像模式,所以我想设置方向测试开始之前。有没有一种方法以编程方式设置在设备或模拟器的方向?
In my instrumentation tests I want to test something in both landscape and portrait mode, so I'd like to set the orientation before the tests start. Is there a way to set the device or emulator orientation programmatically?
我知道的 setRequestedOrientation()
的方法,但这个工程有一定的活性,如果另一个活动开始我一定要记得再次调用它。我正在寻找一种方法来设置方向全球性,让每一个新的活动会自动启动与方向。
I am aware of the setRequestedOrientation()
method but this works for a certain activity, if another activity is started I have to remember to call it again. What I'm looking for is a way to set the orientation "globally", so that every new activity is automatically started with that orientation.
更新:
必须满足2要求的解决方案:1)它的不让我改变了生产code,2)它需要在一个CI环境中运行
The solution must fit 2 requirements: 1) it doesn't make me change my production code, 2) it needs to run in a CI environment.
推荐答案
下面是我制作这个简单的创建一个ViewAction: https://gist.github.com/nbarraille/03e8910dc1d415ed9740
Here is a ViewAction I created for making this simpler:https://gist.github.com/nbarraille/03e8910dc1d415ed9740
的用法是在注释中描述。希望有所帮助。
The usage is described in the comments.Hope that helps.
这篇关于设置仿真器/设备方向编程仪器仪表测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!