UiAutomator Uiautomator+Spoon 截图,提示:java.lang.RuntimeException: Unable to capture screenshot.

杨! · April 12, 2017 · Last by 999 replied at August 02, 2017 · 1471 hits

前两天在网上看了有关《Spoon 技术应用于 UiAutomator 自动化测试》的文章,
文中说到 Uiautomator 可以借助 Spoon 的Spoon.save()方法将截图保存在测试报告中。
跟着我参考网上很多帖子,就在自己的代码中引入spoon-client-1.7.1.jar,执行代码如下:

public ActivityTestRule<MainActivity> mActivityRule = new ActivityTestRule<>(
        MainActivity.class);
@Test
public void  test_case() throws UiObjectNotFoundException, IOException, InterruptedException {
    ListView_public.Refresh();
    device.pressHome();
    System.out.println("Ui========="+mActivityRule.getActivity());
    Spoon.screenshot(mActivityRule.getActivity(),"test");
    device.pressHome();
}

运行编译后提示:java.lang.RuntimeException: Unable to capture screenshot.

请问有人知道这是为什么吗??😭 😭

共收到 2 条回复 时间 点赞
  • 1.查看是否有写入权限
  • 2.uiautomator 使用 spoon 截图,我记得是需要获取被测应用的 activity 对象才能操作的,而 uiautomator 拿不到,所以可以改掉它的截图方法,改成系统的或者其他非侵入式的

其实楼主离成功只差一步了 需要在前面加个@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");
}
3Floor has deleted
4Floor has deleted
需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up