Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Commit

Permalink
fix(build): add missing test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cdaringe committed Sep 7, 2017
1 parent 808942b commit a4b5656
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 0 deletions.
25 changes: 25 additions & 0 deletions backstop_data/engine_scripts/casper/clickAndHoverHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
var WAIT_TIMEOUT = 5000;

module.exports = function(casper, scenario) {
var waitFor = require('./waitForHelperHelper')(casper, WAIT_TIMEOUT);
var hoverSelector = scenario.hoverSelector,
clickSelector = scenario.clickSelector,
postInteractionWait = scenario.postInteractionWait;

if (hoverSelector) {
waitFor(hoverSelector);
casper.then(function () {
casper.mouse.move(hoverSelector);
});
}

if (clickSelector) {
waitFor(clickSelector);
casper.then(function () {
casper.click(clickSelector);
});
}

// TODO: if postInteractionWait === integer then do ==> wait(postInteractionWait) || elsevvv
waitFor(postInteractionWait);
};
15 changes: 15 additions & 0 deletions backstop_data/engine_scripts/casper/loadCookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var fs = require('fs');

module.exports = function (casper, scenario) {
var cookies = [];
var cookiePath = scenario.cookiePath;

// READ COOKIES FROM FILE IF EXISTS
if (fs.exists(cookiePath)) {
cookies = JSON.parse(fs.read(cookiePath));
}

casper.page.cookies = cookies;
console.log('Cookie state restored with cookies:', JSON.stringify(cookies, null, 2));
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36');
};
4 changes: 4 additions & 0 deletions backstop_data/engine_scripts/casper/onBefore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (casper, scenario, vp) {
require('./loadCookies')(casper, scenario);
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36');
};
5 changes: 5 additions & 0 deletions backstop_data/engine_scripts/casper/onReady.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function(casper, scenario, vp) {
console.log('SCENARIO> ' + scenario.label);
require('./clickAndHoverHelper')(casper, scenario);
// add more helpers here...
};
18 changes: 18 additions & 0 deletions backstop_data/engine_scripts/casper/waitForHelperHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var TIMEOUT_DEFAULT = 2000;

module.exports = function (casper, timeout) {
var TIMEOUT = timeout || TIMEOUT_DEFAULT;

return function waitFor (selector) {
if (selector) {
casper.waitForSelector(
selector,
function () {},
function () {
console.error('NOT FOUND > ' + selector);
},
TIMEOUT
);
}
};
};
24 changes: 24 additions & 0 deletions backstop_data/engine_scripts/chromy/clickAndHoverHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = function (chromy, scenario) {
var hoverSelector = scenario.hoverSelector;
var clickSelector = scenario.clickSelector;
var postInteractionWait = scenario.postInteractionWait; // selector [str] | ms [int]

if (hoverSelector) {
chromy
.wait(hoverSelector)
.rect(hoverSelector)
.result(function (rect) {
chromy.mouseMoved(rect.left, rect.top);
});
}

if (clickSelector) {
chromy
.wait(clickSelector)
.click(clickSelector);
}

if (postInteractionWait) {
chromy.wait(postInteractionWait);
}
};
22 changes: 22 additions & 0 deletions backstop_data/engine_scripts/chromy/loadCookies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var fs = require('fs');

module.exports = function (chromy, scenario) {
var cookies = [];
var cookiePath = scenario.cookiePath;

// READ COOKIES FROM FILE IF EXISTS
if (fs.existsSync(cookiePath)) {
cookies = JSON.parse(fs.readFileSync(cookiePath));
}

// MUNGE COOKIE DOMAIN FOR CHROMY USAGE
cookies = cookies.map(cookie => {
cookie.url = 'https://' + cookie.domain;
delete cookie.domain;
return cookie;
});

// SET COOKIES VIA CHROMY
chromy.setCookie(cookies);
console.log('Cookie state restored with:', JSON.stringify(cookies, null, 2));
};
6 changes: 6 additions & 0 deletions backstop_data/engine_scripts/chromy/onBefore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (chromy, scenario, vp) {
require('./loadCookies')(chromy, scenario);

// IGNORE ANY CERT WARNINGS
chromy.ignoreCertificateErrors();
};
5 changes: 5 additions & 0 deletions backstop_data/engine_scripts/chromy/onReady.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = function (chromy, scenario, vp) {
console.log('SCENARIO > ' + scenario.label);
require('./clickAndHoverHelper')(chromy, scenario);
// add more ready handlers here...
};
14 changes: 14 additions & 0 deletions backstop_data/engine_scripts/cookies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"domain": ".www.yourdomain.com",
"path": "/",
"name": "yourCookieName",
"value": "yourCookieValue",
"expirationDate": 1798790400,
"hostOnly": false,
"httpOnly": false,
"secure": false,
"session": false,
"sameSite": "no_restriction"
}
]
4 changes: 4 additions & 0 deletions backstop_data/engine_scripts/onBefore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = function (engine, scenario, vp) {
// This script runs before your app loads. Edit here to log-in, load cookies or set other states required for your test.
console.log('onBefore.js has run for ' + vp.label + '.');
};
6 changes: 6 additions & 0 deletions backstop_data/engine_scripts/onReady.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function (engine, scenario, vp) {
engine.evaluate(function () {
// Your web-app is now loaded. Edit here to simulate user interacions or other state changes in the browser window context.
});
console.log('onReady.js has run for: ', vp.label);
};

0 comments on commit a4b5656

Please sign in to comment.