Search in sources :

Example 21 with Dimension

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);
}
Also used : Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point) File(java.io.File) BufferedImage(java.awt.image.BufferedImage)

Example 22 with Dimension

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);
        }
    }
}
Also used : Dimension(org.openqa.selenium.Dimension) Assertion(com.wikia.webdriver.common.core.Assertion) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) WebDriverException(org.openqa.selenium.WebDriverException) WebElement(org.openqa.selenium.WebElement) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) PageObjectLogging(com.wikia.webdriver.common.logging.PageObjectLogging) List(java.util.List) Assert(org.testng.Assert) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) By(org.openqa.selenium.By) Dimension(org.openqa.selenium.Dimension) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) IOException(java.io.IOException) WebElement(org.openqa.selenium.WebElement) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException)

Example 23 with Dimension

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;
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) Dimension(org.openqa.selenium.Dimension) File(java.io.File) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) TakesScreenshot(org.openqa.selenium.TakesScreenshot) SessionNotFoundException(org.openqa.selenium.remote.SessionNotFoundException)

Example 24 with Dimension

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.");
        }
    }
}
Also used : Rectangle(java.awt.Rectangle) OutputType(org.openqa.selenium.OutputType) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) WebDriver(org.openqa.selenium.WebDriver) Proxy(org.openqa.selenium.Proxy) LoggerFactory(org.slf4j.LoggerFactory) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) TakesScreenshot(org.openqa.selenium.TakesScreenshot) ImageIO(javax.imageio.ImageIO) Dimension(org.openqa.selenium.Dimension) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) ImageReader(javax.imageio.ImageReader) Proxies(org.openqa.selenium.browserlaunchers.Proxies) CommandLine(org.openqa.selenium.os.CommandLine) Builder(org.openqa.selenium.phantomjs.PhantomJSDriverService.Builder) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) BufferedImage(java.awt.image.BufferedImage) Collection(java.util.Collection) By(org.openqa.selenium.By) IOException(java.io.IOException) Capabilities(org.openqa.selenium.Capabilities) FileInputStream(java.io.FileInputStream) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) File(java.io.File) ImageInputStream(javax.imageio.stream.ImageInputStream) ImageReadParam(javax.imageio.ImageReadParam) ComponentUtil(org.codelibs.fess.util.ComponentUtil) SessionNotFoundException(org.openqa.selenium.remote.SessionNotFoundException) PostConstruct(javax.annotation.PostConstruct) PhantomJSDriverService(org.openqa.selenium.phantomjs.PhantomJSDriverService) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) Dimension(org.openqa.selenium.Dimension) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) IOException(java.io.IOException) SessionNotFoundException(org.openqa.selenium.remote.SessionNotFoundException)

Aggregations

Dimension (org.openqa.selenium.Dimension)24 File (java.io.File)9 Point (org.openqa.selenium.Point)7 WebDriver (org.openqa.selenium.WebDriver)6 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)4 WebElement (org.openqa.selenium.WebElement)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3 PublicAtsApi (com.axway.ats.common.PublicAtsApi)2 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)2 Execute (com.wikia.webdriver.common.core.annotations.Execute)2 VisualEditorAddMediaDialog (com.wikia.webdriver.pageobjectsfactory.componentobject.visualeditordialogs.VisualEditorAddMediaDialog)2 AdsBaseObject (com.wikia.webdriver.pageobjectsfactory.pageobject.adsbase.AdsBaseObject)2 VisualEditorPageObject (com.wikia.webdriver.pageobjectsfactory.pageobject.visualeditor.VisualEditorPageObject)2 BufferedImage (java.awt.image.BufferedImage)2 IOException (java.io.IOException)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)2 By (org.openqa.selenium.By)2