gpt4 book ai didi

windows - 在远程机器上使用 robot.createScreenCapture 获取黑色图像

转载 作者:可可西里 更新时间:2023-11-01 09:37:54 28 4
gpt4 key购买 nike

我有一个常见的问题,当 rdp session 关闭时屏幕截图变成黑色。没有找到解决此问题的任何有效答案。我有 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();
}
}

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

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

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

最佳答案

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

安装后,使用 uvnc session 启动您的 selenium Jenkins slave 并断开连接。

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

关于windows - 在远程机器上使用 robot.createScreenCapture 获取黑色图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22804460/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com