Selenium Webdriver Tutorial To Capture Screenshot With Example

Capturing screenshot of software spider web application page is real tardily inwards selenium webdriver. As nosotros knows, It is real basic required affair inwards software automation tools to capture screenshot on seek out instance failure or whenever required during seek out instance execution. VIEW MORE SELENIUM WEBDRIVER BASIC COMMANDS for your webdriver knowledge improvement in addition to utilization them inwards your software spider web application seek out instance creation.

If y'all remember, We tin utilization "captureEntirePageScreenshot" ascendence inwards selenium IDE to capture the screenshot on software spider web application electrical flow page. In Selenium WebDriver/Selenium 2, nosotros postulate to capture screenshot of spider web page using bellow syntax.
File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

Then nosotros bring to shop it inwards our local induce using bellow given syntax. You tin change/provide your ain file goal path in addition to name.
FileUtils.copyFile(screenshot, novel File("D:\\screenshot.jpg"));

Now nosotros postulate to import bellow given header files to larn back upward of capture screenshot inwards webdriver.
import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot;

Copy bellow given @Test method role of Capture covert shot webdriver instance in addition to supplant it amongst the @Test method role of instance given on THIS PAGE. Don't forget to import higher upward given header files inwards your eclipse test.(Note : @Test method is marked with pink color in that linked page).
@Test  world void seek out () throws InterruptedException, IOException   {    //Capture entire page screenshot in addition to thus shop it to goal drive   File screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);   FileUtils.copyFile(screenshot, novel File("D:\\screenshot.jpg"));   System.out.print("Screenshot is captured in addition to stored inwards your D: Drive");  }

You tin position higher upward syntax nether pick out handgrip of block of  try to capture screenshot on failure. You tin stance THIS POST If y'all wants to tape video for your selenium webdriver software seek out execution.
More interesting articles here :Generation Enggelmundus Internet Marketing Tool here :Zeageat IM http://www.software-testing-tutorials-automation.com/
Post a Comment (0)
Previous Post Next Post