【问题标题】:testUI (Jenkins) using espresso使用浓缩咖啡的 testUI (Jenkins)
【发布时间】:2014-11-26 03:47:45
【问题描述】:

应用程序正在本地通过 espresso 测试,我的意思是直接通过设备和 genymotion 模拟器。当我使用 Jenkins 构建应用程序的图像时。浓缩咖啡测试不成功我收到此错误。

詹金斯:

 java.lang.RuntimeException: Waited for the root of the view hierarchy to have window focus and not be requesting layout for over 10 seconds. If you specified a non default root matcher, it may be picking a root that never takes focus. Otherwise, something is seriously wrong. Selected Root:
Root{application-window-token=android.view.ViewRootImpl$W@536a97d4, window-token=android.view.ViewRootImpl$W@536a97d4, has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#100 ty=1 fl=#1810100 pfl=0x8 wanim=0x103028f}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=800, height=1184, has-focus=true, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}}
. All Roots:
Root{application-window-token=android.view.ViewRootImpl$W@536a97d4, window-token=android.view.ViewRootImpl$W@536a97d4, has-window-focus=false, layout-params-type=1, layout-params-string=WM.LayoutParams{(0,0)(fillxfill) sim=#100 ty=1 fl=#1810100 pfl=0x8 wanim=0x103028f}, decor-view-string=DecorView{id=-1, visibility=VISIBLE, width=800, height=1184, has-focus=true, has-focusable=true, has-window-focus=false, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}}
at com.google.android.apps.common.testing.ui.espresso.base.RootViewPicker.get(RootViewPicker.java:84)
at com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule.provideRootView(ViewInteractionModule.java:51)
at com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule$$ModuleAdapter$ProvideRootViewProvidesAdapter.get(ViewInteractionModule$$ModuleAdapter.java:187)
at com.google.android.apps.common.testing.ui.espresso.ViewInteractionModule$$ModuleAdapter$ProvideRootViewProvidesAdapter.get(ViewInteractionModule$$ModuleAdapter.java:151)
at com.google.android.apps.common.testing.ui.espresso.base.ViewFinderImpl.getView(ViewFinderImpl.java:52)
at com.google.android.apps.common.testing.ui.espresso.ViewInteraction$2.run(ViewInteraction.java:141)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:442)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)

【问题讨论】:

  • 这个堆栈跟踪来自什么设备?
  • 詹金斯就是这么说的。
  • 该堆栈跟踪来自在 android 模拟器或 android 设备上运行的 Espresso。你在你的 Jenkins 服务器上运行模拟器吗?
  • 您的模拟器是否使用“--no-window”运行?尝试使用与 Jenkins 机器上完全相同的 AVD 在本地复制。
  • 我在使用无人机时也遇到了同样的问题,您找到解决方案了吗?

标签: android jenkins android-espresso


【解决方案1】:

我建议使用Test-Butler,在测试时禁用动画和解锁屏幕。

【讨论】:

  • Test-Butler 只能用于模拟器,所以如果您使用模拟器来运行测试是个好主意。如果您在真实设备上进行测试,我建议您使用UiAutomator。
【解决方案2】:

从我的角度来看,您需要按以下方式组织 Jenkins 作业:在运行 Espresso 测试之前(我想您已经在 gradle 构建后操作中连接了 AndroidTest 或类似的东西),添加构建后卸载应用程序包的操作和卸载应用程序测试包的另一个操作。示例:com.example.mypackage.debug 和 com.example.mypackage.debug.test。这是将应用程序刷新到智能手机/模拟器中的好方法,以便让 Espresso 发挥它的魔力。

还要确保您已激活开发者工具中的 Always On 选项(取决于设备,在“设置”中您有开发者选项或开发者工具子菜单)。

如果这些都不起作用,则意味着您在 Jenkins 工作的某个地方存在一些操作顺序问题,需要加以澄清。对我来说,软件包的卸载帮助我清理了系统中与我的应用相关的所有内容。

希望它也对你有用。

如果没有,请写评论,我会帮助你。

祝你好运!

【讨论】:

    【解决方案3】:

    解决方案是创建一个自定义测试运行器来解锁屏幕并启动唤醒锁定,直到测试完成。

    public class TestRunner extends android.support.test.runner.AndroidJUnitRunner
    {
        private PowerManager.WakeLock mWakeLock;
    
        @Override
        public void callApplicationOnCreate(Application app)
        {
            // Unlock the screen
            KeyguardManager keyguard = (KeyguardManager) app.getSystemService(Context.KEYGUARD_SERVICE);
            keyguard.newKeyguardLock(getClass().getSimpleName()).disableKeyguard();
    
            // Start a wake lock
            PowerManager power = (PowerManager) app.getSystemService(Context.POWER_SERVICE);
            mWakeLock = power.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.ON_AFTER_RELEASE, getClass().getSimpleName());
            mWakeLock.acquire();
    
            super.callApplicationOnCreate(app);
        }
    
        @Override
        public void onDestroy()
        {
            mWakeLock.release();
    
            super.onDestroy();
        }
    }
    

    然后AndroidManifest.xml你的测试并添加必要的权限:

    <uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
    <uses-permission android:name="android.permission.WAKE_LOCK"/>
    

    不要忘记编辑您的 build.gradle 以使用新的 testInstrumentationRunner 类。

    Source

    【讨论】:

    • 此解决方案使用了一些已弃用的方法和常量。你能提供一些替代方案吗?
    【解决方案4】:

    Stacktrace 表示 Espresso 找不到应用程序窗口。在模拟器屏幕上进行测试期间,通常隐藏在屏幕锁定后面。您需要使用一些代码以编程方式禁用 ScreenLock。 我解锁屏幕最方便的方法是使用 Robotium。它有 solo.unlockScreen() 方法。我已将其放入测试生命周期的 setUp() 方法中。

    链接: https://github.com/RobotiumTech/robotium/blob/master/robotium-solo/src/main/java/com/robotium/solo/Solo.java

    【讨论】:

    • 在 scytale 的响应之上 - 您还可以提供您建议的实施的简单示例。
    猜你喜欢
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多