This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.js
executable file
·213 lines (178 loc) · 5.5 KB
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
// Configuration and some usefull methods
/**
* Debug/Verbose
* ----------------------------------------------------------------------------
*/
var debug_mode = !!casper.cli.get('verbose');
if (debug_mode) {
debug_mode = true;
casper.options.verbose = true;
casper.options.logLevel = 'debug';
}
var colorizer = require('colorizer').create('Colorizer');
/**
* The view
* ----------------------------------------------------------------------------
*/
// The viewport size
casper.options.viewportSize = {
width: 1200,
height: 900
};
casper.options.waitTimeout = 15000;
/**
* The HTTP responses
* ----------------------------------------------------------------------------
*/
casper.options.httpStatusHandlers = {
200: function(self, resource) {
this.echo(resource.url + " is OK (200)", "INFO");
},
400: function(self, resource) {
this.echo(resource.url + " is nok (400)", "INFO");
},
404: function(self, resource) {
this.echo("Resource at " + resource.url + " not found (404)", "COMMENT");
},
302: function(self, resource) {
this.echo(resource.url + " has been redirected (302)", "INFO");
}
};
/**
* Login credentials
* ----------------------------------------------------------------------------
*/
var login_user_firstname = 'FirstName';
var login_user_lastname = 'LastName';
var login_user_middlename = 'MiddleName';
var login_user_username = casper.cli.get("email");
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(login_user_username))
{
login_user_username
}
else{
casper.die('Please enter valid email or add email to command line --email="yourmail@example.com" ');
}
var login_user_password = 'PassWord';
var login_user_password_bad = "badpassword";
var user_address_company = 'Atwix';
var user_address_street = '16243 Ivy Lake Dr.';
var user_address_city = 'Odessa';
var user_address_region = 'Florida';
var user_address_postcode = '33556';
var user_address_telephone = '1234567890';
var user_address_fax = '12345678';
var user_address_coundry = 'United States';
/**
* Product credentials
* ----------------------------------------------------------------------------
*/
var prod_url_simple = 'madison-overear-headphones.html';
var prod_name_simple = 'Madison Overear Headphones';
var prod_url_conf ='men/new-arrivals/chelsea-tee.html';
var prod_name_conf = 'Chelsea Tee';
/* Utils, XPath, FileSystem
* ----------------------------------------------------------------------------
*/
var utils = require('utils');
var x = casper.selectXPath;
var fs = require('fs');
/**
* URLs
* ----------------------------------------------------------------------------
*/
var base_url = casper.cli.get("base_url");
if (!/\/$/.test(base_url)) {
// We haven't trailing slash: add it
base_url = base_url + '/';
}
// Done for the test file
// ----------------------------------------------------------------------------
casper.test.done();
/**
* Tear down and set up
* ----------------------------------------------------------------------------
*/
// Tear down:
// - clear cookies
// - reset captures counter
casper.test.tearDown(function () {
/* // Clear cookies
casper.clearCookies();*/
// Reset captures counter
captures_counter = 0;
});
// Set up: nothing
casper.test.setUp(function () {});
/**
* Steps
* ----------------------------------------------------------------------------
*/
casper.on("load.failed", function() {
casper.capturePage();
});
casper.on("load.finished", function() {
casper.printTitle();
casper.capturePage();
});
casper.on("fill", function() {
casper.capturePage();
});
casper.on("mouse.down", function() {
casper.capturePage();
});
casper.on("mouse.move", function() {
casper.capturePage();
});
casper.on("mouse.move", function() {
casper.capturePage();
});
casper.on("step.complete", function() {
casper.capturePage();
});
casper.on("step.error", function() {
casper.capturePage('error');
});
casper.on("http.status.500", function() {
casper.capturePage('500');
});
casper.on("http.status.404", function() {
casper.capturePage('404');
});
/**
* Tools and cool methods :')
* ----------------------------------------------------------------------------
*/
// Clear cookies
casper.clearCookies = function () {
casper.test.info("Clear cookies");
casper.page.clearCookies();
};
// Print the current page title
casper.printTitle = function () {
this.echo('### ' + casper.getTitle() + ' ###', 'INFO_BAR');
};
// Capture the current test page
var captures_counter = 0;
casper.capturePage = function (debug_name) {
var directory = 'captures/' + casper.test.currentSuite.name;
if (captures_counter > 0) {
var previous = directory + '/step-' + (captures_counter-1) + '.jpg';
if (debug_name) {
var current = directory + '/step-' + captures_counter + '-' + debug_name + '.jpg';
} else {
var current = directory + '/step-' + captures_counter + '.jpg';
}
casper.capture(current);
// If previous is same as current (and no debug_name), remove current
if (!debug_name && fs.isFile(previous) && fs.read(current) === fs.read(previous) && fs.isFile(current)) {
fs.remove(current);
captures_counter--;
casper.log('Capture removed because same as previous', 'warning');
}
} else {
// We remove the directory to cleanup
fs.removeTree(directory);
}
captures_counter++;
};