Giter VIP home page Giter VIP logo

ashot's Introduction

aShot

release Maven Central

WebDriver Screenshot utility

  • Takes a screenshot of a WebElement on different platforms (i.e. desktop browsers, iOS Simulator Mobile Safari, Android Emulator Browser)
  • Decorates screenshots
  • Provides flexible screenshot comparison
WebElement view

aShot takes a screenshot in three simple steps:

  • Capture a screenshot of the entire page
  • Find the element's size and position
  • Crop the original screenshot

As a result, aShot provides an image of the WebElement images snippet

Maven dependency

<dependency>
    <groupId>ru.yandex.qatools.ashot</groupId>
    <artifactId>ashot</artifactId>
    <version>1.5.4</version>
</dependency>
Capturing the entire page

Different WebDrivers take screenshots differently. Some WebDrivers provide a screenshot of the entire page while others handle the viewport only. aShot might be configured to handle browsers with the viewport problem. This example configuration gives a screenshot of the entire page even for Chrome, Mobile Safari, etc.

new AShot()
  .shootingStrategy(ShootingStrategies.viewportPasting(100))
  .takeScreenshot(webDriver);

There are built-in strategies in ShootingStrategies for different use cases. In case there are no suitable strategies it is possible to build it using existing strategies as decorators or implement your own.

CutStrategy cutting = new VariableCutStrategy(HEADER_IOS_8_MIN, HEADER_IOS_8_MAX, VIEWPORT_MIN_IOS_8_SIM);
ShootingStrategy rotating = new RotatingDecorator(cutting, ShootingStrategies.simple());
ShootingStrategy pasting = new ViewportPastingDecorator(rotating)
    .withScrollTimeout(scrollTimeout);   
new AShot()
  .shootingStrategy(pasting)
  .takeScreenshot(webDriver);
Capturing the WebElement

One can take a screenshot of particular WebElement(s). Just specify the element(s).

WebElement myWebElement = webDriver.findElement(By.cssSelector("#my_element"));
new AShot()
  .takeScreenshot(webDriver, myWebElement);

As noted earlier, aShot will find an element's size and position and crop the original image. WebDriver API provides a method to find the WebElement's coordinates but different WebDriver implementations behave differently. The most general approach to find coordinates is to use jQuery, so aShot uses jQuery by default. But some drivers have problems with Javascript execution such as OperaDriver. In this case there is another way to find the WebElement's coordinates.

new AShot()
  .coordsProvider(new WebDriverCoordsProvider()) //find coordinates with WebDriver API
  .takeScreenshot(webDriver, myWebElement);

Feel free to implement your own CoordsProvider. Pull requests are welcome.

Prettifying the screenshot

So, let's take a simple screenshot of the weather snippet at Yandex.com.

new AShot()
  .takeScreenshot(webDriver, yandexWeatherElement);

Here is the result. simple weather snippet

DefaultCropper is used by default. Can we do better? Yes, we can.

new AShot()
  .withCropper(new IndentCropper()           // set custom cropper with indentation
                 .addIndentFilter(blur()))   // add filter for indented areas
  .takeScreenshot(driver, yandexWeatherElement);

indent blur weather snippet This screenshot provides more information about position relative other elements and blurs indent in order to focus on the WebElement.

Screenshot comparison

.takeScreenshot() returns a Screenshot object which contains an image and data for comparison. One can ignore some WebElements from comparison.

Screenshot myScreenshot = new AShot()
  .addIgnoredElement(By.cssSelector("#weather .blinking_element")) // ignored element(s)
  .takeScreenshot(driver, yandexWeatherElement);

Use ImageDiffer to find a difference between two images.

ImageDiff diff = new ImageDiffer().makeDiff(myScreenshot, anotherScreenshot);
BufferedImage diffImage = diff.getMarkedImage(); // comparison result with marked differences
Several elements comparison

(since 1.2)
Sometimes one needs to take a screenshot of several independent elements. In this case aShot computes complex comparison area.

List<WebElement> elements = webDriver.findElements(By.cssSelector("#my_element, #popup"));
new AShot()
  .withCropper(new IndentCropper() 
                 .addIndentFilter(blur()))
  .takeScreenshot(webDriver, elements);

Here is the result. complex comparison area

One can see only specified elements (the header and the popup) are focused and will be compared if needed.

Ignoring of pixels with predefined color

You can set the color of pixels which should be excluded from comparison of screenshots.

ImageDiffer imageDifferWithIgnored = new ImageDiffer().withIgnoredColor(Color.MAGENTA);
ImageDiff diff = imageDifferWithIgnored.makeDiff(templateWithSomeMagentaPixels, actualScreenshot);
assertFalse(diff.hasDiff());

Any pixels in template with color MAGENTA (255, 0, 255 in RGB) will be ignored during comparison.

ashot's People

Contributors

1hella avatar alb-i986 avatar borisnaguet avatar dependabot[bot] avatar ikalinin1 avatar kriegaex avatar kroartem avatar lanwen avatar leonsabr avatar naruoga avatar pazone avatar qatools-ci avatar ryanfromqa avatar smecsia avatar uarlouski avatar valfirst avatar vbauer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ashot's Issues

Screenshot only capturing upper-left corner of the visible window

I'm having trouble capturing the entire page. It appears to only be capturing the top-left corner of the page.

webDriver.navigate().to("https://www.reddit.com/");
				
String screenshotDirectoryPath = "target/site/screenshots/test/";
new File(screenshotDirectoryPath).mkdirs();
		
String outputFileName = "reddit.jpg";
File outputFile = new File(screenshotDirectoryPath + "/" + outputFileName);

Screenshot takeScreenshot = new AShot()
		.shootingStrategy(ShootingStrategies.viewportPasting(100))
		.takeScreenshot(Browser.getDriver());
BufferedImage image = takeScreenshot.getImage();

try {
	ImageIO.write(image, "jpg", outputFile);
} catch (IOException e1) {
	System.out.println("Unable to save screenshot");
	e1.printStackTrace();
}

Here's the screenshot I get with this code:
reddit

And here's a comparable screenshot I got using a chrome plugin:
download

Specs:

  • Google Chrome 59.0.3071.115 (Official Build) (64-bit)
  • Chromedriver 2.29
  • Mac OS Sierra 10.12.5
  • 2880 x 1800 resolution
  • Selenium 3.4.0
  • Java 8

No full page screenshot when using PhantomJS driver

Hi all,
I'm using Ghost Driver + Selenium in order to create a headless browser testing.
Using aShot for full page screenshot does not return the desired result - only the actual state (same result is I would use Selenium)

pom:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-server</artifactId>
    <version>3.0.1</version>
</dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-remote-driver</artifactId>
        <version>3.0.1</version>
    </dependency>

    <dependency>
        <groupId>com.codeborne</groupId>
        <artifactId>phantomjsdriver</artifactId>
        <version>1.3.0</version>
    </dependency>

    <dependency>
        <groupId>ru.yandex.qatools.ashot</groupId>
        <artifactId>ashot</artifactId>
        <version>1.5.2</version>
    </dependency>`

block code:

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true); // enabled by default
caps.setCapability(
		PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
	    "phantomjs.exe"
);

WebDriver driver = new PhantomJSDriver(caps);
driver.manage().window().maximize(); //!!!
//driver.manage().window().setSize(new Dimension(1920, 2080));///??? not s solution

driver.get("http://some.url");

WebElement userName = driver.findElement(By.id("login-form-username"));
WebElement passWord = driver.findElement(By.id("login-form-password"));

userName.sendKeys("username");
passWord.sendKeys("password");
passWord.submit();
Thread.sleep(2500);

Screenshot screenshot =
		new AShot().takeScreenshot(driver);

ImageIO.write(screenshot.getImage(), "PNG", new File("screenshot_1.png"));

driver.quit();

resulting screenshot
screenshot_1

Any suggestions?

Exclude "marked" points from comparison

Hi, thanks for AShot and please look at this feature request:

  • I want mark some area(pixels) in png file (by red/green/any color)
  • During autotests AShot should compare actual screenshot and my "marked" screenshot
  • AShot should exclude marked points (with predefined color) from comparison

Is there a way to set some ImageDiff comparison coefficient ?

I have screenshots that have minor differences and I would like to ignore them. I don't want to ignore webElements while capturing screenshots, - I just want to set some comparison rate during compare procedure, let say like uncertainty 5% between screenshots. Is it possible ?

Getting "unknown error: $ is not defined" Error..

Hello,

I am getting erorr on "Screenshot screenshot = new AShot().takeScreenshot(driver, driver.findElement(By.xpath("//*[@id='rc-imageselect-target']")));"

Any advice?

`<dependency>
	<groupId>ru.yandex.qatools.ashot</groupId>
	<artifactId>ashot</artifactId>
	<version>1.5.2</version>
</dependency>`

Code:

private void downloadImg(String imageName, String userCode) { try { Screenshot screenshot = new AShot().takeScreenshot(driver, driver.findElement(By.xpath("//*[@id='rc-imageselect-target']"))); ImageIO.write(screenshot.getImage(), "PNG", new File(imageName)); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }

org.openqa.selenium.WebDriverException: unknown error: $ is not defined
(Session info: chrome=55.0.2883.95)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.12.2 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 15 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:49:13 -0700'
System info: host: 'ITs-MacBook-Pro-7.local', ip: '10.0.0.249', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.2', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9), userDataDir=/var/folders/41/pzbtm1m57h9fpx78wl8hvp6mh6vxg_/T/.org.chromium.Chromium.nEk9HB}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.95, platform=MAC, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: 8126033dc0318682269890c03bd41228

Issue in capturing screenshot of a webElement on Chrome(Mac)

Hi,

I am not able to capture complete Web Element, Also there is some issue with the color as well.

At times, It doesn't even capture the correct element.

Screenshot screenshot= new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(driver,webElement) ;

image

Thanks.

Ashot is not working at all!

I have added maven dependency and injected Ashot to my code for selenium tests, but it is not working at all.
I was trying screenshot of whole page, screenshots of separate leements.
I receive such error after executin mvn clean test:

demoTest(framework.utils.tests.WebDriverDemoTest) Time elapsed: 16.161 sec <<<
FAILURE!
org.openqa.selenium.WebDriverException: $ is not defined
Command duration or timeout: 1.04 seconds
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43a
d8', time: '2014-10-23 13:11:40'
System info: host: 'CP0528', ip: '172.25.113.47', os.name: 'Windows 7', os.arch:
'amd64', os.version: '6.1', java.version: '1.7.0_67'
Session ID: 49c82632-7ae3-4066-b813-d5c263ae6c05
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cs
sSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts
=true, nativeEvents=true, webStorageEnabled=true, rotatable=false, locationConte
xtEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=33.0
.2}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct

orAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
onstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.
java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHa
ndler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.ja
va:599)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDri
ver.java:508)
at ru.yandex.qatools.ashot.util.JsCoords.findCoordsWithJquery(JsCoords.j
ava:26)
at ru.yandex.qatools.ashot.coordinates.JqueryCoordsProvider.ofElement(Jq
ueryCoordsProvider.java:13)
at ru.yandex.qatools.ashot.coordinates.CoordsProvider.ofElements(CoordsP
rovider.java:20)
at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:110)
at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:127)
at framework.utils.tests.WebDriverDemoTest.searchGoogleEleks(WebDriverDe
moTest.java:65)
at framework.utils.tests.WebDriverDemoTest.demoTest(WebDriverDemoTest.ja
va:49)
Caused by: org.openqa.selenium.WebDriverException: $ is not defined
Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43a
d8', time: '2014-10-23 13:11:40'
System info: host: 'CP0528', ip: '172.25.113.47', os.name: 'Windows 7', os.arch:
'amd64', os.version: '6.1', java.version: '1.7.0_67'
Driver info: driver.version: unknown
at .anonymous(https://www.google.com.ua/?gfe_rd=cr&ei=7
I1XVKGaLaaH8Qfo-oHIAw&gws_rd=ssl#q=eleks line 68 > Function:19:10)
at .handleEvaluateEvent(https://www.google.com.ua/?gfe_
rd=cr&ei=7I1XVKGaLaaH8Qfo-oHIAw&gws_rd=ssl#q=eleks:68:20)

Issue with taking full screenshot for IE browser

getting below error:

java.lang.NullPointerException
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getCurrentScrollY(ViewportPastingDecorator.java:79)
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:54)
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:35)
at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:143)

Unable to scroll and capture full screen shot of the webpage

Hi All,

I have written the below code to capture the entire webpage of [www.flipkart.com]

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import ru.yandex.qatools.ashot.AShot;
import ru.yandex.qatools.ashot.Screenshot;
import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

public class ScreenShot {

    public static WebDriver driver = null;

    public static void main(String[] args) throws IOException, InterruptedException {
                System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
        driver = new FirefoxDriver();
        driver.manage().window().maximize();

        driver.get("https://www.flipkart.com/");
        Thread.sleep(10000);


        //Take the screenshot of the entire home page and save it to a png file
        Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);

        //Screenshot screenshot = new AShot().takeScreenshot(driver, driver.findElement(By.xpath(".//*[@id='container']")));
        ImageIO.write(screenshot.getImage(), "PNG", new File("C:\\Users\\Vishvambruth JT\\Desktop\\home.png"));

        driver.quit();
    }   
}

But I'm facing the below error. Please suggest.
the code is not working even with the below line.
Screenshot screenshot = new AShot().takeScreenshot(driver, driver.findElement(By.xpath(".//*[@id='container']")));

Oct 08, 2016 2:29:09 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Attempting bi-dialect session, assuming Postel's Law holds true on the remote end
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
1475911750672   Marionette  INFO    Listening on port 54373
1475911752234   Marionette  INFO    startBrowser 7fc07847-22bf-484b-ac3b-5dfaf2f7f45f
Oct 08, 2016 2:29:12 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" java.lang.RuntimeException: org.openqa.selenium.WebDriverException: Permission denied to access property "H"
Build info: version: 'unknown', revision: '3169782', time: '2016-09-29 10:24:50 -0700'
System info: host: 'LAPTOP-JUUNTJIC', ip: '10.0.0.112', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20160922113459, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=11664, browserVersion=49.0.1, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt, device=desktop}]
Session ID: 7fc07847-22bf-484b-ac3b-5dfaf2f7f45f
    at ru.yandex.qatools.ashot.util.InnerScript.execute(InnerScript.java:29)
    at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getFullHeight(ViewportPastingDecorator.java:67)
    at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:41)
    at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:35)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:143)
    at ScreenShot.main(ScreenShot.java:35)
Caused by: org.openqa.selenium.WebDriverException: Permission denied to access property "H"
Build info: version: 'unknown', revision: '3169782', time: '2016-09-29 10:24:50 -0700'
System info: host: 'LAPTOP-JUUNTJIC', ip: '10.0.0.112', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_101'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{rotatable=false, raisesAccessibilityExceptions=false, marionette=true, appBuildId=20160922113459, version=, platform=XP, proxy={}, command_id=1, specificationLevel=0, acceptSslCerts=false, processId=11664, browserVersion=49.0.1, platformVersion=10.0, XULappId={ec8030f7-c20a-464f-9b0e-13a3a9e97384}, browserName=firefox, takesScreenshot=true, takesElementScreenshot=true, platformName=windows_nt, device=desktop}]
Session ID: 7fc07847-22bf-484b-ac3b-5dfaf2f7f45f
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:126)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:93)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:42)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:163)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:538)
    at ru.yandex.qatools.ashot.util.InnerScript.execute(InnerScript.java:27)
    ... 5 more

I'm Using:
Firefox Version: 49.0.1
Selenium Version: Version 3.0.0-beta4
OS: Win10 64 bit
Java: 1.8

Augmenter should be applied to the instances of @Augmentable classes or previously augmented instances only

I am using 1.4.12
I am getting following warning on using the ashot lib

Jun 01, 2015 1:45:24 PM org.openqa.selenium.remote.Augmenter extractRemoteWebDriver
WARNING: Augmenter should be applied to the instances of @augmentable classes or previously augmented instances only

Code that I am using

WebDriver webDriver = new FirefoxDriver();
webDriver.get("http://www.google.com");
WebElement element = webDriver.findElement(By.name("q"));
element.sendKeys("Cheese!");

Screenshot screenshot = new AShot()
.shootingStrategy(new ViewportPastingStrategy(0))
.takeScreenshot(webDriver);

File outputfile = new File("saved.png");
ImageIO.write(screenshot.getImage(), "png", outputfile);
element.submit();

Any reason why I am getting this warning ?

WebElement Screenshot does not actually take screenshot of the element

Hi,

I'm trying to feed ashot a bunch of different elements to screenshot, like this:

ru.yandex.qatools.ashot.Screenshot myScreenshot = new AShot() .takeScreenshot(_driver.getWebDriver(), element);

But despite the element size being 94*36px, Ashot will instead take a regular screenshot of the visible bit of the page, not even scrolling to the actual position of the element.

Am I doing something wrong?

Unable to get screenshot in headless Chrome

Hello,

I try to get a screenshot in headless Chrome (inside Docker) via

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(10)).takeScreenshot(driver)

and on-time get the Execption:

java.lang.RuntimeException: Unexpected result for screenshot command: null
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:391)
at ru.yandex.qatools.ashot.shooting.SimpleShootingStrategy.getScreenshot(SimpleShootingStrategy.java:31)
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:53)
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:35)
at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:145)

and next time another:

java.lang.NullPointerException
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getCurrentScrollY(ViewportPastingDecorator.java:80)
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:54)
at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:35)
at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:145)

but never without error :(

Maybe I must use another Strategy? Without ViewPortPasting I get no errors, but the created screenshot has only the viewable part of page without scrolling.

Could You please help me?
Thanks.

Not capturing complete view in iOS and Android

I wrote the below code take the screenshots in iOS and Android devices. While capturing screenshot, it is capturing complete screen view by scrolling the page until the timeout session I have given ViewPortPastingStrategy. But after merging all the screenshots, the final screenshot showing a portion of screenshot only not complete screenview.
Attached individual screenshots and finals screenshot. Code is below

final Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver);
final BufferedImage image = screenshot.getImage();
ImageIO.write(image, "PNG", "screenshot_1.png"));
ipad_ipad mini 2 homepage
screenshot-selenium-1
screenshot-selenium-2
screenshot-selenium-3
screenshot-selenium-4

Pixel Density in ViewportPastingDecorator

Hey guys,

This is more of a doubt than an issue. I have been using AShot to take full screenshots in Android. The recommendation I have followed was using ShootingStrategies.viewportRetina method passing the DPR parameter to capture the complete mobile device screen.

From my perspective, this strategy was used since the Browser width/height in the DOM do not match the actual device rendering specification. Hence, we have to pass the DPR parameter indicating the proportional rate between the device resolution and the webpage DOM dimensions.

Is there a reason for not calculating this proportional rate using the BufferedImage.getWidth obtained directly from WebDriver (SimpleShootingStrategy) and DOM width in ViewportPastingDecorator class?

Willian.

Configurable Indent for Blurred Image

I have been experimenting with using the blur feature of aShot. I have been able to get it to work, but the imageCropper is cropping too much of the page. Is there a way to configure this to still show the entire page, but blur everything except the given webElement?

VerticalPastingShootingStrategy locally may work wrong

If you need to make screenshots on your local monitor (for example, laptop display) there might occur difference between

$(window).height()

and

BufferedImage baseImage = simple().getScreenshot(wd);
int h = baseImage.getHeight();

This is because high-resolution monitors (like retina displays) perform image scaling.
For example, I get following values:

$(window).height(); 728

BufferedImage baseImage = simple().getScreenshot(wd);
int h = baseImage.getHeight(); 1456

and finally this causes missing part of image when parts are combined:

for (int n = 0; n < scrollTimes; n++) {
    js.executeScript("scrollTo(0, arguments[0])", winH * n);
    waitForScrolling();
    BufferedImage part = super.getScreenshot(wd);
    graphics.drawImage(part, 0, n * winH, null);
}

scrolling problem with IE and Safari "webdriver -Ashot"

public class IndiaTimes {
public static void main(String[] args) throws IOException, InterruptedException {
WebDriver wd = new SafariDriver();
wd.get("http://www.indiatimes.com");
Thread.sleep(5000);
((JavascriptExecutor) wd).executeScript("$('#wrap header').hide();");
Thread.sleep(500);
WebElement we = wd.findElement(By.cssSelector("#hp_block_2"));
final Screenshot screenshot = new AShot()
.shootingStrategy(new ViewportPastingStrategy(1500))
.takeScreenshot(wd, we);
final BufferedImage image = screenshot.getImage();
ImageIO.write(image, "PNG",
new File(System.getProperty("user.home") + "/AShot_indiatimes.png"));
}
}

@abhishekkyd @pazone @frolovs I am using the code that you are suggesting that it will work for safari, but it is not working for me on safari... I have attached the screenshot I obtained using the code above... please provide any configuration i need for Safari and IE.
I am new sorry if i ask some silly question or use inappropriate words...
thank you
image

Taking full screenshot with Ashot (IE and Safari)

hello everyone , I am very new with Ashot, I was trying to get browser full screenshot, I can take it fine with Opera, Chrome but it repeat the first display screen image for the rest of the browser. Is there different function i need to use for different browser (safari, IE and fireforx).

please provide me a sample code and help.

your time and sample code will be much appreciated.

Cheeers

Typo in ru.yandex.qatools.ashot.comparison.ImageMarkupPolicy

result variable is overwritten two times in ImageMarkupPolicy.

    @Override
    public int hashCode() {
        int result = diffPointCount;
        result = 31 * result +  xSum - diffPointCount * xReference;
        result = 31 * result +  ySum - diffPointCount * yReference;
        return result;
    }

Looks like it should be += instead of =

Getting NullPointerException when using ashot in my project

I am working on below code

    WebDriver wd = new FirefoxDriver();     
    wd.get("http://www.indiatimes.com");

    new AShot()
      .shootingStrategy(new ViewportPastingStrategy(0))
      .takeScreenshot(wd);

getting below error, please suggest the solution

Exception in thread "main" java.lang.NullPointerException
at ru.yandex.qatools.ashot.screentaker.VerticalPastingShootingStrategy.shiftCoords(VerticalPastingShootingStrategy.java:90)
at ru.yandex.qatools.ashot.screentaker.VerticalPastingShootingStrategy.getScreenshot(VerticalPastingShootingStrategy.java:43)
at ru.yandex.qatools.ashot.screentaker.VerticalPastingShootingStrategy.getScreenshot(VerticalPastingShootingStrategy.java:33)
at ru.yandex.qatools.ashot.screentaker.ScreenTaker.take(ScreenTaker.java:25)
at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:166)
at ru.yandex.qatools.elementscompare.tests.MyTest.main(MyTest.java:28)

Unable to capture proper full screenshot in Chrome

I am using below code to capture screenshot in chrome but it capture same thing multiple times in screenshot. I just want to take full screenshot of page in chrome browser.

Screenshot screenshot = new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(500))
.takeScreenshot(driver);

Getting WebDriverException when using AShot in my project to capture a webelement

Hii Ashot Team,
I'm getting WebDriver Exception for taking screenshot of an invisible element (need to scroll down to find this element).
Exception:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: $ is not defined
Code :
WebElement element = driver.findElement(By.cssSelector("#imgId"));
Screenshot screenshot = new AShot().shootingStrategy(new ViewportPastingStrategy(1000)).takeScreenshot(driver,element);
ImageIO.write(screenshot.getImage(), "PNG", new File("C:\screenshot.png"));

Element blur screenshots are cropped incorrectly on retina screen in Google Chrome

I am using this method to crop element screenshot:
private static BufferedImage blurElementOnScreenShot(WebDriver driver,
WebElement element) {
Screenshot imageScreen = new AShot()
.coordsProvider(new WebDriverCoordsProvider())
.imageCropper(new IndentCropper() // overwriting cropper
.addIndentFilter(new BlurFilter()))
.takeScreenshot(driver, element); // adding filter for indent

    return imageScreen.getImage();
}

and I am using MAcBook Pro with retina - images are cropped incorrectly in Chrome. The blur effect highlight images incorrectly.
!!! But everything is fine for Firefox browser.

Unable to get correct screenshot when scrollbar in an iFrame

Hi

In my application, the scroll bar is in an iframe and all content populate inside that. With the statements mentioned in readme, I am not able to get the complete screenshot. It is skipping few sections to get populate on screen shot. Is there any workaround on same.

You can take any force.com console application to repro this.

Thanks.

Getting WebDriverException when using AShot in my project to capture a webelement

Hi AShot Team,

When I am executing below Java program, I am getting WebDriver Exception for takescreenshot method. Please look into the issue and help me to resolve this. I am using AShot version 1.4.12

System.setProperty("webdriver.chrome.driver",
                "src/main/resources/drivers/chromedriver");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();

        driver.get("http://www.bbc.com");
        Thread.sleep(10000);

        WebElement element = driver
                .findElement(By.cssSelector("#worldService"));

        final Screenshot screenshot = new AShot().shootingStrategy(
                new ViewportPastingStrategy(500)).takeScreenshot(driver,
                element);
        final BufferedImage image = screenshot.getImage();
        ImageIO.write(image, "PNG", new File(System.getProperty("user.home")
                + "/Documents/AShot_BBC_WebElement.png"));

        driver.quit();

Exception:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: undefined is not a function
  (Session info: chrome=43.0.2357.81)
  (Driver info: chromedriver=2.15.322455 (ae8db840dac8d0c453355d3d922c91adfb61df8f),platform=Mac OS X 10.10.3 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 6 milliseconds
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09:10:26'
System info: host: 'Abhisheks-MacBook-Pro.local', ip: '192.168.1.34', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.3', java.version: '1.7.0_79'
Session ID: 3282b4dba0e5dfaf74c935d511ab485e
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/fm/thrpfvws2dj9kglbtz3278wstl_32s/T/.org.chromium.Chromium.F8GFJ2}, rotatable=false, locationContextEnabled=true, mobileEmulationEnabled=false, version=43.0.2357.81, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, takesScreenshot=true}]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
    at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:508)
    at ru.yandex.qatools.ashot.util.JsCoords.findCoordsWithJquery(JsCoords.java:26)
    at ru.yandex.qatools.ashot.coordinates.JqueryCoordsProvider.ofElement(JqueryCoordsProvider.java:13)
    at ru.yandex.qatools.ashot.coordinates.CoordsProvider.ofElements(CoordsProvider.java:21)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:138)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:155)
    at com.tribune.uiautomation.testscripts.AShotTestEntirePage.main(AShotTestEntirePage.java:33)

Getting black spot on the Chrome - Tablet Emulator screenshot while Capturing the entire page

Getting black spot on the Chrome-Tablet emulator screenshot while Capturing the entire page by using
new AShot()
.shootingStrategy(ShootingStrategies.viewportPasting(100))
.takeScreenshot(webDriver);

Same works fine for Chrome- Phone emulator.

Please provide resolution for this issue.

Here is the code.
String baseUrl = "https://github.com/yandex-qatools/ashot";

    Map<String, String> mobileEmulation = new HashMap<String, String>();
    mobileEmulation.put("deviceName", "Apple iPad");
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    chromeOptions.put("mobileEmulation", mobileEmulation);
    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    WebDriver driver = new ChromeDriver(capabilities);
    driver.manage().window().maximize();

    driver.get(baseUrl);

    final Screenshot screenshot = new AShot()
              .shootingStrategy(ShootingStrategies.viewportPasting(100))
              .takeScreenshot(driver);

    final BufferedImage image = screenshot.getImage();
    ImageIO.write(image, "PNG", new File("C:\\Selenium\\"+ "Ahot-Tablet.png"));

Tablet Screenshot:
ahot-tablet

Phone Screenshot:
ahot-phone

How to set transparent color?

Using aShot 1.5.2 version in project. And have a problem. How to set transparent color for ignorred regions of image?
Try use
ImageDiffer imageDifferWithIgnored = new ImageDiffer().withIgnoredColor(Color.MAGENTA);
but method withIgnoredColor() is not found in lib.

Thanks!

readme.md not actual

On readme.md may see following code:

new AShot()
  .shootingStrategy(new ViewportPastingStrategy())
  .takeScreenshot(webDriver);

But class ViewportPastingStrategy doesn't exists.

Example github project with Ashot

This is more like question and not an issue.

I wonder whether there is any working example project on github using Ashot where everything required is already programmed.. For example:
Frist run:
The baseline creation of full page or elements on a page
Second run:
The compare

This way i don't have to build all functionalities from scratch

WARNING: Augmenter should be applied to the instances of @Augmentable classes or previously augmented instances only

I am getting following warning on using the ashot lib

lis 30, 2016 12:57:14 PM org.openqa.selenium.remote.Augmenter extractRemoteWebDriver
WARNING: Augmenter should be applied to the instances of @augmentable classes or previously augmented instances only
lis 30, 2016 12:57:16 PM org.openqa.selenium.remote.Augmenter extractRemoteWebDriver
WARNING: Augmenter should be applied to the instances of @augmentable classes or previously augmented instances only

ashot 1.5.2
selenium 2.53.0
code:
public class ashot {

private static WebDriver driver;

@BeforeTest
public void setUp() throws Exception {
    System.setProperty("webdriver.chrome.driver", "./libs/chromedriver.exe");
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    driver = new ChromeDriver(cap);

}

@Test
public void github() throws IOException{
    driver.get("https://github.com");
    Screenshot screenshot = new AShot()
                .shootingStrategy(ShootingStrategies.viewportPasting(100))
                .takeScreenshot(driver);
    ImageIO.write(screenshot.getImage(), "PNG", new File("./ashot/screen.png"));
}


@AfterTest
public void close() {
    driver.quit();
}

}

Only Current Screen is captured in Chrome Driver

Hi AShot Team,
When I run the below java code it runs properly,but it captures only current screen. The below part of screen is not captured by this code. please see the below code ๐Ÿ‘

System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("http://www.bbc.com");
			Thread.sleep(5000);
			(new WebDriverWait(driver, 60)).until(new ExpectedCondition<WebElement>() {
				public WebElement apply(WebDriver newDriver) {
					return newDriver.findElement(By.cssSelector(".wsradio__title__link"));
				}
			});
final Screenshot screenshot = new AShot().coordsProvider(new WebDriverCoordsProvider()).takeScreenshot(driver);
final BufferedImage image = screenshot.getImage();
ImageIO.write(image, "PNG", new File("D:\\temp\\"+ "AShot_BBC_Entire.png"));
driver.quit();

Please provide the solution. It works perfectly in Firefox browser.

screenshot with webdriver +Ashot for opera

@pazone
i have read on the link bellow you have mentioned that using Ashot you could successfully get full screenshot.
http://yuluer.sc0713.com/page/cdjjhhab-selenium-webdriver-screenshots-in-opera.shtml#f_pst
Its not working for me, could you please give me the details of your drivers version and browser version you are using, plus if you can provide me with a working code would be much appreciated.

@smecsia @vbauer @eroshenkoam @BorisNaguet @andreas Bovens @cosimo Streppone

please feel free to provide code sample if you feel generous to help new comer

thx SeekingKowledge

Select colour of difference markigs

It would be nice if the colour for the difference markings could be changed.
If the screenshot contains many red elements, it can be difficult to see where the markings are since they currently are of a pale red.

.net Version?

Hey,

I don't suppose there is a .net version of this library available?

ViewportPastingStrategy not available

The readme states that I should using the following code but ViewportPastingStrategy() doesn't exist in 1.5.2.

new AShot()
.shootingStrategy(new ViewportPastingStrategy())
.takeScreenshot(webDriver);

Unable to see full web page view of mobile web site

I am trying to capture full mobile web page view using Ashot latest jar. Following are the code I used

Screenshot sh = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(500)).takeScreenshot(driver);

BufferedImage fullScreen = sh.getImage();

ImageIO.write(fullScreen, "png", new File("D:\test"+"coool.png"));

Site: http://www.rapidvaluesolutions.com/

Loaded in Mobile Web and captured using above code.

Attached screenshot.
coool

Page elements are not ignored

I'm using this construction to exclude elements on my page from diff comparison:

AShot shooter = new AShot().shootingStrategy(ShootingStrategies.simple())
                .ignoredElements(ignoredElements).coordsProvider(new WebDriverCoordsProvider());

However my test is failing and I see marked image with areas it's supposed to ignore.

Ashot version 1.5.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.