pazone / ashot

WebDriver Screenshot utility. Take screenshots, crop, prettify, compare
Other
636 stars 157 forks source link

Full screenshot - EDGE- Why do you get the pageHeight and pageWidth using javascript command? #136

Open fescobar opened 5 years ago

fescobar commented 5 years ago

I'm trying to take a full screenshot for EDGE. It works for CHROME/FIREFOX at least.

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

When I tried to do that using EDGE, throws this error:

java.lang.IllegalArgumentException: Width (0) and height (0) must be > 0
    at java.awt.image.SampleModel.<init>(SampleModel.java:126)
    at java.awt.image.ComponentSampleModel.<init>(ComponentSampleModel.java:146)
    at java.awt.image.PixelInterleavedSampleModel.<init>(PixelInterleavedSampleModel.java:87)
    at java.awt.image.Raster.createInterleavedRaster(Raster.java:641)
    at java.awt.image.Raster.createInterleavedRaster(Raster.java:278)
    at java.awt.image.BufferedImage.<init>(BufferedImage.java:376)
    at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:46)
    at ru.yandex.qatools.ashot.shooting.ViewportPastingDecorator.getScreenshot(ViewportPastingDecorator.java:35)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:145)

I see you are getting the size using javascript: https://github.com/pazone/ashot/blob/master/src/main/java/ru/yandex/qatools/ashot/shooting/ViewportPastingDecorator.java#L67

I think this error happened because that method can't execute javascript for this specific browser. Why don't try to get the size from the Selenium Driver?

driver.manage().window().getSize().getHeight();
driver.manage().window().getSize().getWidth();

I think with this fix, it will run in any browser. What do you think?

JAnton101 commented 5 years ago

Don't experience this issue with MS Edge. Use the same code. Use selenium-java version 3.141.59.

But I experience this issue with IE11:

 Screenshot screen = new AShot() .shootingStrategy(ShootingStrategies.viewportPasting(1000))
.takeScreenshot(driver);

Part of stack trace:

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.AShot.takeScreenshot(AShot.java:116)
    at ru.yandex.qatools.ashot.AShot.takeScreenshot(AShot.java:132)