You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Set<By> ignoredElements = new HashSet<>();
WebElement elementRefresh = driver.findElement(By.cssSelector(ignoreRefresh));
Point p = elementRefresh.getLocation();
ignoredElements.add(By.cssSelector(ignoreRefresh));
ignoredElements.add(By.cssSelector(alertWarning));
ignoredElements.add(By.cssSelector(alertSdt));
ignoredElements.add(By.cssSelector(alertCritical));
ignoredElements.add(By.cssSelector(alertError));
ignoredElements.add(By.cssSelector(imgSrc));
Set<Coords> ignoredCords = getCords(ignoredElements, driver);
String layout = "Hierarchical (top down)";
Screenshot actualScreenShot = takeScreenAshot(driver,"Hierarchical_top_down", ignoredElements);
BufferedImage expectedImage = ImageIO.read(new File(getUsersProjectRootDirectory(osName)+"/ExpectedImages/"+layout+".png"));
// Create ImageDiffer object and call method makeDiff()
Screenshot expectedScreenShot = new Screenshot(expectedImage);
expectedScreenShot.setIgnoredAreas(actualScreenShot.getIgnoredAreas());
expectedScreenShot.setCoordsToCompare(actualScreenShot.getCoordsToCompare());
ImageDiffer imgDiff = new ImageDiffer();
ImageDiff diff = imgDiff.makeDiff(actualScreenShot.getImage(), expectedScreenShot.getImage());
if (diff.hasDiff()) {
makeDiffImage(actualScreenShot.getImage(), expectedScreenShot.getImage(), "Hierarchical (top down)", diff);
softAssert.assertFalse(diff.hasDiff(), "images are not same");
} else {
logger.info("images are same");
}
softAssert.assertAll();
}
// i have used it for to get cords but i am not using it as of now
public static Set getCords(Set ignoredElements, WebDriver driver) {
Set ignoredCoords = new HashSet<>();
for (By locator : ignoredElements) {
Point point = driver.findElement(locator).getLocation();
Dimension dimension = driver.findElement(locator).getSize();
ignoredCoords.add(new Coords(point.getX(), point.getY(), dimension.getWidth(), dimension.getHeight()));
}
return ignoredCoords;
}
public Screenshot takeScreenAshot(WebDriver driver, String layout, Set ignoredElements) {
String destination = null;
ImageIO.setUseCache(false);
AShot shooter = new AShot().shootingStrategy(ShootingStrategies.simple()).
ignoredElements(ignoredElements).coordsProvider(new WebDriverCoordsProvider());
Screenshot screenshot= shooter.takeScreenshot(driver);
if (pathForStoringScreenshots == null) {
pathForStoringScreenshots = getUsersProjectRootDirectory(osName) + "/Screenshots/";
}
try {
destination =
pathForStoringScreenshots + "/" + layout
+ ".png";
ImageIO.write(screenshot.getImage(), "png", new File(destination));
// FileUtils.copyFile(scrFile, new File(destination));
} catch (Exception e) {
logger.error("Unable to save Screenshot due to error :: ", e);
}
return screenshot;
}
public void makeDiffImage(BufferedImage actualImage, BufferedImage expectedImage, String layout, ImageDiff diff) throws IOException {
String destination = null;
if (pathForStoringScreenshots == null) {
pathForStoringScreenshots = getUsersProjectRootDirectory(osName) + "/Screenshots/Difference/";
}
try {
destination =
pathForStoringScreenshots + "/" + "diff_" + layout
+ ".png";
BufferedImage diffImage = diff.getMarkedImage();
ImageIO.write(diffImage, "png", new File(destination));
} catch (Exception e) {
logger.error("Unable to save Screenshot due to error :: ", e);
}
}
But still i am getting difference image even if i added list of ignored elements with css values.
Tried every way to achieve comparison but Ashot not doing it in correct way.
Please let me know thing i am missing. need help for this.
Thanks.
The text was updated successfully, but these errors were encountered:
Please check below snippet of code:
public void verifyMapLayout() throws IOException {
String ignoreRefresh = "time[title]";
String alertCritical = "div[class*='bg-critical']";
String alertError = "div[class*='bg-error']";
String alertWarning = "div[class*='bg-warning']";
String alertSdt = "div[class*='bg-sdt']";
String imgSrc = "img[id='companyLogo']";
String canvasXpath = "//div[contains(@Class,'MapContainer__TopologyMapWrapper')]";
String canvasCss = "div.yfiles-svgpanel";
String mapGroupXpath = "//span[@Class='group-name' and text()='mapTest']";
String mapLinkXpath = "//span[@Class='group-name' and text()='mapTest']/../../../../div[@Class='group-container']//tbody/tr[@data-name='MapHierachical']//a";
uiCommonLib.waitForElementVisible(driver.findElement(By.xpath(mapGroupXpath)));
uiCommonLib.click(driver.findElement(By.xpath(mapGroupXpath)));
uiCommonLib.waitForElementVisible(driver.findElement(By.xpath(mapLinkXpath)));
uiCommonLib.click(driver.findElement(By.xpath(mapLinkXpath)));
uiCommonLib.waitForElementVisible(driver.findElement(By.xpath(canvasXpath)));
WebElement mapElement = driver.findElement(By.xpath(canvasXpath));
Dimension d = mapElement.getSize();
logger.info("height:"+ d.height+" width: "+d.width);
// i have used it for to get cords but i am not using it as of now
public static Set getCords(Set ignoredElements, WebDriver driver) {
Set ignoredCoords = new HashSet<>();
for (By locator : ignoredElements) {
Point point = driver.findElement(locator).getLocation();
Dimension dimension = driver.findElement(locator).getSize();
ignoredCoords.add(new Coords(point.getX(), point.getY(), dimension.getWidth(), dimension.getHeight()));
}
return ignoredCoords;
}
public Screenshot takeScreenAshot(WebDriver driver, String layout, Set ignoredElements) {
String destination = null;
ImageIO.setUseCache(false);
AShot shooter = new AShot().shootingStrategy(ShootingStrategies.simple()).
ignoredElements(ignoredElements).coordsProvider(new WebDriverCoordsProvider());
Screenshot screenshot= shooter.takeScreenshot(driver);
if (pathForStoringScreenshots == null) {
pathForStoringScreenshots = getUsersProjectRootDirectory(osName) + "/Screenshots/";
}
try {
destination =
pathForStoringScreenshots + "/" + layout
+ ".png";
ImageIO.write(screenshot.getImage(), "png", new File(destination));
// FileUtils.copyFile(scrFile, new File(destination));
} catch (Exception e) {
logger.error("Unable to save Screenshot due to error :: ", e);
}
return screenshot;
}
But still i am getting difference image even if i added list of ignored elements with css values.
Tried every way to achieve comparison but Ashot not doing it in correct way.
Please let me know thing i am missing. need help for this.
Thanks.
The text was updated successfully, but these errors were encountered: