我正在开发我的第一个Android应用程序,并正在设置CI服务器。我的Espresso测试在我的计算机上运行良好,但是travis出现以下错误:
java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds.
似乎我需要在运行测试之前解锁模拟器屏幕。为此,我必须在
java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds.
似乎我需要在运行测试之前解锁模拟器屏幕。为此,我必须在
src/debug
中添加一个清单以获取所需的权限,然后使用以下命令解锁屏幕:KeyguardManager mKeyGuardManager = (KeyguardManager) ctx.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock mLock = mKeyGuardManager.newKeyguardLock(name);
mLock.disableKeyguard();
问题在于我不想在我的活动中使用if块包含的上述代码。有没有一种方法可以从espresso测试本身解锁屏幕?
我的Espresso测试:
@RunWith(AndroidJUnit4.class)
public class EspressoSetupTest {
@Rule
public final ActivityTestRule<WelcomeActivity> activity =
new ActivityTestRule<>(WelcomeActivity.class, true, true);
@Test
public void launchTest() {
onView(withId(R.id.welcome_textView_hello))
.perform(click())
.check(matches(withText("RetroLambda is working")));
}
}
mActivityRule.runOnUiThread()
中。 - woley