Code Monkey home page Code Monkey logo

selenium-shutterbug's Introduction

selenium-shutterbug

Build Status Maven Central

Synopsis

Selenium Shutterbug is a utility library written in Java for making screenshots using Selenium WebDriver and further customizing, comparing and processing them with the help of Java AWT.

The idea behind the project is to make testers life easier by enabling them to create descriptive screenshots which, in some cases, could be directly attached to the bug reports or serve as a source of information about system state at a specific moment of time.

Selenium WebDriver version 4+ support starts from version 1.6

Temporary workaround for Selenium v4+ in case of using RemoteWebDriverBuilder

Instead of:

WebDriver driver = RemoteWebDriver.builder().address("http://gridurl:4444").addAlternative(new ChromeOptions()).build();

use

URL remoteAddress = new URL("http://gridurl:4444/wd/hub");
Tracer tracer = OpenTelemetryTracer.getInstance();
ClientConfig config = ClientConfig.defaultConfig().baseUrl(remoteAddress);
CommandExecutor executor = new HttpCommandExecutor(Collections.emptyMap(), config, new TracedHttpClient.Factory(tracer, org.openqa.selenium.remote.http.HttpClient.Factory.createDefault()));
CommandExecutor executorTraced =  new TracedCommandExecutor(executor, tracer);
WebDriver webDriver = new RemoteWebDriver(executorTraced, new ChromeOptions());

The reasoning is described in #103

Supported features:

  • Capturing the entire page
  • Screenshot comparison (with diff highlighting)
  • Capturing the WebElement
  • Capturing entire scrollable WebElement
  • Capturing frame
  • Creating thumbnails
  • Screenshot customizations:
    • Highlighting element on the page
    • Highlighting element on the page with added text
    • Blur WebElement on the page (e.g. sensitive information)
    • Blur whole page
    • Blur whole page except specific WebElement
    • Monochrome WebElement
    • Crop around specific WebElement with offsets

Installation

The project is available in Maven Central

Maven dependency
<dependency>
    <groupId>com.assertthat</groupId>
    <artifactId>selenium-shutterbug</artifactId>
    <version>1.6</version>
    <exclusions>
        <exclusion>
	    <groupId>org.seleniumhq.selenium</groupId>
	    <artifactId>selenium-java</artifactId>
	</exclusion>
     </exclusions>
</dependency>
Using Gradle
compile ('com.assertthat:selenium-shutterbug:1.6') {
    exclude group: "org.seleniumhq.selenium", name: "selenium-java"
    }
Using SBT
"com.assertthat" % "selenium-shutterbug" % "1.6" exclude("org.seleniumhq
.selenium", "selenium-java"),

Code Example

Below are some basic examples of usage.

Page screenshots

  • Take screenshot and save to default location (./screenshots/):
  Shutterbug.shootPage(driver).save();
  • Take screenshot and specify location to save to:
  Shutterbug.shootPage(driver).save("C:\\testing\\screenshots\\");
  • Wait for condition before taking screenshot:
   Shutterbug.wait(visibilityOfElementLocated(By.id("someId")), 5).shootPage(driver, Capture.FULL).save();
  • Take screenshot and scroll in both directions (Will make full page screenshot in Chrome):
  Shutterbug.shootPage(driver, Capture.FULL_SCROLL).save();
  • Take screenshot and scroll in both directions with half a second scrolling timeout (Will make full page screenshot in Chrome) and use devicePixelRatio - for retina displays:
  Shutterbug.shootPage(driver, Capture.FULL_SCROLL ,500,true).save();
  • Take screenshot of the whole page using Chrome DevTools. This is applicable for Chrome only. Use this one instead of ScrollStrategy.WHOLE_PAGE if page has sticky header or any other sticky elements.
  Shutterbug.shootPage(driver, Capture.FULL,true).save();

WebElement screenshots

  • Take screenshot of specified WebElement only:
  Shutterbug.shootElement(driver, element).save();

Screenshots comparison

  • Compare screenshot taken with the expected one with specified deviation rate (for example 0.1 represents that if image differences are less than 10% the images are considered to be equal):
  Shutterbug.shootPage(driver).equals(otherImage,0.1);
  • Compare screenshot taken with the expected one with specified deviation rate and create new image with differences highlighted (for example 0.1 represents that if image differences are less than 10% the images are considered to be equal and no resulting image with highlighted differences produced):
  Shutterbug.shootPage(driver).equalsWithDiff(otherImage,pathToNewImage,0.1);
  • Compare screenshot taken with the expected one and create new image with differences highlighted:
  Shutterbug.shootPage(driver).equalsWithDiff(otherImage,pathToNewImage);

Screenshots Thumbnails

  • Take screenshot and save thumbnail as well (with specified resize ratio):
  Shutterbug.shootPage(driver).withThumbnail(0.4).save();

Frame screenshots

  • Take screenshot of scrollable frame locatable by supplied frameID:
driver.switchTo().defaultContent();
Shutterbug.shootFrame(driver, "frameID", CaptureElement.FULL_SCROLL).save();
  • Take screenshot of scrollable frame web element:
driver.switchTo().defaultContent();
Shutterbug.shootFrame(driver, frameWebElement, CaptureElement.FULL_SCROLL).save();

Please note

  • Currently full scrollable frame screenshot is only possible when the full frame is visible in the viewport. If frame size is greater than viewport size UnsupportedOperationException will be throws suggesting to use CaptureElement.VIEWPORT instead.
  • Need to perform driver.switchTo().defaultContent(); before frame screensot. After the screenshot is taken driver will stay switched to the target frame.

Scrollable WebElements screenshots

  • Take screenshot of scrollable web element. Horizontal capture only:
Shutterbug.shootElement(driver, webElement, CaptureElement.HORIZONTAL_SCROLL).save();

Operations chaining

To demonstrate how it all can be pieced together the example follows:

    System.setProperty("webdriver.chrome.driver", "your path to  chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com/imghp");
        WebElement googleLogo = driver.findElement(By.id("hplogo"));
        WebElement searchBtn = driver.findElement(By.id("sblsbb"));
        WebElement searchBox = driver.findElement(By.className("gsfi"));

        searchBox.sendKeys("Testing");

        Shutterbug.shootPage(driver)
                .blur(searchBox)
                .highlight(searchBtn)
                .monochrome(googleLogo)
                .highlightWithText(googleLogo, Color.blue, 3, "Monochromed logo",Color.blue, new Font("SansSerif", Font.BOLD, 20))
                .highlightWithText(searchBox, "Blurred secret words")
                .withTitle("Google home page - " + new Date())
                .withName("home_page")
                .withThumbnail(0.7)
                .save("C:\\testing\\screenshots\\");
        driver.quit();

Available capture types

VIEWPORT - capture visible part of the viewport only

FULL - full page screenshot using devtools

FULL_SCROLL - full page/element/frame screenshot using scroll & stitch method

VERTICAL_SCROLL - vertical scroll page/element/frame screenshot using scroll & stitch method

HORIZONTAL_SCROLL - horizontal scroll page/element/frame screenshot using scroll & stitch method

Contributing

For details please read CONTRIBUTING

License

Code released under the MIT license

selenium-shutterbug's People

Contributors

andyphillips404 avatar anna-shchurok avatar beatngu13 avatar bielinskilukasz avatar christophkaser avatar deepthought42 avatar dependabot[bot] avatar glibas avatar inha-briia avatar jpratt2 avatar koichirok avatar oriash93 avatar peterd23 avatar unleashurgeek avatar zeeshanyshaikh 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

selenium-shutterbug's Issues

Retina methods are not available

I added newest available version of shutterbug to my POM:

<dependency>
<groupId>com.assertthat</groupId>
<artifactId>selenium-shutterbug</artifactId>
<version>0.5</version>
</dependency>

but newest retina methods are not loading:
Sources:

public class Shutterbug {

    private static final int DEFAULT_SCROLL_TIMEOUT = 100;

    public Shutterbug() {
...
    }

    public static PageSnapshot shootPage(WebDriver driver) {
...
    }

    public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll) {
...
    }

    public static PageSnapshot shootPage(WebDriver driver, ScrollStrategy scroll, int scrollTimeout) {
...
    }

    public static ElementSnapshot shootElement(WebDriver driver, WebElement element) {
...
    }
}

Am I doing something wrong?

Crop page and focus on captured element

Currently if we use the .shootElement it will result in only the defined element captured.
2017_10_04_13_54_40_749

Is it possible to setup so we can capture the element while still showing relative other elements around?
2017_10_04_13_54_40_298

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils

I am receiving the error when using shootElement method.

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils
at com.assertthat.selenium_shutterbug.utils.file.FileUtil.getJsScript(FileUtil.java:32)
at com.assertthat.selenium_shutterbug.utils.web.Browser.executeJsScript(Browser.java:255)
at com.assertthat.selenium_shutterbug.utils.web.Browser.scrollToElement(Browser.java:247)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootElement(Shutterbug.java:149)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootElement(Shutterbug.java:135)

question: why using JS execution to pull location & dimension of an element

regarding the implementation from here

why do you use "hard-core" JS execution, when you could simply pull the information directly from the WebElement?

WebElement el;
el.getLocation(); // returns a Point
el.getSize(); // returns a Dimension

    public Coordinates getBoundingClientRect(WebElement element) {
        return new Coordinates(element.getLocation(), element.getSize());
    }

The output screenshot captured by sutterbug doesn't seems to be correct

Hi All,

I have written the below code. But the out put captured by Shutterbug doesn't seems to be correct. Could you please check.

import java.awt.Color;
import java.awt.Font;
import java.util.Date;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import com.assertthat.selenium_shutterbug.core.Shutterbug;
import com.assertthat.selenium_shutterbug.utils.web.Browser;
import com.assertthat.selenium_shutterbug.utils.web.ScrollStrategy;

public class ShutterBug {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Eclipse\\Drivers\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        //driver.manage().window().maximize();
        driver.get("https://www.google.com/");
        WebElement googleLogo = driver.findElement(By.xpath(".//*[@id='logo']"));
        WebElement searchBtn = driver.findElement(By.xpath(".//*[@id='sblsbb']"));
        WebElement searchBox = driver.findElement(By.xpath(".//*[@id='lst-ib']"));

        searchBox.sendKeys("Testing");  

        Shutterbug.shootPage(driver)
            .blur(searchBox)
            .highlight(searchBtn)
            .monochrome(googleLogo)
            .highlightWithText(googleLogo, Color.blue, 3, "Monochromed logo",Color.blue, new Font("SansSerif", Font.BOLD, 20))
            .highlightWithText(searchBox, "Blurred secret words")
            .withTitle("Google home page - " + new Date())
            .withName("home_page")
            .withThumbnail(0.7)
            .save("C:\\Users\\Vishvambruth JT\\Desktop\\Screen.jpg");
            driver.quit();
    }
}

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

home_page

Reset the full screen resolution after taking screenshot using chrome command

Hi, Am currently facing issue where after taking the full page screen shot using chrome command its not resetting the viewport even after refreshing the page. I end up searching on google and found that viewport is not reset on setting the new values

this.sendCommand("Emulation.setDeviceMetricsOverride", metrics);

After taking the screenshot it should be reset using below command
send('Emulation.clearDeviceMetricsOverride', {})

as found here

Please resolve. Thanks

Headers and other Static Web contents issue

So I'm currently using the code below :

Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS, 300).withName(fileName).save(screenshotDestination.getAbsolutePath());

It successfully makes the screenshot but the headers and fixed images are always stuck on the screenshot.png file.

Please see images on the links :
The header is always on the screenshot : https://drive.google.com/file/d/0B_PXSe2aM-mTc1dYdjlIelhrX00/view?usp=sharing

Are there any workaround on this issue?

Scroller listener

Hi!

I would like to know if it's possible to have a extensible scroller, so one could, for instance, hide fixed elements after the first scroll down and such.

What do you think?

Custom names for screenshots?

Hi, do we have a way to set custom names for screenshots? There's a directory that I want the screenshots to, but I'm looking for a way to have custom names for the screenshot instead of the date-time auto generated names. Is this possible?

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils

Hi,
I've imported the jar in my project (automation test on varius site) btw when I call:
Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS).save();

i receive that errors:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils
at com.assertthat.selenium_shutterbug.utils.file.FileUtil.getJsScript(FileUtil.java:32)
at com.assertthat.selenium_shutterbug.utils.web.Browser.executeJsScript(Browser.java:193)
at com.assertthat.selenium_shutterbug.utils.web.Browser.getDocWidth(Browser.java:161)
at com.assertthat.selenium_shutterbug.utils.web.Browser.takeScreenshotEntirePage(Browser.java:82)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:98)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:72)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:58)

Can u explain why, so I can fix my code?

Thanks

Sutterbug with mobile

Hi,
I tried shutterbug with web, it is working fine. I tried with android and ios, but i am getting the following error.
Session ID: 1fa95a27-8a33-45dd-a664-ceb47a0ed94e
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:231)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:485)
at com.assertthat.selenium_shutterbug.utils.web.Browser.executeJsScript(Browser.java:266)
at com.assertthat.selenium_shutterbug.utils.web.Browser.getViewportHeight(Browser.java:243)
at com.assertthat.selenium_shutterbug.utils.web.Browser.takeScreenshotEntirePageUsingChromeCommand(Browser.java:182)
at com.assertthat.selenium_shutterbug.utils.web.Browser.takeScreenshotEntirePage(Browser.java:119)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:110)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:72)
at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:86)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:822)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1130)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:782)
at org.testng.TestRunner.run(TestRunner.java:632)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:366)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319)
at org.testng.SuiteRunner.run(SuiteRunner.java:268)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1244)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
at org.testng.TestNG.run(TestNG.java:1064)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:113)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:206)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:177)

ScrollStrategy halves screenshots

While using ScrollStrategy to capture full page screenshot, it halves output screenshots (for some reason).
Code example:

        WebDriver driver = new ChromeDriver();
        driver.get("https://www.linkedin.com");
        Shutterbug.shootPage(driver).save(".");
        Shutterbug.shootPage(driver, ScrollStrategy.VERTICALLY).save(".");

Resultant screenshots:
2017_12_27_16_05_58_785
2017_12_27_16_06_00_650

Accidental issue

Hello Everyone,

I was typing up an issue, then accidentally hit the "Submit new issue" button at the bottom of the page. It appears that one cannot completely get rid of an issue once one's posted it:

isaacs/github#253

In whole-page screenshots with Firefox only the upper part of the page is captured

Hi,

I'm dealing with the problem that when taking a whole page screenshot, only the upper part of the viewport is taken.

2019_11_07_14_13_58_326

Steps to reproduce

Used versions:

Firefox version 70.0.1 (64-Bit)
geckodriver-v0.26.0-macos
Java OpenJDK 11
macOS Catalina Version 10.15.1
selenium-java version 3.141.59
selenium-shutterbug version 0.9.3

Here's a snippet of the relevant code:

final FirefoxOptions opts = new FirefoxOptions();
opts.addArguments( "--headless", "--window-size=1200,800" );
driver = new FirefoxDriver( opts );

driver.get( "https://stackoverflow.com" );
Shutterbug.shootPage( driver, ScrollStrategy.WHOLE_PAGE, 500, true ).save( "/Users/abc/Downloads/whole_page" );

driver.quit();

Thanks in advance.

Unknown error: cannot focus element

Hi All,

I have written the below code

import java.awt.Color;
import java.awt.Font;
import java.util.Date;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import com.assertthat.selenium_shutterbug.core.Shutterbug;

public class ShutterBug {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Eclipse\\Drivers\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.com/");
        WebElement googleLogo = driver.findElement(By.xpath(".//*[@id='hplogo']"));
        WebElement searchBtn = driver.findElement(By.xpath(".//*[@id='tsf']/div[2]/div[3]/center/input[1]"));
        WebElement searchBox = driver.findElement(By.xpath(".//*[@id='sb_ifc0']"));

        searchBox.sendKeys("Testing");

        Shutterbug.shootPage(driver)
            .blur(searchBox)
            .highlight(searchBtn)
            .monochrome(googleLogo)
            .highlightWithText(googleLogo, Color.blue, 3, "Monochromed logo",Color.blue, new Font("SansSerif", Font.BOLD, 20))
            .highlightWithText(searchBox, "Blurred secret words")
            .withTitle("Google home page - " + new Date())
            .withName("home_page")
            .withThumbnail(0.7)
            .save("C:\\Users\\Vishvambruth JT\\Desktop\\Screen.jpg");
            driver.quit();
    }
}

But the code is failing with the below error:

Starting ChromeDriver 2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b) on port 32342
Only local connections are allowed.
Oct 09, 2016 1:33:03 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.
Oct 09, 2016 1:33:05 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: unknown error: cannot focus element
  (Session info: chrome=53.0.2785.143)
  (Driver info: chromedriver=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 78 milliseconds
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.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, chrome={chromedriverVersion=2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b), userDataDir=C:\Users\VISHVA~1\AppData\Local\Temp\scoped_dir11416_8399}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=53.0.2785.143, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 7bf71af0c3983c11b1fb2417f703dad0
    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.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:164)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:636)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:284)
    at org.openqa.selenium.remote.RemoteWebElement.sendKeys(RemoteWebElement.java:108)
    at ShutterBug.main(ShutterBug.java:23)

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

Retina display

I have a problem on retina display, screen looks like this
gitgub

on non retina is ok

github

driver.get("https://github.com");
Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS).save();

Capture screenshot not proper in mac safari browser

WebDriver driver = new SafariDriver();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.manage().window().maximize();

	driver.get("https://www.amazon.in/");
   
	
	Shutterbug.shootPage(driver, ScrollStrategy.WHOLE_PAGE).save("/Users/abc/Documents/web.png");
	
	driver.quit();

2019_11_06_14_17_43_968

The vertical site has been cut.

Vertical Screenshot on Mobile is HALVED

Tried the code below :

Shutterbug.shootPage(driver, ScrollStrategy.VERTICALLY).save("/screenshots");

Result is that the VERTICAL part is captured correctly, but the HORIZONTAL part is missing.

Tried removing the ScrollStrategy and it works fine but I'm missing the whole page screenshot.

Taking a snapshot of an iframe with scroll bars

Hello,
I'm trying to take a snapshot of an iframe element that has a scrollbar. Does anyone know of a way to do this that would be less invasive than creating a forked version of selenium-shutterbug with a new function similar to Browser.takeScreenshotEntirePage() that would scroll through an iframe and create an image of the whole iframe?

I'm using shutterbug as a part of Fitnesse/Xebium/Selenium in order to do regression testing, so I don't have access to the webpage that I'm taking a screenshot of (so I can't get rid of the scroll bars). I'm not going to post a picture of the system I'm testing (I don't think the person who owns that system would be alright with that), but to help give an idea of what I'm talking about, the iframe has scroll bars similar to the code box in the following screenshot:

screenshot_6

Remove or ignore duplicate navigation bar

I am trying to capture full page using Firefox in headless mode.
Using this Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS), I manage to get it to scroll and shot, but the results kinda looks ugly because we use navigation bar on the top and left.
8db913dabbb19e56
If we try to use shootElement and try to capture the body only, we'll get "Requested element is outside the viewport".

Any idea how we can solve this duplicating issue? Can we maybe ignore spesific elements when capturing?

[help] Infinite scrolling pages - timeout?

Hi!

What's the best approach on screenshots for infinite scrolling page?
Is there a maximum scrolling time parameter or something like this?
From what I've saw in the source code, there isn't such a param... anyway, would this be the best approach?

How to embed a screenshot from shutterbug to a scenario

How can i embed a shutterbug screenshot to my scenario?:

//current code

byte[] screenshot = webDriver.getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");

//throws java.lang.ClassCastException: java.awt.image.DataBufferInt cannot be cast to java.awt.image.DataBufferByte:

BufferedImage image = Shutterbug.shootPage(webDriver, ScrollStrategy.BOTH_DIRECTIONS).getImage();
byte[] screenshot = ((DataBufferByte) convertedImg.getData().getDataBuffer()).getData();
scenario.embed(screenshot, "image/png");

`getDocHeight()` incorrectly returning viewport height for some applications

I am using Chrome 79.0.3945.88 (64-bit) and Selenium WebDriver 3.141.59. When I use a public website like Google or Wikipedia the WHOLE_PAGE strategy works fine. I can see the page scrolling and the screenshot reflects that,

Using a proprietary application (Guidewire PolicyCenter, a major insurance system vendor), however, it doesn’t work. I’ve done some tracing and discovered the exact issue: com.assertthat.selenium_shutterbug.utils.web.Browser.getDocHeight() always returns the same value as com.assertthat.selenium_shutterbug.utils.web.Browser.getViewportHeight(). In short, the called JavaScript,

return Math.max(document.body.scrollHeight, document.body.offsetHeight, 
document.documentElement.clientHeight, document.documentElement.scrollHeight, 
document.documentElement.offsetHeight);

Simply returns the viewport height.

I don’t have any knowledge of the web UI framework that PolicyCenter uses and, unfortunately, I can’t provide access to PolicyCenter, as we use it over a VPN.

Have you ever seen anything like this before? Do you have any suggestions?

All Screenshots Black

Hi,

I'm running Ubuntu 16.04 with XFCE window manager. When I take a screenshot of the browser (Chromedriver), I get a completely black screen. I see the browser open and the scrolling happen, but the screenshot has no content.

The code I use is:

Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS, 500).withName(tmpfile).save("/tmp");

When I take a screenshot standard selenium-style, it works fine:

TakesScreenshot yourScreenshot = (TakesScreenshot) driver;
tempfile = yourScreenshot.getScreenshotAs(OutputType.FILE);

Add timeout for chrome full page screenshot

I see that it scrolls the page and then back to top and take a screenshot. There should be a possibility to set a timeout between these operations because sometimes need to wait while page will be fully rendered and all effects stop after scroll

image

Gaps in full-page screenshots and cut off on the right side (IE 8)

(Edit: I meant IE 11)

Hi,

I'm running into this issue where there are gaps in my full-page screenshots and a cut-off down the middle on the right side.

2019_10_02_09_27_55_676

Here's a snippet of the relevant code:

WebDriver ieDriver = new InternetExplorerDriver(); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); //disable protected mode settings capabilities.setCapability("ignoreProtectedModeSettings", true); capabilities.setCapability("initialBrowserUrl", "https://stackoverflow.com/"); ieDriver = new InternetExplorerDriver(capabilities); Shutterbug.shootPage(ieDriver, ScrollStrategy.BOTH_DIRECTIONS,500,true).save(saveToDirectory);
Can anyone see something wrong or have any ideas on a fix for this?

Thanks in advance!

Usage with FitNesse/Selenium stack

Has anyone got selenium-shutterbug to work with FitNesse running on top of Selenium? We're a Java shop but, in the FitNesse/Selenium context, it isn't clear how to get this working. We can run arbitrary Javascript within the SUT (system under test) in the browser, but I'm not sure that helps.

Thanks for your help.

getting error while scrolling the webpage

Hi All,

I have written the below code to scroll [https://www.flipkart.com/]

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.assertthat.selenium_shutterbug.core.Shutterbug;
import com.assertthat.selenium_shutterbug.utils.web.ScrollStrategy;

public class FlipKart_Shutterbug {

    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "C:\\Eclipse\\Drivers\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.manage().window().maximize();
        driver.get("https://www.flipkart.com/");
        Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS).save("C:\\Users\\Vishvambruth JT\\Desktop\\Screen.jpg");
        driver.quit();
    }
}

The code scrolls the webpage till end and throw the below error:

Starting ChromeDriver 2.22.397933 (1cab651507b88dec79b2b2a22d1943c01833cc1b) on port 22816
Only local connections are allowed.
Oct 08, 2016 2:13:14 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.
Oct 08, 2016 2:13:15 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Exception in thread "main" java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Long
    at com.assertthat.selenium_shutterbug.utils.web.Browser.getCurrentScrollY(Browser.java:134)
    at com.assertthat.selenium_shutterbug.utils.web.Browser.takeScreenshotEntirePage(Browser.java:81)
    at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:70)
    at com.assertthat.selenium_shutterbug.core.Shutterbug.shootPage(Shutterbug.java:45)
    at FlipKart_Shutterbug.main(FlipKart_Shutterbug.java:15)

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

Not finiding Element corretly

Hi Team,
This is working fine but it is not finding element correctly help me out to proceed further
Not finding Element correctly

f-1512823962763
f-1512823960268

selenium-shutterbug -0.4 unable to see equalsWithDiff functions

Hi,

I added the following dependencies to my project

com.assertthat
selenium-shutterbug
0.4

But am unable to access the following funtion "Shutterbug.shootPage(driver).equalsWithDiff(otherImage,pathToNewImage,0.1);"

I could see only .equals methods.

Screen captured by shutterbug is not correct

Hi @glib-briia,

My apologies for raising this bug again and again.
I have written the below code. But the output screen captured by shutter bug is not correct. I double checked all my xpaths and its correctly recognizing the web elements. Am I doing something wrong here.

import java.awt.Color;
import java.awt.Font;
import java.util.Date;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import com.assertthat.selenium_shutterbug.core.Shutterbug;

public class ShutterBug {

    public static void main(String[] args) {
//      System.setProperty("webdriver.chrome.driver", "C:\\Eclipse\\Drivers\\chromedriver.exe");
//      WebDriver driver = new ChromeDriver();
        System.setProperty("webdriver.gecko.driver","C:\\Eclipse\\Drivers\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.get("https://www.google.com/");
        WebElement googleLogo = driver.findElement(By.xpath(".//*[@id='hplogo']"));
        WebElement searchBtn = driver.findElement(By.xpath(".//*[@id='tsf']/div[2]/div[3]/center/input[1]"));
        WebElement searchBox = driver.findElement(By.xpath(".//*[@id='lst-ib']"));

        //searchBox.sendKeys("Testing");    

        Shutterbug.shootPage(driver)
            .blur(searchBox)
            .highlight(searchBtn)
            .monochrome(googleLogo)
            .highlightWithText(googleLogo, Color.blue, 3, "Monochromed logo",Color.blue, new Font("SansSerif", Font.BOLD, 20))
            .highlightWithText(searchBox, "Blurred secret words")
            .withTitle("Google home page - " + new Date())
            .withName("home_page")
            .withThumbnail(0.7)
            .save("C:\\Users\\Vishvambruth JT\\Desktop\\Screen.jpg");
            driver.quit();      
    }
}

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

Output Screen captured by shutterbug

home_page

scrolling with WHOLE_PAGE option doesn't work

Hi, I am trying to accomplish taking screenshots of whole page. When I use:
Shutterbug.shootPage(webDriver,ScrollStrategy.WHOLE_PAGE).withName("wholepage").save();
I am only getting one screenshot of head. I also tried:
((webDriver) JavascriptExecutor).executeScript(window.scrollBy(0,100));
which also didn't work. Seems like I have problems with proper scrolling. Can I ask for help or any guide?

I use:
Chrome - 76.0.3809.87 (64-bit)
selenium-shutterbug - 0.9.2

ScrollTo

I have a problem about scrolling (ScrollTo), it doesn't work.
The program capture the visible page.
Thx

Scrollbars are visible in Chrome 54, and only the first "row" is collected

Steps to reproduce:

  • Open the following url using selenium with chrome 54:
    data:text/html;charset=utf-8;base64,PGh0bWw+DQoJPGJvZHkgc3R5bGU9ImhlaWdodDogMzcyOXB4OyB3aWR0aDogMTQ2NXB4OyBtYXJnaW46IDBweDsgcGFkZGluZzogMHB4OyBiYWNrZ3JvdW5kLWltYWdlOiBsaW5lYXItZ3JhZGllbnQodG8gbGVmdCB0b3AsIGJsdWUsIHJlZCk7IGJhY2tncm91bmQtc2l6ZTogMTQ2NXB4IDEwMCU7Ij4NCgk8L2JvZHk+DQo8L2h0bWw+
  • Take a screenshot
    Shutterbug.shootPage(driver, ScrollStrategy.BOTH_DIRECTIONS).getImage()

expected:
expected
received:
received

There are actually two problems:

  • The scrollbars are visible
  • The viewport height is wrong, and therefore only the first line is queried

I will submit a PR that fixes these problems

Not making screenshots using RemoteWebdriver

Using 0.8 version of Shuttherbug using ScrollStrategy.WHOLE_PAGE_CHROME with RemoteWebdriver the Exception "You must use Chrome driver for this operation" occured.

Same exception if wrap driver into OOT selenium EventFiringWebDriver

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.