• 当设备不支持 KEYCODE_BACK 时会导致注入失败从而重启 app,希望楼主看下🙏
    我的测试设备是华为荣耀 9

  • 感谢楼主分享,经过尝试有两个地方需要注意下 sdcard 中要有 jacoco 文件夹否则创建 ec 文件时会抛异常,build.gradle 里面需要添加 testCoverageEnabled = true,否则也会报异常

  • 是的 需要手动执行, 或者找个 root 的 android 设备写个能执行 adb shell 命令的 apk,直接在 apk 里执行 shell 脚本

  • 重启后可以通过连接 USB 线然后执行下面命令来重启服务
    adb shell /data/local/tmp/atx-agent server --server 192.168.101.209:8000 -d

  • 请问你这问题解决了吗
    我也遇到同样问题,一直没找到解决方法😭

  • 其实楼主离成功只差一步了 需要在前面加个@Rule

    @Rule
    public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
            MainActivity.class);
    
    @Test
    public void testScreenshot() throws InterruptedException {
        mDevice.pressHome();
        Thread.sleep(2);
        Activity ss=mActivityRule.getActivity();
        Spoon.screenshot(ss,"aaa");
    }
    
  • uiautomator2.0 用 as 运行出错 at 2017年02月17日
    1. 测试类要放在 androidTest 下面
    2. 执行测试的时候要在 Run/Debug Configurations 里新建一个用于 android test 的配置。
  • 虽然 uiautomator 检测不到悬浮闹钟提示控件,但是直接用 mDevice.wait(Until.findObject(By.text("Dismiss")),120000).click(); 还是可以在闹钟响的时候点击到取消的,实测 andorid 6.0 的机器上可用

  • 感谢分享 请教楼主代码中关于 refresh 的部分,取消注释的话能正常刷新界面嘛

    //click(refresh) item15-19
    
    item15.addSelectionListener(new SelectionAdapter(){
        @Override
        public void widgetSelected(SelectionEvent e){
            objectClick();
            //UiAutomatorViewer window=UiAutomatorViewer.getInstance();
            //ScreenshotAction screenshot=new ScreenshotAction(window, false);
            //screenshot.run();
        }
    });
    

    我这里总是报下面的错误

    Unhandled event loop exception during blocked modal context.
    org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.NullPointerException)
        at org.eclipse.swt.SWT.error(Unknown Source)
        at org.eclipse.swt.SWT.error(Unknown Source)
        at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Unknown Source)
        at org.eclipse.swt.widgets.Display.runAsyncMessages(Unknown Source)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
        at org.eclipse.jface.operation.ModalContext$ModalContextThread.block(ModalContext.java:173)
        at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:388)
        at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:507)
        at com.android.uiautomator.actions.ScreenshotAction.run(ScreenshotAction.java:85)
        at com.android.uiautomator.UiAutomatorView$3$6.widgetSelected(UiAutomatorView.java:324)
        at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
        at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
        at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
        at org.eclipse.jface.window.Window.open(Window.java:801)
        at com.android.uiautomator.UiAutomatorViewer.main(UiAutomatorViewer.java:91)
    Caused by: java.lang.NullPointerException
        at com.android.uiautomator.UiAutomatorViewer$1.run(UiAutomatorViewer.java:117)
        at org.eclipse.swt.widgets.RunnableLock.run(Unknown Source)
        ... 16 more
    java.lang.NullPointerException
        at com.android.uiautomator.actions.ScreenshotAction.showError(ScreenshotAction.java:108)
        at com.android.uiautomator.actions.ScreenshotAction.run(ScreenshotAction.java:103)
        at com.android.uiautomator.UiAutomatorView$3$6.widgetSelected(UiAutomatorView.java:324)
        at org.eclipse.swt.widgets.TypedListener.handleEvent(Unknown Source)
        at org.eclipse.swt.widgets.EventTable.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Widget.sendEvent(Unknown Source)
        at org.eclipse.swt.widgets.Display.runDeferredEvents(Unknown Source)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
        at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
        at org.eclipse.jface.window.Window.open(Window.java:801)
        at com.android.uiautomator.UiAutomatorViewer.main(UiAutomatorViewer.java:91)
    
    
    
    
  • 打造专属 uiautomatorviewer at 2016年04月28日

    #15 楼 @niuniudd 大侠能把你的刷新部分代码贴出来吗 菜鸟连刷新都还没搞定呢..