【问题标题】:Getting black images with robot.createScreenCapture on remote machine在远程机器上使用robot.createScreenCapture 获取黑色图像
【发布时间】:2014-04-02 07:32:06
【问题描述】:

当 rdp 会话关闭时,我遇到了一个常见的问题。 没有找到此问题的任何有效答案。 我有 java-selenium 测试。 代码:

private void screenShot() {
    try {
        String newFileNamePath;  
        File directory = new File (".");
        DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss");
        Date date = new Date();

        newFileNamePath = directory.getCanonicalPath() + "\\test-output\\" + "logs\\" + "screenshot_" + dateFormat.format(date) + ".png";
        System.out.println(newFileNamePath);

        //Capture the screen shot of the area of the screen defined by the rectangle
        Robot robot = new Robot();
        BufferedImage bi=robot.createScreenCapture(new Rectangle(1920,1080));
        ImageIO.write(bi, "png", new File(newFileNamePath));
        Reporter.log(newFileNamePath);   
    }       
    catch (AWTException e) {
        e.printStackTrace();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    }

当我通过 Jenkins 在远程服务器 (Windows Server 2008 R2) 上运行测试并且 rdp-session 关闭时,我得到黑色屏幕截图。 如果会话处于活动状态 - 我会得到正常的屏幕截图。 但是我需要在会话关闭时制作正常的屏幕截图。

我怎样才能做到? 有任何想法吗?

VisualCron 和 selenium.captureScreenshot() 不适合我。

【问题讨论】:

  • 这里有同样的问题。在 Win 2003 上,您可以 /console login 和 tscon 0 /dest:console 断开连接。使用 VNC 是一种解决方案,但我不想这样做。

标签: windows session selenium remote-desktop rdp


【解决方案1】:

我一直在寻找使用 VNC 服务器的替代方法,但找不到。所以我的回答是“使用 VNC”。就个人而言,我更喜欢UltraVNC

安装后,使用 uvnc 会话启动 selenium Jenkins 从站并断开连接。

AWT 机器人现在可以工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-21
    • 1970-01-01
    • 2021-12-03
    • 2018-02-16
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    相关资源
    最近更新 更多