Skip to content

Commit c179062

Browse files
committed
added set cookies example
1 parent 34c0a3b commit c179062

13 files changed

+116
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ yarn.lock
2323
.idea
2424

2525
compare/bower_components/**/.*
26+
examples/**/html_report/
2627

2728
/backstop_data/bitmaps_test/
2829
/backstop_data/html_report/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"id": "prod_test",
3+
"viewports": [
4+
{
5+
"name": "tablet_v",
6+
"width": 568,
7+
"height": 1024
8+
}
9+
],
10+
"scenarios": [
11+
{
12+
"label": "no_cookies_1",
13+
"url": "index.html",
14+
"selectors": [],
15+
"readyEvent": null,
16+
"delay": 50,
17+
"misMatchThreshold" : 0.1,
18+
"onBeforeScript": "onBefore.js",
19+
"onReadyScript": "onReady.js"
20+
},
21+
{
22+
"label": "cookie1",
23+
"url": "index.html",
24+
"selectors": [],
25+
"readyEvent": null,
26+
"delay": 50,
27+
"misMatchThreshold" : 0.1,
28+
"testCookieValue": "cookie1",
29+
"onBeforeScript": "onBefore.js",
30+
"onReadyScript": "onReady.js"
31+
},
32+
{
33+
"label": "no_cookies_2",
34+
"url": "index.html",
35+
"selectors": [],
36+
"readyEvent": null,
37+
"delay": 50,
38+
"misMatchThreshold" : 0.1,
39+
"onBeforeScript": "onBefore.js",
40+
"onReadyScript": "onReady.js"
41+
},
42+
{
43+
"label": "cookie2",
44+
"url": "index.html",
45+
"selectors": [],
46+
"readyEvent": null,
47+
"delay": 50,
48+
"misMatchThreshold" : 0.1,
49+
"testCookieValue": "cookie2",
50+
"onBeforeScript": "onBefore.js",
51+
"onReadyScript": "onReady.js"
52+
}
53+
],
54+
"paths": {
55+
"bitmaps_reference": "backstop_data/bitmaps_reference",
56+
"bitmaps_test": "backstop_data/bitmaps_test",
57+
"casper_scripts": "backstop_data/casper_scripts",
58+
"html_report": "backstop_data/html_report",
59+
"ci_report": "backstop_data/ci_report"
60+
},
61+
"casperFlags": [],
62+
"engine": "phantomjs",
63+
"report": ["browser"],
64+
"debug": false
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
module.exports = function (casper, scenario, vp) {
3+
// This script runs before your app loads. Edit here to log-in, load cookies or set other states required for your test.
4+
console.log('onBefore.js has run for ' + vp.name + '.');
5+
6+
if (scenario.testCookieValue) {
7+
var cookieShim = [
8+
{
9+
"domain": ".",
10+
"path": "/",
11+
"expirationDate": 1528614000,
12+
"name": "testCookieValue",
13+
"value": scenario.testCookieValue,
14+
"hostOnly": false,
15+
"httpOnly": false,
16+
"sameSite": "no_restriction",
17+
"secure": false,
18+
"session": false,
19+
"storeId": "0",
20+
"id": 1000
21+
}
22+
]
23+
console.log('setting a single testCookieValue: ' + scenario.testCookieValue);
24+
casper.page.cookies = cookieShim;
25+
} else {
26+
casper.page.cookies = [];
27+
console.log('Clearing all cookies.');
28+
}
29+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function (casper, scenario, vp) {
2+
casper.evaluate(function () {
3+
// Your web-app is now loaded. Edit here to simulate user interacions or other state changes.
4+
});
5+
console.log('onReady.js has run for: ', vp.name);
6+
};
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>TEST FOR COOKIE VALUE</title>
5+
<style type="text/css">h1,p{font-size: 70px}</style>
6+
</head>
7+
<body>
8+
<h1>COOKIE VALUE...</h1>
9+
<p id="cookieValue"></p>
10+
</body>
11+
<script type="text/javascript">
12+
var pTag = document.getElementById('cookieValue');
13+
pTag.innerText = document.cookie || 'no value';
14+
</script>
15+
</html>

0 commit comments

Comments
 (0)