0

I know below code takes a screenshot of the page. But what is the different if i create a DesiredCapabilities instance and associate this capability to driver to take a screenshot? I am not getting why DesiredCapabilities are used for, though i have gone through some sites. Can someone explain in layman terms please? Why to set capabilities of platform, browserName, version?

WebDriver driver=new FirefoxDriver();
driver.get("http://www.google.com");

File srcFile=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(srcFile, new File("d:\\Screenshot.png"));
driver.close();
Uday
  • 1,433
  • 10
  • 36
  • 57
  • 1
    possible duplicate of [What is the use of DesiredCapabilities in Selenium WebDriver?](http://stackoverflow.com/questions/17527951/what-is-the-use-of-desiredcapabilities-in-selenium-webdriver) – Ajinkya Feb 09 '15 at 12:08
  • I want bit more detail, so posted here. I want what happens if we dont set those capability properties? as per my example, even though i didnt set screenshot capability, how am i able to save screenshots? – Uday Feb 09 '15 at 12:15

1 Answers1

0

Capture screenshot works well with both selenium2 standard implementation and with remote webdriver.The RemoteWebDriver class does not implement the TakesScreenshot interface so you have to create your own CustomRemoteWebDriver by extending RemoteWebDriver and implementing TakesScreenshot interface without doing it you cannot take screenshot with Remotedriver.

public class MyCustomRemoteWebDriver extends RemoteWebDriver implements TakesScreenshot { 

.....

}

Another important feature of RemoteWebDriver is that exceptions often have an attached screenshot, encoded as a Base64 PNG.

Vicky
  • 2,999
  • 2
  • 21
  • 36