Git Product home page Git Product logo

testcafe-screenshot-testing's Introduction

Screenshot Testing with TestCafe

This compare-screenshots.js Node.js module will compare a model screenshot with a screenshot captuad with TestCafe. The code uses TestCafe and Rembrant for Node.js.

How it works

Every single run of the tests generates a screenshot of the tested page. This screenshot is then used to track changes and write screenshot-based tests. With this capability, you can generate reports with all the screenshots, and plug this into your Continuous Integration, by recording screenshots for the first time as base ones (or whenever you intentionally change them), and letting your continuous integration check against the recorded screenshots.

Creating a screenshot from within a test is very easy. You can do this using the [t.takeScreenshot( [path] )] action (https://devexpress.github.io/testcafe/documentation/test-api/actions/take-screenshot.html). Call this action when your page is set up to check the layout:

    await t
       .typeText('#developer-name', 'John Smith')
       .click('#submit-button')
       .takeScreenshot(testScreenshotPath);
    });

Preparation

Before running the application, configure your environment:

npm install

The TestCafe, Rembrant, Colors and UAParser modules will be installed automatically.

Launch the example

Open index.html and configure screenshotPath and modelPath if necessary. You only type a single command to begin testing.

testcafe chrome index.js -s screenshots

Result

TestCafe automatically starts browsers, runs tests, takes a screenshot and compares it with a model screenshot. The test result will be shown on a console.

testcafe-screenshot-testing's People

Contributors

marinarukavitsyna avatar

Stargazers

 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

testcafe-screenshot-testing's Issues

Rembrandt is failing to install?

After cloning repo and running npm install, I get this error...

`> node-gyp rebuild

gyp ERR! configure error
gyp ERR! stack Error: Command failed: /usr/local/opt/python/libexec/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack at ChildProcess.emit (events.js:200:13)
gyp ERR! stack at maybeClose (internal/child_process.js:1021:16)
gyp ERR! stack at Socket. (internal/child_process.js:430:11)
gyp ERR! stack at Socket.emit (events.js:200:13)
gyp ERR! stack at Pipe. (net.js:586:12)
gyp ERR! System Darwin 18.6.0
gyp ERR! command "/Users/tyleroneal/.nvm/versions/node/v12.3.1/bin/node" "/Users/tyleroneal/.nvm/versions/node/v12.3.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/tyleroneal/repos/TestCafe-Screenshot-Testing/node_modules/canvas
gyp ERR! node -v v12.3.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN Screenshot_Testing@ No repository field.
npm WARN Screenshot_Testing@ No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
`

strange rembrandt init parameter in compare-screenshots.js

Hi,
Glad to find your job as a good example for testcafe screenshot stuff. Thanks for sharing.
However, there is a small issue in compare-screenshots.js:12. The Rembrandt init param
maxDelta: 20,
does not seem to be correct.
I think you should put a percentage in float. Otherwise, it'll always return true !

See Rembrandt lib example with thresholdType: Rembrandt.THRESHOLD_PERCENT

// Maximum color delta (0...1):
  maxDelta: 0.02,

Thanks

Missing file compare-screenshots

In the /TestCafe-Screenshot-Testing/example/index.js file the following imported file is missing
import compareScreenshots from './modules/compare-screenshots' is missing``

It is possible to add it please ?

Thanks a lot.

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.