I was thinking on the following example for taking a screenshot in WebDriver2:
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
When a class implements an Interface, the class must implement the defined the methods in the interface, right?
So, how come during runtime we implement TakeScreenshot
interface, without implementing the logic in getScreenshotAs
method before that?
I tried to simulate it this way:
interface TakeScreenShot{ public void getScreenshotAs(); }
class WebDriver
{
public static void main (String[] args) throws java.lang.Exception
{
WebDriver driver = new WebDriver();
((TakeScreenShot)driver).getScreenshot();
}
}
I ran it in Ideone and I am getting a runtime error:
Runtime error time: 0.05 memory: 711168 signal:-1
So, how does it work in WebDriver?