Screenshot in Selenium

// Initialize the Driver

WebDriver driver = new ChromeDriver();

// Providing path of chrome exe ,you can use any browser (Mozila,IE etc..)
System.setProperty("webdriver.chrome.driver", "E:/My Workspace/Chrome_Path//chromedriver.exe");

//Open the webpage 
driver.get("http://gmail.com");

//Maximaize the opened window
driver.manage().window().maximize();

// "TakesScreenshot" is the methos is used for screenshot but in selenium it is not directly present so we need to cast as  a driver "((TakesScreenshot)driver)" then we get the method "getScreenshotAs(OutputType.FILE)",here we have stored the screenshot in a file.
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

//In below line we are coping taken screen shot in our local system
FileUtils.copyFile(src, new File("E:\\shailandra\\ScreenShot\\test.png"));

Comments

Popular posts from this blog

Handling Dynamic Web Tables Using Selenium WebDriver

Importance of testng.xml file

Read it out for TESTNG before going for an iterview