问题
I'm running Selenium with TestNG using Eclipse and Selenium RC. I used the command:
selenium.captureEntirePageScreenshot("\\test.png","");
but got the following error:
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]
Can someone please suggest why this error is occuring? I have already tried the following:
1)Replaced "" (String kwargs parameter) with "background=#CCFFDD"
2)Running in Firefox in chrome mode
3)Changed the path to the following values and I'm still getting the error: "\test.jpg", "c:\test.jpg", "c:\test.png", "c:\folder1\test.png", (folder1 exists) "c:\folder1\test.jpg",
4)Tried with - selenium.captureScreenshot("\test.png"); and it works fine but it does not solve my purpose and I dont want to use awt.
Can someone please suggest what could be wrong?
Thanks,
Mugen
回答1:
Better yet...
I ran into a similar issue, where I only had access to a relative path instead of an absolute one. Here is the solution I came up with:
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(), "");
}
Which will put a screen shot of the entire page into the reports
directory that is relative to the project. I am using the method name as the file name, or the current time if null is sent to the method.
回答2:
Try this:
String path = System.getProperty("user.dir");
selenium.captureEntirePageScreenshot(path + "\\test.png", "");
回答3:
To whomsoever it may concern,. the problem was solved after I kept fiddling with the code for a while and restarted my system. I came to know that captureEntirePageScreenshot works only on absolute paths so I made sure I kept trying with just that.
回答4:
I got it working after looking at this page.
http://ashishbhatt.wordpress.com/2010/02/03/using-captureentirepagescreenshot-with-selenium/
来源:https://stackoverflow.com/questions/1387807/selenium-captureentirepagescreenshot-does-not-work-but-selenium-capturescreensho