Table of Contents generated with DocToc
- Page
- Frame
- Element
- Viewport
- Vertical Scroll
- Horizontal Scroll
- Full Scroll (Vertical & Horizontal)
- Selenium: 4.9.1
- Selenide: 6.14.1
- JUnit5: 5.9.3
- TestNG: 7.8.0
It automatically provides the current WebDriver instance to com.github.ngoanh2n.wdc.WebDriverShooter
.
You don't need to pass the WebDriver instance to the argument of shooting methods.
When project is using Selenide
directly.
When project is using JUnit Jupiter
as a testing framework.
When project is using TestNG
as a testing framework.
Add to build.gradle
implementation("com.github.ngoanh2n:webdrivershooter:1.0.0")
Add to pom.xml
<dependency>
<groupId>com.github.ngoanh2n</groupId>
<artifactId>webdrivershooter</artifactId>
<version>1.0.0</version>
</dependency>
ShooterOptions.builder()
.setScrollDelay(300) // Set delay duration between scrolling times (Default to 200)
.setMaskedColor(Color.GRAY) // Set color to mask areas (Default to GRAY)
.checkDevicePixelRatio(true) // Indicate to check device pixel ratio or not (Default to true)
/* [Shooting Strategies] */ // Default to shootFullScroll()
.shootViewport() // Mark as taking by viewport strategy
//.shootVerticalScroll() // Mark as taking by vertical scroll strategy
//.shootHorizontalScroll() // Mark as taking by horizontal scroll strategy
//.shootFullScroll() // Mark as taking by full scroll strategy
.maskElements(bysToMask) // Set locators to mask over screenshot
//.maskElements(elementsToMask) // Set elements to mask over screenshot
//.maskExceptingElements(bysToIgnoreMasking) // Set locators are not being masked over screenshot
//.maskExceptingElements(elementsToIgnoreMasking) // Set elements are not being masked over screenshot
.build();
- Take full page screenshot
Screenshot screenshot = WebDriverShooter.page(driver);
- Take full page screenshot and mask some elements
Screenshot screenshot = WebDriverShooter.page(elementsToMask, driver);
- Take horizontal page screenshot
ShooterOptions options = ShooterOptions.builder() .shootHorizontalScroll() .build(); Screenshot screenshot = WebDriverShooter.page(options, driver);
- Take full iframe screenshot
Screenshot screenshot = WebDriverShooter.frame(frame, driver);
- Take full iframe screenshot and mask some elements (Should be
org.openqa.selenium.By
)Screenshot screenshot = WebDriverShooter.frame(frame, bysToMask, driver);
- Take horizontal iframe screenshot
ShooterOptions options = ShooterOptions.builder() .shootHorizontalScroll() .build(); Screenshot screenshot = WebDriverShooter.frame(options, frame, driver);
- Take full element screenshot
Screenshot screenshot = WebDriverShooter.element(element, driver);
- Take full element screenshot and mask some elements
Screenshot screenshot = WebDriverShooter.element(element, elementsToMask, driver);
- Take horizontal element screenshot
ShooterOptions options = ShooterOptions.builder() .shootHorizontalScroll() .build(); Screenshot screenshot = WebDriverShooter.element(options, element, driver);
- Save the image
Screenshot screenshot = WebDriverShooter.page(driver); screenshot.saveImage() //screenshot.saveImage(fileOuput)
- Save the masked image
Screenshot screenshot = WebDriverShooter.page(driver); screenshot.saveMaskedImage() //screenshot.saveMaskedImage(fileOuput)
- Compare with other image
Screenshot screenshot = WebDriverShooter.page(driver); ImageComparisonResult result = screenshot.compare(image);
- Compare with other screenshot
Screenshot screenshot = WebDriverShooter.page(driver); ImageComparisonResult result = screenshot.compare(screenshot);