use of org.openqa.selenium.TakesScreenshot in project geode by apache.
the class ScreenshotOnFailureRule method takeScreenshot.
private void takeScreenshot(String screenshotName) {
WebDriver driver = this.webDriverSupplier.get();
if (driver instanceof TakesScreenshot) {
File tempFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
File screenshot = new File("build/screenshots/" + screenshotName + ".png");
FileUtils.copyFile(tempFile, screenshot);
System.err.println("Screenshot saved to: " + screenshot.getCanonicalPath());
} catch (IOException e) {
throw new Error(e);
}
}
}
use of org.openqa.selenium.TakesScreenshot in project ats-framework by Axway.
the class UiEngineUtilities method createScreenshot.
/**
* Create a screenshot image (supported image format/type is PNG).<br/>
* If the screenshot image file already exists it will be automatically replaced by the new one.<br/>
* <br/>
* Currently the supported UI drivers are {@link AbstractRealBrowserDriver} and {@link MobileDriver}:
* <ul>
* <li>{@link AbstractRealBrowserDriver} - the method makes a best effort to create a screenshot,
* depending on the browser to return the following in order of preference:
* <ul>
* <li>Entire page</li>
* <li>Current window</li>
* <li>Visible portion of the current frame</li>
* <li>The screenshot of the entire display containing the browser</li>
* </ul>
* </li>
* <li>{@link MobileDriver} - creates a screenshot of the mobile device screen.<br/>
* <b>NOTE:</b> There is a <a href="https://github.com/selendroid/selendroid/issues/325">known issue</a> on Android Virtual Device with <b>"Use Host GPU"</b> enabled option.
* So in order to get a screenshot it should be disabled. Keep in mind that it will affect the performance, because
* it is a performance acceleration option.
* </li>
* </ul>
*
* @param filePath the screenshot image file path
* @param uiDriver {@link UiDriver} instance
*/
@PublicAtsApi
public static void createScreenshot(String filePath, UiDriver uiDriver) {
WebDriver webDriver = null;
if (uiDriver instanceof AbstractRealBrowserDriver) {
AbstractRealBrowserDriver browserDriver = (AbstractRealBrowserDriver) uiDriver;
webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.toString());
} else if (uiDriver instanceof MobileDriver) {
MobileDriver mobileDriver = (MobileDriver) uiDriver;
webDriver = (WebDriver) mobileDriver.getInternalObject(InternalObjectsEnum.WebDriver.toString());
((AppiumDriver) webDriver).context(MobileDriver.NATIVE_CONTEXT);
} else {
throw new NotSupportedOperationException("Currently it is not possible to create a screenshot with driver: " + uiDriver.getClass().getSimpleName());
}
File scrTmpFile = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
File scrFile = new File(filePath);
if (scrFile.exists() && !scrFile.delete()) {
log.warn("The Screenshot image file '" + filePath + "' already exists, but couldn't be deleted. You can find the current Screenshot image here: " + scrTmpFile.getAbsolutePath());
} else if (!scrTmpFile.renameTo(scrFile)) {
// if renameTo() fails we will try to copy the file
try {
new LocalFileSystemOperations().copyFile(scrTmpFile.getCanonicalPath(), scrFile.getCanonicalPath(), true);
scrTmpFile.delete();
} catch (Exception e) {
log.warn("Unable to create Screenshot image file: " + filePath);
}
}
}
use of org.openqa.selenium.TakesScreenshot in project fess by codelibs.
the class WebDriverGenerator method generate.
@Override
public boolean generate(final String thumbnailId, final String url, final File outputFile) {
if (logger.isDebugEnabled()) {
logger.debug("Generate Thumbnail: " + url);
}
if (outputFile.exists()) {
if (logger.isDebugEnabled()) {
logger.debug("The thumbnail file exists: " + outputFile.getAbsolutePath());
}
return true;
}
final File parentFile = outputFile.getParentFile();
if (!parentFile.exists()) {
parentFile.mkdirs();
}
if (!parentFile.isDirectory()) {
logger.warn("Not found: " + parentFile.getAbsolutePath());
return false;
}
if (webDriver instanceof TakesScreenshot) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
synchronized (this) {
try {
webDriver.get(url);
if (webDriver instanceof JavascriptExecutor) {
final Dimension dim = webDriver.findElement(By.tagName("body")).getSize();
if (dim.height >= fessConfig.getThumbnailHtmlPhantomjsMaxHeightAsInteger()) {
if (logger.isInfoEnabled()) {
logger.info("Skpped Thumbnail generation " + dim + " for " + url);
}
return false;
}
}
final File thumbnail = ((TakesScreenshot) webDriver).getScreenshotAs(OutputType.FILE);
convert(thumbnail, outputFile);
updateThumbnailField(thumbnailId, url, url);
return true;
} catch (final UnreachableBrowserException | SessionNotFoundException e) {
if (logger.isDebugEnabled()) {
logger.debug("WebDriver is not available.", e);
}
previousCheckTime = 0;
} finally {
final long now = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
if (now - previousCheckTime > fessConfig.getThumbnailHtmlPhantomjsKeepAliveAsInteger().longValue()) {
destroy();
startWebDriver();
}
}
}
} else {
logger.warn("WebDriver is not instance of TakesScreenshot: " + webDriver);
}
return false;
}
Aggregations