我在设置 Robotium 测试以在 Travis 上运行而没有随机误报时遇到问题。
我得到的每一对构建
pl.mg6.agrtt.TestActivityTests > testCanEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
junit.framework.AssertionFailedError: EditText is not found!
at com.robotium.solo.Waiter.waitForAndGetView(Waiter.java:540)
在我所有的测试中。
我创造了GitHub 上的一个简单项目 https://github.com/mg6maciej/android-gradle-robotium-travis-test来展示问题。
您可能会看到它是如何构建的在特拉维斯 https://travis-ci.org/mg6maciej/android-gradle-robotium-travis-test/builds。请注意,修改不相关文件后,构建 #7 失败。
我怀疑这是由模拟器被锁定或其屏幕变暗引起的。我可以通过关闭连接设备的屏幕然后运行来在本地计算机上重现此问题
./gradlew connectedAndroidTest
修改测试后,我收到了不同的错误消息,该消息的信息量更大,因此我添加它以防万一有人尝试找到解决方案:
pl.mg6.agrtt.TestActivityTests > testCanFindViewsEnterTextAndPressButton[test(AVD) - 4.4.2] FAILED
junit.framework.AssertionFailedError: Click at (160.0, 264.0) can not be completed! (java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission)
at com.robotium.solo.Clicker.clickOnScreen(Clicker.java:106)
虽然我仍然不知道这个问题的根本原因,但经过一番调查并在 Robotium 作者的帮助下雷纳斯·雷达 https://stackoverflow.com/users/188914/renas我可以确认我最初怀疑的模拟器确实会自行锁定。
我现在使用的解决方法是将此代码放入setUp
method:
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
}
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)