use of org.openqa.selenium.Dimension in project selenium-tests by Wikia.
the class AdsSkinHelper method skinPartPresent.
private boolean skinPartPresent(boolean isLeft) {
hideCoveredSkinElements();
String pathToFile = isLeft ? pathToLeftPart : pathToRightPart;
File patternFile = new File(pathToFile);
BufferedImage patternImage = imageEditor.fileToImage(patternFile);
if (shouldCutPattern(patternImage.getWidth(), isLeft)) {
patternFile = getCutPattern(patternImage, isLeft);
patternImage = imageEditor.fileToImage(patternFile);
}
Dimension size = new Dimension(patternImage.getWidth(), patternImage.getHeight());
PageObjectLogging.logImage("EXPECTED", patternFile, true);
Point startPoint = getStartPoint(patternImage, isLeft);
File actualFile = shooter.capturePageAndCrop(startPoint, size, driver);
PageObjectLogging.logImage("ACTUAL", actualFile, true);
BufferedImage actualImg = imageEditor.fileToImage(actualFile);
return !imageComparison.areImagesDifferent(patternImage, actualImg, IMAGES_THRESHOLD_PERCENT);
}
use of org.openqa.selenium.Dimension in project selenium-tests by Wikia.
the class AdsRecoveryObject method verifyPageFairRecoveryWithAdBlock.
public void verifyPageFairRecoveryWithAdBlock() {
By spansBodyChildrenSelector = By.cssSelector("body>span");
Dimension topLeaderboardSize = new Dimension(728, 90);
Dimension medrecSize = new Dimension(300, 250);
String expectedRecoveredLB;
String expectedRecoveredMR;
try {
expectedRecoveredLB = readFileToString(new File(EXPECTED_TOP_LEADERBOARD_PATH));
expectedRecoveredMR = readFileToString(new File(EXPECTED_MEDREC_PATH));
} catch (IOException e) {
PageObjectLogging.log("Can't open expected PageFair recovery file.", e, false);
throw new WebDriverException("Can't open expected PageFair recovery file.");
}
// when PF recovered ad is on page, inserts span elements as a direct children of body
wait.forElementPresent(spansBodyChildrenSelector);
// verify that adblock is turned on on that page
verifyNoAdsOnPage();
String firstSpanClass = driver.findElement(spansBodyChildrenSelector).getAttribute("class");
List<WebElement> recoveredAds = driver.findElements(By.cssSelector("body>span." + firstSpanClass)).stream().filter(WebElement::isDisplayed).filter(e -> e.getCssValue("background").contains("data:image/jpeg")).collect(Collectors.toList());
Assert.assertEquals(recoveredAds.size(), RECOVERABLE_ADS_COUNT);
for (WebElement ad : recoveredAds) {
Dimension adSize = ad.getSize();
if (adSize.equals(topLeaderboardSize)) {
Assertion.assertTrue(ad.getCssValue("background").contains(expectedRecoveredLB), "TOP_LEADERBOARD is not correctly recovered!");
} else if (adSize.equals(medrecSize)) {
Assertion.assertTrue(ad.getCssValue("background").contains(expectedRecoveredMR), "MEDREC is not correctly recovered!");
} else {
Assertion.fail("Not supported PageFair recovery ad size encountered: " + adSize);
}
}
}
use of org.openqa.selenium.Dimension 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;
}
use of org.openqa.selenium.Dimension in project fess by codelibs.
the class WebDriverGenerator method startWebDriver.
protected void startWebDriver() {
try {
if (webDriver == null) {
if (webDriverCapabilities == null) {
webDriver = new PhantomJSDriver();
} else {
if (webDriverCapabilities instanceof DesiredCapabilities) {
final DesiredCapabilities capabilities = (DesiredCapabilities) webDriverCapabilities;
webDriverCapabilities.asMap().entrySet().stream().filter(e -> e.getValue() instanceof String && filePathMap.containsKey(e.getValue().toString())).forEach(e -> capabilities.setCapability(e.getKey(), filePathMap.get(e.getValue().toString())));
}
webDriver = new PhantomJSDriver(createDriverService(webDriverCapabilities), webDriverCapabilities);
}
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
webDriver.manage().window().setSize(new Dimension(fessConfig.getThumbnailHtmlPhantomjsWindowWidthAsInteger(), fessConfig.getThumbnailHtmlPhantomjsWindowHeightAsInteger()));
previousCheckTime = ComponentUtil.getSystemHelper().getCurrentTimeAsLong();
} catch (final Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("WebDriver is not available for generating thumbnails.", e);
} else {
logger.info("WebDriver is not available for generating thumbnails.");
}
}
}
Aggregations