Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
[![NPM version](https://badge.fury.io/js/dayguard.png)](http://badge.fury.io/js/dayguard)
Dayguard is a "plugin" for NightwatchJS that allows you to do CSS Regression tests.
It's based on Resemble.js (for NodeJS) and gm for GraphicsMagick/ImageMagick support.
visualChangesOf(selector, customName, threshold)
— will call low-level commands and test for differencestakeScreenshotFromElement(selector, customName, timeout)
— takes a custom screenshot for the given selectorcompareScreenshotFromElement(selector, customName, callback)
— compare the differences between the last referencesInstall the following dependencies:
$ npm install nwrun dayguard nightwatch chromedriver
Save the following script as runner.js
:
const chromedriver = require('chromedriver');
const dayguard = require('dayguard');
const nwrun = require('nwrun');
const path = require('path');
nwrun({
standalone: true,
src_folders: path.join(__dirname, 'tests'),
output_folder: path.join(__dirname, 'reports'),
custom_commands_path: [dayguard.custom_commands_path],
custom_assertions_path: [dayguard.custom_assertions_path],
selenium: {
cli_args: {
'webdriver.chrome.driver': chromedriver.path,
},
},
test_settings: {
default: {
desiredCapabilities: {
browserName: 'chrome',
},
screenshots: {
enabled: true,
path: path.join(__dirname, 'screenshots'),
},
},
},
}, success => {
if (!success) {
process.exit(1);
}
});
Save the following code as tests/dayguard.js
:
module.exports = {
'Load an example page just for testing': browser => {
browser
.url('http://randomcolour.com/')
.waitForElementVisible('body', 200);
},
'Take a screenshot and ask for differences': browser => {
browser
.assert.visualChangesOf('body')
.end();
},
};
Now just execute node runner.js
and see your tests fail.
Why? Because each time you load randoumcolour.com you'll get a different color...
Each time takeScreenshotFromElement()
gets called dayguard will do the following:
screenshots/<testName>/<selector>/ref.<offset|diff>.png
Every used selector will keep its saved positions as screenshots/<testName>/<selector>/index.json
where each array-item will match the <offset|diff>
pattern:
ref.0.png
— initial referenceref.0_1.png
— difference between 0
and 1
refsref.1.png
— second referenceUsing this cache dayguard is able to effectively report any difference found.
Dayguard leverages on NightwatchJS (Webdriver → Selenium) so you can take screenshots from real browsers and not just headless ones.
I've got really tired from trying other solutions (NightwatchCSS, PhantomJS, PhantomCSS, CasperJS, Grunt, Gulp, etc.) that relies on "toy" browsers exposing ugly APIs to enjoy.
Meh.
FAQs
[![NPM version](https://badge.fury.io/js/dayguard.png)](http://badge.fury.io/js/dayguard)
The npm package dayguard receives a total of 2 weekly downloads. As such, dayguard popularity was classified as not popular.
We found that dayguard demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.