selenium.captureEntirePageScreenshot不起作用,但selenium.captureScreenshot工作

时间:2009-09-07 06:24:32

标签: selenium screenshot selenium-rc

我正在使用Eclipse和Selenium RC运行Selenium和TestNG。我用了命令:

selenium.captureEntirePageScreenshot("\\test.png","");

但出现以下错误:

com.thoughtworks.selenium.SeleniumException: ERROR: Command execution failure. Please search the forum at http://clearspace.openqa.org for error details from the log window.  The error message is: Component returned failure code: 0x80520001 (NS_ERROR_FILE_UNRECOGNIZED_PATH) [nsILocalFile.initWithPath]



有人可以建议为什么会出现这个错误吗?我已经尝试了以下内容:

1)用“background =#CCFFDD”替换“”(String kwargs参数)

2)以Chrome模式在Firefox中运行

3)将路径更改为以下值,我仍然收到错误: “\ test.jpg放在” “C:\ test.jpg放在” “C:\ test.png” “c:\ folder1 \ test.png”,(folder1存在) “C:\文件夹1 \ test.jpg放在”,

4)尝试 - selenium.captureScreenshot(“\ test.png”);它工作正常,但它没有解决我的目的,我不想使用awt。

有人可以建议可能出现的问题吗?

谢谢,
无限

4 个答案:

答案 0 :(得分:1)

试试这个:

String path = System.getProperty("user.dir");
selenium.captureEntirePageScreenshot(path + "\\test.png", "");

答案 1 :(得分:1)

更好......

我遇到了类似的问题,我只能访问相对路径而不是绝对路径。这是我提出的解决方案:

public void saveScreenshot(String methodName) {
    if (methodName == null) {
        methodName = String.valueOf(System.currentTimeMillis());
    }
    File f = new File("reports" + File.separator + methodName + ".jpg");
    selenium.captureEntirePageScreenshot(f.getAbsolutePath(), "");
}

将整个页面的屏幕截图放入与项目相关的reports目录中。我使用方法名称作为文件名,或者如果将null发送到方法,则使用当前时间。

答案 2 :(得分:0)

对于可能涉及的任何人,在我花了一段时间摆弄代码并重新启动我的系统之后,问题就解决了。我开始知道captureEntirePageScreenshot仅适用于绝对路径,所以我确保我一直在尝试。

答案 3 :(得分:-1)