Table of Contents
- Target: Page, Frame, Element
- Strategy: Viewport, Vertical Scroll, Horizontal Scroll, Full Scroll (Vertical & Horizontal)
- Selenium: 4.15.0
- Selenide: 7.0.3
- JUnit5: 5.10.1
- TestNG: 7.8.0
It automatically provides the current WebDriver
instance to com.github.ngoanh2n.wds.WebDriverShooter
.
You don't need to pass the WebDriver
instance to the argument of shooting methods.
With extension | Without extension |
---|---|
WebDriverShooter.page() |
WebDriverShooter.page(driver) |
When using Selenide
directly.
When using JUnit Jupiter
as a testing framework.
When using TestNG
as a testing framework.
Add to build.gradle
.
implementation("com.github.ngoanh2n:webdrivershooter:1.1.1")
Add to pom.xml
.
<dependency>
<groupId>com.github.ngoanh2n</groupId>
<artifactId>webdrivershooter</artifactId>
<version>1.1.1</version>
</dependency>
WebDriverShooter.page(..)
WebDriverShooter.frame(..)
WebDriverShooter.element(..)
ShooterOptions.builder().shootViewport()
ShooterOptions.builder().shootVerticalScroll()
ShooterOptions.builder().shootHorizontalScroll()
ShooterOptions.builder().shootFullScroll()
Below API methods are using default ShooterOptions
with full screenshot.
Screenshot screenshot = WebDriverShooter.page(driver)
Screenshot screenshot = WebDriverShooter.frame(frame, driver)
Screenshot screenshot = WebDriverShooter.element(element, driver)
When taking the iframe
, you have to pass locators instead.
Screenshot screenshot = WebDriverShooter.page(elementsToMask, driver)
Screenshot screenshot = WebDriverShooter.frame(frame, locatorsToMask, driver)
Screenshot screenshot = WebDriverShooter.element(element, elementsToMask, driver)
Screenshot and mask with customized ShooterOptions
- Mask elements
ShooterOptions options = ShooterOptions .builder() .maskElements(elements) .build(); Screenshot screenshot = WebDriverShooter.page(options, driver);
- Mask all excepting elements
ShooterOptions options = ShooterOptions .builder() .maskExceptingElements(elements) .build(); Screenshot screenshot = WebDriverShooter.page(options, driver);
- With the image
Screenshot screenshot = WebDriverShooter.page(driver); ImageComparisonResult result = screenshot.compare(image);
- With the screenshot
driver.get(URL1); Screenshot screenshot1 = WebDriverShooter.page(driver); driver.get(URL2); Screenshot screenshot2 = WebDriverShooter.page(driver); ImageComparisonResult result = screenshot1.compare(screenshot2); Assertions.assertTrue(result.isDifferent());
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)
.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 (This is default option)
.maskElements(locatorsToMask) // Set locators to mask over screenshot
.maskElements(elementsToMask) // Set elements to mask over screenshot
.maskExceptingElements(locatorsToIgnoreMasking) // Set locators are not being masked over screenshot
.maskExceptingElements(elementsToIgnoreMasking) // Set elements are not being masked over screenshot
.build();