Take Screenshot of Particular WebElement on Page using Ashot - Bug Reaper

                  Bug Reaper

Lean about Automation Testing,Selenium WebDriver,RestAssured,Appium,Jenkins,JAVA,API Automation,TestNG,Maven, Rest API, SOAP API,Linux,Maven,Security Testing,Interview Questions

Tuesday, 6 February 2018

Take Screenshot of Particular WebElement on Page using Ashot

Download Maven Dependency
    <dependency>
            <groupId>ru.yandex.qatools.ashot</groupId>
            <artifactId>ashot</artifactId>
            <version>1.4.12</version>
        </dependency>

package com.neeraj.test.neeraj;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.coordinates.WebDriverCoordsProvider;

public class ok {

    public static WebDriver driver = new ChromeDriver();

    @Test
    public void add1() throws InterruptedException, IOException{

        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

        driver.get("http://www.vpl.ca");


        Screenshot totalviews = new AShot()
                .coordsProvider(new WebDriverCoordsProvider()) //find coordinates with WebDriver API
                .takeScreenshot(driver, driver.findElement(By.xpath("(//img[@title='Poet Laureate'])[2]")));

        ImageIO.write(totalviews.getImage(), "PNG", new File("c:\\screenshots\\home21313.png"));   



    }

}

No comments:

Post a Comment