package com.amazon.qa.tests;

 

import java.io.File;

import java.io.IOException;

 

import org.openqa..OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.openqa.selenium.;

import org.openqa.selenium.WebDriverException;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.io.;

import org.testng.annotations.Test;

 

public class FileHandlerClass {

 

@Test

public void fileHandlerTest() throws WebDriverException, IOException {

            //Initialize webdriver     

            System.setProperty(“webdriver.chrome.driver”,“C:\Selenium Project\Drivers\chromedriver.exe”);

    WebDriver driver=new ChromeDriver();

    // To open Softwaretestingmaterial.com site

            driver.get(“https://www.softwaretestingmaterial.com/”);

            // Following code captures the and place it in specified location

    TakesScreenshot ts=(TakesScreenshot)driver;

    FileHandler.copy(ts.getScreenshotAs(OutputType.FILE), new File(“C:\Selenium Project\CaptureScreenshot.png”));

    driver.quit();

}

}



Source link https://www.softwaretestingmaterial.com/-screenshot-in-selenium-webdriver-using-filehandler/

LEAVE A REPLY

Please enter your comment!
Please enter your name here