我正在使用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。
有人可以建议可能出现的问题吗?
谢谢,
无限
答案 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)
答案 3 :(得分:-1)