0
votes

Im experimenting with Allure aShot() class to take screenshots of specific WebElements on a website I'm working on, and below is the code I used in selenium to make it happen. Please visit this link, which shows aShot() project documentation:

https://github.com/yandex-qatools/ashot

So My QUESTION is that, where are these AShot() screenshots of the WebElement actually being saved? I used testNG to execute below method and successfully able to generate allure reports but I can't see these screenshots in those reports or anywhere in my framework. Please check below code, it is very difficult to pinpoint the location of these images.

So again, my basic question is: How do we specify selenium to store these AShot() screenshots of the WebElement into a particular file that we want?

I've tried to cast Screenshot class mentioned below to BufferedImage or TakesScreenshot class and use ImageIO.write or FileUtils.copyFile methods to copy these images into a file and store these images there, but I get an error saying, for example, "java.lang.ClassCastException: ru.yandex.qatools.ashot.Screenshot cannot be cast to org.openqa.selenium.TakesScreenshot" and I've tried other methods as well, unsuccessfully.

Please help me resolve this issue, how do we know/specify where these AShot() screenshots are being saved?

public WebDriver driver;

@Test
public void getAShotImage() {
  driver.get("http://....../");
  WebElement element = driver.FindElement(By.xpath(".............."));
  AShot shot = new AShot();
  shot.takeScreenShot(driver, element);

  OR

  shot.coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(driver, element);

}
2

2 Answers

0
votes

You can attach your screenshots by returning byte array from the method. Look at the following example:-

@Attachment(value="Screenshot", type="image/png")
private static byte[] captureScreenshot(Webdriver driver)
{
    byte[] screenshot = null;
            screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
        }
  return screenshot
}

Above code does not use Ashot but it shows how you need to attach files. Also, if you are still not able to see your screenshots, check if your steps are displayed in your report.If not then probably you are missing javaagent as discussed in FAQ

0
votes

AShot returns the Screenshot object, that contains the image of your element and information for comparison of screenshots. In this case you can use getImage() method to get the image.

new AShot().takeScreenshot(....).getImage();

The Screenshot will contain the byte array instead of BufferedImage soon.