package Techniques.ChildWindowHandling;
import java.io.File;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

public class TakeScreenShot {
    public static void main(String[] args) {


        FirefoxOptions object= new FirefoxOptions();
        WebDriver obj = new FirefoxDriver(object);

        //------------------------------------> get the website.

        obj.get("https://expired.badssl.com/");

        //---------------------> creating js Executor.

        JavascriptExecutor js = (JavascriptExecutor) obj;

        js.executeScript("window.scrollBy(0,1400)");

        //----------------------> Take a Screen Shot.


        // now caste your web driver object into TakeScreenShot method.
        try {
            File src = ((TakesScreenshot) obj).getScreenshotAs(OutputType.FILE);
            FileUtils.copyFile(src, new File("/Users/zain/ScreenTest.png"));
        }
        catch (Exception e)
        {
            System.out.println("File not found");
        }

    }
}
