/*********************************************************************
Script Summary
Title : Webdriver Script019 : Capturing Screen Shot
Author : Gaurav Khanna
1. Set the Base URL to http://not-just-a-tester.blogspot.in
2. Capture the screenshot.
3. Save it to directory.
*********************************************************************/
package com.gaurav.webdriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
public class s019_CapturingScreenShot {
// Declaring variable 'webDriver' of WebDriver Type
WebDriver webDriver;
// Declaring baseURL variable of String Type
String baseUrl;
@BeforeMethod
public void startUp() throws Exception {
// Initializing FireFox Driver
webDriver = new FirefoxDriver();
// Assigning URL to variable 'baseUrl'
baseUrl = "http://not-just-a-tester.blogspot.in";
}
@Test
public void testscript019() throws Exception {
// Open the link
webDriver.get(baseUrl);
// Captures the screen shot
File scrFile = ((TakesScreenshot) webDriver)
.getScreenshotAs(OutputType.FILE);
// Copying screen shot to the desired location
FileUtils.copyFile(scrFile, new File("c:\\gk\\screenshot.png"));
}
@AfterMethod
public void shutDown() throws Exception {
// This will close the browser
webDriver.quit();
}
}
Script Summary
Title : Webdriver Script019 : Capturing Screen Shot
Author : Gaurav Khanna
1. Set the Base URL to http://not-just-a-tester.blogspot.in
2. Capture the screenshot.
3. Save it to directory.
*********************************************************************/
package com.gaurav.webdriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
public class s019_CapturingScreenShot {
// Declaring variable 'webDriver' of WebDriver Type
WebDriver webDriver;
// Declaring baseURL variable of String Type
String baseUrl;
@BeforeMethod
public void startUp() throws Exception {
// Initializing FireFox Driver
webDriver = new FirefoxDriver();
// Assigning URL to variable 'baseUrl'
baseUrl = "http://not-just-a-tester.blogspot.in";
}
@Test
public void testscript019() throws Exception {
// Open the link
webDriver.get(baseUrl);
// Captures the screen shot
File scrFile = ((TakesScreenshot) webDriver)
.getScreenshotAs(OutputType.FILE);
// Copying screen shot to the desired location
FileUtils.copyFile(scrFile, new File("c:\\gk\\screenshot.png"));
}
@AfterMethod
public void shutDown() throws Exception {
// This will close the browser
webDriver.quit();
}
}