ru.yandex.qatools.ashot.shooting.ShootingStrategy Java Examples
The following examples show how to use
ru.yandex.qatools.ashot.shooting.ShootingStrategy.
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 |
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: AshotFactoryTests.java From vividus with Apache License 2.0 | 6 votes |
@Test void shouldCreateAshotUsingScrollableElement() { WebElement webElement = mock(WebElement.class); ScreenshotConfiguration screenshotConfiguration = new ScreenshotConfiguration(); screenshotConfiguration.setScrollableElement(() -> Optional.of(webElement)); screenshotConfiguration.setCoordsProvider("CEILING"); screenshotConfiguration.setScreenshotShootingStrategy(Optional.empty()); AShot aShot = ashotFactory.create(false, Optional.of(screenshotConfiguration)); assertThat(Whitebox.getInternalState(aShot, COORDS_PROVIDER), is(instanceOf(CeilingJsCoordsProvider.class))); ShootingStrategy scrollableElementAwareDecorator = getShootingStrategy(aShot); assertThat(scrollableElementAwareDecorator, is(instanceOf(AdjustingScrollableElementAwareViewportPastingDecorator.class))); assertEquals(webElement, Whitebox.getInternalState(scrollableElementAwareDecorator, "scrollableElement")); ShootingStrategy scalingDecorator = getShootingStrategy(scrollableElementAwareDecorator); assertThat(scalingDecorator, is(instanceOf(ScalingDecorator.class))); verifyDPR(scalingDecorator); }
Example #3
Source File: AshotFactory.java From vividus with Apache License 2.0 | 6 votes |
private AShot createAshot(ScreenshotConfiguration screenshotConfiguration) { ShootingStrategy decorated = baseShootingStrategy.get(); int nativeFooterToCut = screenshotConfiguration.getNativeFooterToCut(); int nativeHeaderToCut = screenshotConfiguration.getNativeHeaderToCut(); if (anyNotZero(nativeFooterToCut, nativeHeaderToCut)) { decorated = cutting(baseShootingStrategy.get(), new FixedCutStrategy(nativeHeaderToCut, nativeFooterToCut)); } int footerToCut = screenshotConfiguration.getWebFooterToCut(); int headerToCut = screenshotConfiguration.getWebHeaderToCut(); if (anyNotZero(footerToCut, headerToCut)) { decorated = cutting(decorated, new StickyHeaderCutStrategy(headerToCut, footerToCut)); } decorated = ((DebuggingViewportPastingDecorator) decorateWithViewportPasting(decorated, screenshotConfiguration)) .withDebugger(screenshotDebugger); return new AShot().shootingStrategy(decorated) .coordsProvider(screenshotConfiguration.getCoordsProvider().create(javascriptActions)); }
Example #4
Source File: ScreenshotShootingStrategyTests.java From vividus with Apache License 2.0 | 5 votes |
@ParameterizedTest @MethodSource("data") void test(ScreenshotShootingStrategy strategy, Class<? extends ShootingStrategy> clazz, boolean viewportScreenshots, boolean isLandscape, String deviceName) { assertThat(strategy.getDecoratedShootingStrategy(new SimpleShootingStrategy(), viewportScreenshots, isLandscape, deviceName), instanceOf(clazz)); }
Example #5
Source File: Screenshot.java From carina with Apache License 2.0 | 5 votes |
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 #6
Source File: SeleniumDriver.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
private File getScreenShotFromAShot(WebDriver driver, ShootingStrategy strategy) throws IOException { File file = File.createTempFile("screenshot", ".png"); Screenshot screenshot = new AShot().shootingStrategy(strategy) .takeScreenshot(driver); ImageIO.write(screenshot.getImage(), "png", file); return file; }
Example #7
Source File: AdjustingRotatingDecoratorTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void testGetScreenshot() { BufferedImage image = new BufferedImage(100, 50, BufferedImage.TYPE_4BYTE_ABGR); WebDriver webDriver = mock(WebDriver.class); ShootingStrategy shootingStrategy = mock(ShootingStrategy.class); when(shootingStrategy.getScreenshot(webDriver)).thenReturn(image); CutStrategy cutStrategy = mock(CutStrategy.class); AdjustingRotatingDecorator adjustingRotatingDecorator = new AdjustingRotatingDecorator(cutStrategy, shootingStrategy, 10); BufferedImage screenshot = adjustingRotatingDecorator.getScreenshot(webDriver); assertEquals(image.getWidth(), screenshot.getHeight()); assertEquals(image.getHeight(), screenshot.getWidth()); }
Example #8
Source File: AshotFactoryTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void shouldCreateAshotWithCuttingStrategiesForNativeWebHeadersFooters() { ScreenshotConfiguration screenshotConfiguration = new ScreenshotConfiguration(); screenshotConfiguration.setNativeFooterToCut(TEN); screenshotConfiguration.setWebHeaderToCut(TEN); screenshotConfiguration.setScreenshotShootingStrategy(Optional.empty()); AShot aShot = ashotFactory.create(false, Optional.of(screenshotConfiguration)); assertThat(Whitebox.getInternalState(aShot, COORDS_PROVIDER), is(instanceOf(CeilingJsCoordsProvider.class))); ShootingStrategy viewportPastingDecorator = getShootingStrategy(aShot); assertThat(viewportPastingDecorator, is(instanceOf(AdjustingViewportPastingDecorator.class))); assertEquals(500, (int) Whitebox.getInternalState(viewportPastingDecorator, "scrollTimeout")); assertEquals(screenshotDebugger, Whitebox.getInternalState(viewportPastingDecorator, "screenshotDebugger")); ShootingStrategy webCuttingDecorator = getShootingStrategy(viewportPastingDecorator); assertThat(webCuttingDecorator, is(instanceOf(CuttingDecorator.class))); CutStrategy webCutStrategy = getCutStrategy(webCuttingDecorator); assertThat(webCutStrategy, is(instanceOf(StickyHeaderCutStrategy.class))); webCutStrategy.getHeaderHeight(null); validateCutStrategy(0, 10, webCutStrategy); ShootingStrategy nativeCuttingDecorator = getShootingStrategy(webCuttingDecorator); CutStrategy nativeCutStrategy = getCutStrategy(nativeCuttingDecorator); assertThat(nativeCutStrategy, is(instanceOf(FixedCutStrategy.class))); validateCutStrategy(10, 0, nativeCutStrategy); ShootingStrategy scalingDecorator = getShootingStrategy(nativeCuttingDecorator); assertThat(scalingDecorator, is(instanceOf(ScalingDecorator.class))); verifyDPR(scalingDecorator); }
Example #9
Source File: AshotFactoryTests.java From vividus with Apache License 2.0 | 5 votes |
@Test void shouldCreateAshotViaWithSimpleCoords() { ashotFactory.setScreenshotShootingStrategy(ScreenshotShootingStrategy.SIMPLE); ShootingStrategy strategy = ScreenshotShootingStrategy.SIMPLE .getDecoratedShootingStrategy(baseShootingStrategy, false, false, null); AShot aShot = ashotFactory.create(false, Optional.empty()); assertThat(Whitebox.getInternalState(aShot, COORDS_PROVIDER), is(instanceOf(CeilingJsCoordsProvider.class))); assertEquals(strategy, baseShootingStrategy); }
Example #10
Source File: AshotFactory.java From vividus with Apache License 2.0 | 5 votes |
private AShot createAShot(ShootingStrategy baseShootingStrategy, ScreenshotShootingStrategy screenshotShootingStrategy, boolean viewportScreenshot) { String deviceName = webDriverFactory.getCapability(SauceLabsCapabilityType.DEVICE_NAME, false); boolean landscapeOrientation = webDriverManager.isOrientation(ScreenOrientation.LANDSCAPE); ShootingStrategy shootingStrategy = screenshotShootingStrategy.getDecoratedShootingStrategy( baseShootingStrategy, viewportScreenshot, landscapeOrientation, deviceName); return new AShot().shootingStrategy(shootingStrategy) .coordsProvider(screenshotShootingStrategy == ScreenshotShootingStrategy.SIMPLE ? CeilingJsCoordsProvider.getSimple(javascriptActions) : CeilingJsCoordsProvider.getScrollAdjusted(javascriptActions)); }
Example #11
Source File: AshotFactory.java From vividus with Apache License 2.0 | 5 votes |
private ShootingStrategy decorateWithViewportPasting(ShootingStrategy toDecorate, ScreenshotConfiguration screenshotConfiguration) { return ((DebuggingViewportPastingDecorator) screenshotConfiguration.getScrollableElement().get() .map(e -> (ShootingStrategy) new AdjustingScrollableElementAwareViewportPastingDecorator( toDecorate, e, javascriptActions, screenshotConfiguration)) .orElseGet(() -> new AdjustingViewportPastingDecorator(toDecorate, screenshotConfiguration.getWebHeaderToCut(), screenshotConfiguration.getWebFooterToCut()))) .withScrollTimeout(((Long) screenshotConfiguration.getScrollTimeout().toMillis()).intValue()); }
Example #12
Source File: AdjustingViewportPastingDecorator.java From vividus with Apache License 2.0 | 5 votes |
AdjustingViewportPastingDecorator(ShootingStrategy strategy, int headerAdjustment, int footerAdjustment, String target) { super(strategy, target); this.headerAdjustment = headerAdjustment; this.footerAdjustment = footerAdjustment; }
Example #13
Source File: AdjustingRotatingDecorator.java From vividus with Apache License 2.0 | 5 votes |
AdjustingRotatingDecorator(CutStrategy cutStrategy, ShootingStrategy shootingStrategy, int adjustingIndentation) { super(cutStrategy, shootingStrategy); this.cutStrategy = cutStrategy; this.shootingStrategy = shootingStrategy; this.adjustingIndentation = adjustingIndentation; }
Example #14
Source File: AdjustingScrollableElementAwareViewportPastingDecorator.java From vividus with Apache License 2.0 | 5 votes |
public AdjustingScrollableElementAwareViewportPastingDecorator(ShootingStrategy strategy, WebElement scrollableElement, IJavascriptActions javascriptActions, ScreenshotConfiguration configuration) { super(strategy, configuration.getWebHeaderToCut(), configuration.getWebFooterToCut(), "arguments[1]"); this.javascriptActions = javascriptActions; this.scrollableElement = scrollableElement; }
Example #15
Source File: AshotFactory.java From vividus with Apache License 2.0 | 4 votes |
private AShot createAShot(ShootingStrategy baseShootingStrategy, boolean viewportScreenshot) { return createAShot(baseShootingStrategy, screenshotShootingStrategy, viewportScreenshot); }
Example #16
Source File: ViewportShootingStrategy.java From vividus with Apache License 2.0 | 4 votes |
public ViewportShootingStrategy(ShootingStrategy shootingStrategy) { this.shootingStrategy = shootingStrategy; }
Example #17
Source File: AdjustingViewportPastingDecorator.java From vividus with Apache License 2.0 | 4 votes |
AdjustingViewportPastingDecorator(ShootingStrategy strategy, int headerAdjustment) { this(strategy, headerAdjustment, 0); }
Example #18
Source File: AshotFactoryTests.java From vividus with Apache License 2.0 | 4 votes |
private void verifyDPR(ShootingStrategy scalingDecorator) { assertEquals(2f, (float) Whitebox.getInternalState(scalingDecorator, "dprX")); assertEquals(2f, (float) Whitebox.getInternalState(scalingDecorator, "dprY")); }
Example #19
Source File: AdjustingViewportPastingDecorator.java From vividus with Apache License 2.0 | 4 votes |
AdjustingViewportPastingDecorator(ShootingStrategy strategy, int headerAdjustment, int footerAdjustment) { super(strategy); this.headerAdjustment = headerAdjustment; this.footerAdjustment = footerAdjustment; }
Example #20
Source File: AshotFactoryTests.java From vividus with Apache License 2.0 | 4 votes |
private ShootingStrategy getShootingStrategy(Object hasShootingStrategy) { return Whitebox.getInternalState(hasShootingStrategy, SHOOTING_STRATEGY); }
Example #21
Source File: ViewportWithCorrectionPastingDecorator.java From vividus with Apache License 2.0 | 4 votes |
public ViewportWithCorrectionPastingDecorator(ShootingStrategy strategy) { super(strategy); }
Example #22
Source File: AssertElementImage.java From opentest with MIT License | 4 votes |
/** * 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 #23
Source File: SeleniumDriver.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 4 votes |
private File getScreenShotFromAShot(WebDriver driver, boolean fullPage) throws Exception { ShootingStrategy strategy = fullPage ? ShootingStrategies.viewportPasting(400) : ShootingStrategies.simple(); return getScreenShotFromAShot(driver, strategy); }
Example #24
Source File: ShootingTargetAreaStrategy.java From vividus with Apache License 2.0 | 4 votes |
public ShootingTargetAreaStrategy(ShootingStrategy shootingStrategy, Rectangle targetArea) { this.shootingStrategy = shootingStrategy; this.targetArea = targetArea; }