Git Product home page Git Product logo

protractor-screenshot-utils's Introduction

Build Status Code Coverage

protractor-screenshot-utils

A simple utility to capture fullpage screenshot, screenshot of any element and crop the screenshot by any screen coordinates from your e2e protractor tests out-of-box.

Features

  1. This module can take fullpage screenshots of any webpage.
  2. It can take screenshot of any given WebElement.
  3. It also has the ability to crop the screenshot with given co-ordinates of screen.
  4. Automatically save the captured screenshot in given path.
  5. Overrides default browser.getScreenshot() method to capture full page screenshots.

Preview

Default Screenshot Fullpage Screenshot Element Screenshot
__________________________________________________________________________

How to install

npm install protractor-screenshot-utils

Usage

Add add the below code to protractor config file:

Example:

protractor.config.js

var screenShotUtils = require("protractor-screenshot-utils").ProtractorScreenShotUtils;
exports.config = {
    framework: 'jasmine2',
      onPrepare: function() {
          global.screenShotUtils = new screenShotUtils({
            browserInstance : browser
          });
      }
};

That's it. Now you can take fullpage screenshots from your tests by just using any of the below code.

Taking fullPage screenshot

screenShotUtils.takeScreenshot().then(function(base64string){
    //logic to save the image to file.
})

or you can also directly save the image as file using

screenShotUtils.takeScreenshot({
   saveTo: "fullpageScreenshot.png"
})

Above code will automatically saves the screenshot as fullpageScreenshot.png file.

Taking screenshot of any element

screenShotUtils.takeScreenshot({
   element : element(by.id("header")), //you can pass any protractor element
   saveTo: "headerElement.png"
})

Taking screenshot by screen co-ordinates

screenShotUtils.takeScreenshot({
   dimensions : {
       x:20, //starting x point
       y:40, //startng y point
       width : 200,
       height: 200
   },
   saveTo: "croppedImage.png"
})

You can also crop the screenshot of an element by using

screenShotUtils.takeScreenshot({
   element : element(by.id("main-container")),
   dimensions : {
       x:20, //starting x point
       y:40, //startng y point
       width : 200,
       height: 200
   },
   saveTo: "croppedElementImage.png"
})

Additional Funtionalities:

Override default browser.takeScreenshot()

If your using any html-screenshot reporter in your test,then those reporters will call browser.takeScreenshot() to capture the screenshot of webpage in case of any failures in test. If you want to override default behaviour of browser.takeScreenshot() to caputer full page screenshot, you can use,

global.screenShotUtils = new screenShotUtils({
    browserInstance : browser,
    setAsDefaultScreenshotMethod : true //this will override default browser.takeScreenshot() method to take full page image.
});

And you can now take fullpage screen shot, element screenshot using browser.takeScreenshot() with all options given in above examples.

protractor-screenshot-utils's People

Contributors

sudharsan-selvaraj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

protractor-screenshot-utils's Issues

Plugin does not capture images

A very nice plugin, but unfortunately it does not capture images.

The avatar in the header is missing in the screenshot, see "home--protractor-screenshot-utils.png". (screenshot 1) When made the screenshot with protractor browser the image is visible, see "home--protractor-browser.png" (screenshot 2).

home--protractor-screenshot-utils

home--protractor-browser

Screenshots does not working with FireFox

Hi, this plugin working fine with Chrome, but has issues with FireFox.

Error when trying to get screenshot with Firefox:
JavascriptError: ReferenceError: html2canvas is not defined Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53' System info: host: '*********', ip: '*************', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181' Driver info: driver.version: unknown at Object.checkLegacyResponse (...\node_modules\selenium-webdriver\lib\error.js:546:15) at parseHttpResponse (...\node_modules\selenium-webdriver\lib\http.js:509:13) at doSend.then.response (...\node_modules\selenium-webdriver\lib\http.js:441:30) at process._tickCallback (internal/process/next_tick.js:68:7)

"protractor": "^5.4.2",
Firefox v74
geckodriver-v0.26.0.exe

Full page screenshot not working for chrome

  • Nodejs version: 10.15.3
  • Protractor version: 7.0.0
  • Operating system: MacOS and windows
  • Browser and its version: Chrome 90.4430.93

We somehow integrated your package in our test framework.
Just a little background, we are using protractor + mocha + mochawesome-screenshot (html reporting).
We have integrated it the way it was listed on the guide:
https://www.npmjs.com/package/protractor-screenshot-utils

However, for some reason, whenever I call it on the ts file, it's not overriding the browser.takeScreenshot(). It only takes the screenshot of what's visible on the browser. We are also using

On the onPrepare section, we have set it to
setAsDefaultScreenshotMethod : true

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.