Take a screenshot with Selenium WebDriver for Selenium:
--------------------------------------------------------------------------
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.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;
import org.openqa.selenium.WebDriver;
public class Screenshot{
public void screenshot(WebDriver
webdriver, String filename) throws IOException{
//Taking the Screenshot
File screenshot = ((TakesScreenshot) webdriver).getScreenshotAs(OutputType.FILE);
//Saving the image
FileUtils.copyFile(screenshot, new File(filename));
} catch (IOException e) {
e.printStackTrace();
}
}
--------------------------------------------------------------------------
public static void
main(String[] args) throws IOException {
Screenshot s = new
Screenshot();
String file1 =
"d://Screenshot//screenshot.png";
s.screenshot(data.oWebDriver, file1);
}
}
No comments:
Post a Comment