Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ignore element in current viewport #247

Open
stamtesteng opened this issue Sep 8, 2021 · 0 comments
Open

ignore element in current viewport #247

stamtesteng opened this issue Sep 8, 2021 · 0 comments

Comments

@stamtesteng
Copy link

I am using aShot for visual testing. https://github.com/pazone/ashot I have some pages that I am interested in taking the screenshot only for the current visible part of the page (and not having a full page screenshot). The problem is that if I add elements to be excluded from the page, then the elements will only be excluded from a screenshot that i have scroll up to the top of the full page.

This means that if I want to exclude the same element from a screenshot that the element is visible in the viewport but I have already scroll down some pixels, then the area that is now placed is not excluded from the comparison.

I assume that the ignored areas(coords) are calculated internally from the aShot methods getting the distance from the top of the page and this works fine for full page screenshot. But when it comes to current viewport screenshot, the calculated areas refers to the same coords, so the element is not ignored.

Please let me know if there is a build in mechanism that I miss, or I have to implement the logic.

Below id my code

/** 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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant