How to perform element based visual testing using imagium?

77 Views Asked by At

I am using Java & Selenium and have been able to successfully capture and validate full page screenshot using Ashot(As documented at imagium.io)

**However I am not able to get a snapshot and test only a chart element of my web app. **

The following code returns nothing, what am I doing wrong? (no error)

WebElement element = driver.findElement(By.id("elementId"));
Screenshot screenshot = new AShot()
        .coordsProvider(new WebDriverCoordsProvider())
        .shootingStrategy(ShootingStrategies.viewportPasting(1000))
        .takeScreenshot(driver, element);

ByteArrayOutputStream out = new  ByteArrayOutputStream(); 
        ImageIO.write(screenshot.getImage(),"PNG", out);
        byte[] bytes = out.toByteArray();
        String imagebase64 = Base64.encodeBase64String(bytes);  

I am not restricting myself to Ashot alone, any other suggestions are welcome.

0

There are 0 best solutions below