ru.yandex.qatools.ashot.shooting.ShootingStrategies Java Examples

The following examples show how to use ru.yandex.qatools.ashot.shooting.ShootingStrategies. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScreenShoter.java    From QVisual with Apache License 2.0 6 votes vote down vote up
private static ShootingStrategy getStrategy() {
    ShootingStrategy strategy = null;

    if (!DEVICE_NAME.isEmpty()) {
        switch (DEVICE_NAME) {
            case "iPhone 6S":
                strategy = ShootingStrategies.viewportRetina(SCREEN_SCROLL_TIMEOUT, new VariableCutStrategy(41, 65, 45, 100), 2F);
                break;
            case "iPad 2 (5.0)":
                strategy = iPad2WithIOS8Simulator();
                break;
            default:
                throw new RuntimeException("Unknown device name: " + DEVICE_NAME);
        }
    } else {
        if (BROWSER_RETINA) {
            strategy = viewportPasting(scaling(2), SCREEN_SCROLL_TIMEOUT);
        } else {
            strategy = viewportPasting(SCREEN_SCROLL_TIMEOUT);
        }
    }

    return strategy;
}
 
Example #2
Source File: Screen.java    From carina with Apache License 2.0 6 votes vote down vote up
@Override
public ICapturable capture(ScreenArea area) {
    try {
        switch (area) {
        case VISIBLE_SCREEN:
            screenshot = new AShot().takeScreenshot(driver).getImage();
            break;

        case FULL_SCREEN:
            screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver).getImage();
            break;
        }
    } catch (Exception e) {
        LOGGER.error("Unable to capture screenshot: " + e.getMessage());
    }
    return this;
}
 
Example #3
Source File: TakeScreenShotSeleniumLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenGoogleIsLoaded_thenCaptureLogo() throws IOException {
    WebElement logo = driver.findElement(By.id("hplogo"));

    Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000))
        .coordsProvider(new WebDriverCoordsProvider())
        .takeScreenshot(driver, logo);

    ImageIO.write(screenshot.getImage(), "jpg", new File(resolveTestResourcePath("google-logo.png")));
    assertTrue(new File(resolveTestResourcePath("google-logo.png")).exists());
}
 
Example #4
Source File: Screenshot.java    From carina with Apache License 2.0 5 votes vote down vote up
private static ShootingStrategy getScreenshotShuttingStrategy(int deviceWidth, String deviceName) {
    switch (deviceWidth) {
    case SpecialKeywords.DEFAULT_WIDTH:
        if (deviceName.contains("X")) {
            return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.IPHONE_X_HEADER,
                    SpecialKeywords.ALTERNATIVE_IOS_FOOTER, SpecialKeywords.IPHONE_X_DPR);
        } else {
            return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.DEFAULT_IOS_HEADER,
                    SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.DEFAULT_DPR);
        }
    case SpecialKeywords.DEFAULT_PLUS_WIDTH:
        if (deviceName.contains("XR")) {
            return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.IPHONE_X_HEADER,
                    SpecialKeywords.ALTERNATIVE_IOS_FOOTER, SpecialKeywords.DEFAULT_DPR);
        } else {
            return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.IPHONE_PLUS_HEADER,
                    SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.IPHONE_X_DPR);
        }
    case SpecialKeywords.DEFAULT_IPAD_WIDTH:
        return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.IPAD_HEADER,
                SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.DEFAULT_DPR);
    case SpecialKeywords.DEFAULT_SE_WIDTH:
        return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.DEFAULT_IOS_HEADER,
                SpecialKeywords.ALTERNATIVE_IOS_FOOTER, SpecialKeywords.DEFAULT_DPR);
    default:
        return ShootingStrategies.viewportRetina(SpecialKeywords.DEFAULT_SCROLL_TIMEOUT, SpecialKeywords.DEFAULT_IOS_HEADER,
                SpecialKeywords.DEFAULT_BLOCK, SpecialKeywords.DEFAULT_DPR);
    }
}
 
Example #5
Source File: AssertElementImage.java    From opentest with MIT License 4 votes vote down vote up
/**
 * Capture the image of the target HTML element.
 * @param targetLocator The locator of the HTML element to capture.
 * @param ignoredElements The HTML elements ignored from the comparison.
 * @param scaleFactor For retina displays, this has to be set to 2.
 * @param ignoredPixelsColor The color that will be used to obscure the
 * HTML elements that are ignored from the comparison.
 * @return The image of the HTML element.
 */
private BufferedImage captureImage(By targetLocator, By[] ignoredElements, Double scaleFactor, Color ignoredPixelsColor) {
    WebElement targetElement = this.getElement(targetLocator);
    ShootingStrategy shootingStrategy = ShootingStrategies.viewportPasting(ShootingStrategies.scaling(scaleFactor.floatValue()), 100);
    AShot ashot = new AShot()
            .coordsProvider(new WebDriverCoordsProvider())
            .shootingStrategy(shootingStrategy);

    // Hide scroll bars, so they don't impact the captured image
    JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
    Object overflowValue = jsExecutor.executeScript("return document.querySelector('html').style.overflow");
    if (!(overflowValue instanceof String)) {
        overflowValue = "initial";
    }
    jsExecutor.executeScript("document.querySelector('html').style.overflow = 'hidden'");

    Screenshot screenshot = ashot.takeScreenshot(driver, targetElement);
    BufferedImage capturedImage = screenshot.getImage();

    jsExecutor.executeScript(String.format("document.querySelector('html').style.overflow = '%s';", overflowValue));

    for (By by : ignoredElements) {
        Point targetElemLocation = targetElement.getLocation();

        WebElement ignoredElement = this.getElement(by);
        Point ignoredElementLocation = ignoredElement.getLocation();

        Dimension size = ignoredElement.getSize();
        int width = size.width;
        int height = size.height;

        int relativeX = ignoredElementLocation.getX() - targetElemLocation.getX();
        int relativeY = ignoredElementLocation.getY() - targetElemLocation.getY();

        for (int xCoord = relativeX; xCoord < relativeX + width; xCoord++) {
            for (int yCoord = relativeY; yCoord < relativeY + height; yCoord++) {
                capturedImage.setRGB(xCoord, yCoord, ignoredPixelsColor.getRGB());
            }
        }
    }

    return capturedImage;
}
 
Example #6
Source File: SeleniumDriver.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
private File getScreenShotFromAShot(WebDriver driver, boolean fullPage) throws Exception {
    ShootingStrategy strategy = fullPage ? ShootingStrategies.viewportPasting(400)
            : ShootingStrategies.simple();
    return getScreenShotFromAShot(driver, strategy);
}