【发布时间】:2015-11-25 17:11:39
【问题描述】:
我正在开发我的第一个 android 应用程序并且我正在设置 CI 服务器。我的浓缩咖啡测试在我的机器上运行良好,但出现以下错误
java.lang.RuntimeException: 等待视图层次结构的根获得窗口焦点并且超过 10 秒没有请求布局。
在运行测试之前,我似乎需要解锁模拟器屏幕。为此,我必须向 src/debug 添加具有所需权限的清单,然后使用以下命令解锁屏幕:
KeyguardManager mKeyGuardManager = (KeyguardManager) ctx.getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock mLock = mKeyGuardManager.newKeyguardLock(name);
mLock.disableKeyguard();
问题是我不想在 if 块中包含上述代码来乱扔我的活动。有没有办法从 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")));
}
}
【问题讨论】: