Skip to content

Commit

Permalink
tests(common): add snapshot tests with cypress and applitools (valor-…
Browse files Browse the repository at this point in the history
…software#1072)

* tests(common): add snapshot tests with cypress and applitools
  • Loading branch information
ludmilanesvitiy authored Mar 18, 2019
1 parent 885dc72 commit 82ff000
Show file tree
Hide file tree
Showing 14 changed files with 1,592 additions and 128 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/out-tsc
# Only exists if Bazel was run
/bazel-out
/cypress/screenshots/*

# dependencies
node_modules
Expand Down
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ addons:
cache:
directories:
- ./node_modules
- ~/.cache
- ~/.npm

install:
- npm install
- npm ci

script:
- npm run build:lib
- npm run test -- --watch=false --no-progress --browsers=ChromeHeadless
- ng serve &
- $(npm bin)/wait-on http-get://localhost:4200/#
- npm run test:main
- npm run test:screenshot
- kill $(jobs -p) || true
7 changes: 7 additions & 0 deletions cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"baseUrl": "http://localhost:4200/",
"video": false,
"eyesTimeout": 1200000,
"viewportWidth": 1366,
"viewportHeight": 768
}
3 changes: 3 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"componentsUrls": ["#LineChart", "#BarChart", "#DoughnutChart", "#RadarChart", "#PieChart", "#PolarAreaChart", "#BubbleChart", "#ScatterChart", "#DynamicChart"]
}
63 changes: 63 additions & 0 deletions cypress/integration/main-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const browsers = [{
name: 'chrome',
browserVersion: 'latest',
width: 1366,
height: 768
}];

describe('Main Page', () => {
it(`navigate to main Demo page and check info`, () => {
const topBarSelector = 'mat-toolbar';
const mainContentSelector = 'main';
cy.visit('');

cy.get(topBarSelector).should('be.visible')
.eyesOpen({
appName: 'NG2-charts',
testName: `NG2-charts Main Page Top Bar`,
browser: browsers
})
.eyesCheckWindow({
sizeMode: 'selector',
selector: topBarSelector,
sendDom: false,
})
.eyesClose();

cy.get(mainContentSelector).should('be.visible')
.eyesOpen({
appName: 'NG2-charts',
testName: `NG2-charts Main Page Content`,
browser: browsers
})
.eyesCheckWindow({
sizeMode: 'selector',
selector: mainContentSelector,
sendDom: false,
/*ignore: [
{selector: '#gh-count'}]*/
})
.eyesClose();
});
});

describe('Charts', () => {
const componentsArray = [
{url: '/#LineChart', selector: 'app-line-chart'},
{url: '/#BarChart', selector: 'app-bar-chart'},
{url: '/#DoughnutChart', selector: 'app-doughnut-chart'},
{url: '/#RadarChart', selector: 'app-radar-chart'},
{url: '/#PieChart', selector: 'app-pie-chart'},
{url: '/#PolarAreaChart', selector: 'app-polar-area-chart'},
{url: '/#BubbleChart', selector: 'app-bubble-chart'},
{url: '/#ScatterChart', selector: 'app-scatter-chart'},
{url: '/#DynamicChart', selector: 'app-dynamic-chart'}
];

componentsArray.forEach(component => {
it(`${component.url}`, () => {
cy.visit(component.url);
cy.get(component.selector).find('canvas').wait(200).screenshot();
});
});
});
32 changes: 32 additions & 0 deletions cypress/integration/screenshot-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var Eyes = require('eyes.images').Eyes;
const fs = require('fs');
const urls = require('../fixtures/example').componentsUrls;

var eyes = new Eyes();

eyes.setApiKey('Nls100t102uNgLhLpblVUdA3tP104MQQS9VUYgHQ5tYOUuIxU110');

eyes.setHostingApp("Chrome");

eyes.setHostOS('MacOS latest');


async function forEachAsync(array, callback) {
let i = 0;
for (; i < array.length; i++) {
await callback(array[i], i, array);
}
}

const testResults = eyes.open("NG2-charts", "Charts comparison", {width: 1366, height: 768}).then(async function () {
return forEachAsync(urls, async (url) => {
const image = fs.readFileSync(`./cypress/screenshots/main-test.js/Charts -- ${url}.png`);
await eyes.checkImage(image, url);
});
}).then(function () {
return eyes.close();
});

testResults.then(function (results) {
console.log("Results: ", results);
});
3 changes: 3 additions & 0 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (on, config) => {
};
require('@applitools/eyes.cypress')(module);
20 changes: 20 additions & 0 deletions cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import '@applitools/eyes.cypress/commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
28 changes: 0 additions & 28 deletions e2e/protractor.conf.js

This file was deleted.

23 changes: 0 additions & 23 deletions e2e/src/app.e2e-spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions e2e/src/app.po.ts

This file was deleted.

13 changes: 0 additions & 13 deletions e2e/tsconfig.e2e.json

This file was deleted.

Loading

0 comments on commit 82ff000

Please sign in to comment.