urls.js
1.8 KB
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
/*eslint strict:0*/
casper.test.begin('urls tests', 9, function(test) {
var assertURL = function(match, message) {
test.assertHttpStatus(200);
test.assertUrlMatches(match, message);
};
casper.start('tests/site/urls.html#fragment');
casper.waitForUrl(/urls.html/, function() {
assertURL('urls.html', 'Casper.start loads URL with fragment');
test.assertEqual(casper.evaluate(function() {
return location.hash;
}), '#fragment', 'location.hash equals fragment');
});
casper.then(function() {
this.clickLabel('raw unicode', 'a');
});
casper.waitForUrl(/Forlì/,
assertURL.bind(this,
'Forlì',
'Casper.getCurrentUrl() retrieves a raw unicode URL'
));
casper.then(function() {
this.clickLabel('escaped', 'a');
});
casper.waitForUrl(/Farlì/,
assertURL.bind(this,
'Farlì',
'Casper.getCurrentUrl() retrieves an escaped URL'
));
casper.then(function() {
this.clickLabel('uri encoded', 'a');
});
casper.waitForUrl(/Furlì/,
assertURL.bind(this,
'Furlì',
'Casper.getCurrentUrl() retrieves a decoded URL'
));
casper.run(function() {
test.done();
});
});
// https://github.com/casperjs/casperjs/issues/841
casper.test.begin('url tests with javascript disabled', 1, function(test) {
casper.options.pageSettings.javascriptEnabled = false;
casper.start('tests/site/urls.html');
casper.then(function() {
test.assertMatch(this.getCurrentUrl(), /urls\.html$/,
'Casper.getCurrentUrl() can work, with javascript disabled');
});
casper.run(function() {
test.done();
casper.options.pageSettings.javascriptEnabled = true;
});
});