我正在使用 aShot 进行视觉测试。 https://github.com/pazone/ashot 我有一些页面我有兴趣只为页面的当前可见部分截取屏幕截图(并且没有完整的页面截图)。问题是,如果我添加要从页面中排除的元素,那么这些元素只会从我滚动到整个页面顶部的屏幕截图中排除。
这意味着如果我想从屏幕截图中排除相同的元素,该元素在视口中可见,但我已经向下滚动了一些像素,那么现在放置的区域不会从比较中排除。
我假设忽略的区域(坐标)是通过 aShot 方法在内部计算得出的,该方法获取到页面顶部的距离,这对于整页屏幕截图来说效果很好。但是对于当前视口截图,计算的区域指的是相同的坐标,所以元素不会被忽略。
请让我知道是否有我错过的内置机制,或者我必须实现逻辑。
下面是我的代码
/** Set ignored areas **/
Set<By> allIgnoredElements = IgnoredElements.getAllIgnoredElements( getFlowType() , mapElementKey );
AShot aShot = new AShot();
for (By element : allIgnoredElements)
aShot.addIgnoredElement(element);
/** Take Screenshot **/
Screenshot actualScreenshot;
if (stickyElementsCase) {
/** Sticky elements case : loop for visible part screenshots **/
} else {
/** NO Sticky elements case : full page screenshot**/
aShot = aShot.shootingStrategy(ShootingStrategies.viewportPasting(1000));
}
actualScreenshot = aShot
.coordsProvider(new WebDriverCoordsProvider())
.takeScreenshot(getDriver());
/** Actual image **/
File actualFile = new File(
path + actualFileName
);
ImageIO.write(actualScreenshot.getImage(), "png", actualFile);
/** Expected image **/
System.out.println("expectedDir + expectedFileName = " + path + expectedFileName);
Screenshot expectedScreenshot = new Screenshot(
ImageIO.read(
new File(
path + expectedFileName
)
)
);
expectedScreenshot.setIgnoredAreas(actualScreenshot.getIgnoredAreas()); // set ignored coordinates before comparing for the master screen
expectedScreenshot.setCoordsToCompare(actualScreenshot.getCoordsToCompare()); // set coordinates which are going to be compared for the master screen
/** Final comparison **/
compareScreenshotsSoftAssert(path, mapElementKey, actualScreenshot, expectedScreenshot, screenShotIndex);