com.applitools.eyes.selenium.capture.SafariScreenshotImageProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of eyes-selenium-java3-jboss Show documentation
Show all versions of eyes-selenium-java3-jboss Show documentation
Applitools Eyes SDK for Selenium Java WebDriver
package com.applitools.eyes.selenium.capture;
import com.applitools.eyes.*;
import com.applitools.eyes.capture.ImageProvider;
import com.applitools.eyes.positioning.PositionProvider;
import com.applitools.eyes.selenium.Eyes;
import com.applitools.eyes.selenium.SeleniumJavaScriptExecutor;
import com.applitools.eyes.selenium.frames.FrameChain;
import com.applitools.eyes.selenium.positioning.ScrollPositionProvider;
import com.applitools.eyes.selenium.wrappers.EyesWebDriver;
import com.applitools.utils.ImageUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import java.awt.image.BufferedImage;
public class SafariScreenshotImageProvider implements ImageProvider {
private final Eyes eyes;
private final Logger logger;
private final TakesScreenshot tsInstance;
private final IEyesJsExecutor jsExecutor;
private final UserAgent userAgent;
public SafariScreenshotImageProvider(Eyes eyes, Logger logger, TakesScreenshot tsInstance, UserAgent userAgent) {
this.eyes = eyes;
this.logger = logger;
this.tsInstance = tsInstance;
this.jsExecutor = new SeleniumJavaScriptExecutor((EyesWebDriver) eyes.getDriver());
this.userAgent = userAgent;
}
@Override
public BufferedImage getImage() {
logger.verbose("Getting screenshot as base64...");
String screenshot64 = tsInstance.getScreenshotAs(OutputType.BASE64);
logger.verbose("Done getting base64! Creating BufferedImage...");
BufferedImage image = ImageUtils.imageFromBase64(screenshot64);
eyes.getDebugScreenshotsProvider().save(image, "SAFARI");
double scaleRatio = eyes.getDevicePixelRatio();
RectangleSize viewportSize = eyes.getViewportSize();
viewportSize = viewportSize.scale(scaleRatio);
if (userAgent.getOS().equals("IOS")) {
image = ImageUtils.cropImage(
image,
new Region(
0,
(int) Math.ceil(64 * scaleRatio),
viewportSize.getWidth(),
viewportSize.getHeight()
)
);
}
if (!eyes.getForceFullPageScreenshot()) {
Location loc;
FrameChain currentFrameChain = ((EyesWebDriver) eyes.getDriver()).getFrameChain();
if (currentFrameChain.size() == 0) {
PositionProvider positionProvider = new ScrollPositionProvider(logger, jsExecutor);
loc = positionProvider.getCurrentPosition();
} else {
loc = currentFrameChain.getDefaultContentScrollPosition();
}
loc = loc.scale(scaleRatio);
image = ImageUtils.cropImage(image, new Region(loc, viewportSize));
}
return image;
}
}