casperjs 1.0.0.RC1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +289 -1
- data/CONTRIBUTING.md +93 -0
- data/CONTRIBUTORS.md +53 -0
- data/README.md +29 -1
- data/batchbin/casperjs.bat +5 -0
- data/bin/bootstrap.js +164 -114
- data/bin/casperjs +84 -0
- data/bin/usage.txt +2 -1
- data/casperjs.gemspec +7 -4
- data/modules/casper.js +661 -239
- data/modules/clientutils.js +240 -54
- data/modules/colorizer.js +2 -1
- data/modules/events.js +13 -1
- data/modules/http.js +70 -0
- data/modules/mouse.js +1 -2
- data/modules/pagestack.js +166 -0
- data/modules/tester.js +1013 -659
- data/modules/utils.js +519 -367
- data/modules/vendors/coffee-script.js +2 -2
- data/modules/xunit.js +56 -24
- data/package.json +2 -2
- data/rpm/casperjs.spec +203 -0
- data/rpm/mkrpm.sh +25 -0
- data/rubybin/casperjs +9 -4
- data/samples/bbcshots.coffee +11 -10
- data/samples/bbcshots.js +16 -15
- data/samples/cliplay.js +3 -0
- data/samples/customevents.js +3 -0
- data/samples/customlogging.coffee +17 -19
- data/samples/customlogging.js +26 -27
- data/samples/download.js +4 -1
- data/samples/dynamic.js +3 -0
- data/samples/each.js +3 -0
- data/samples/events.js +4 -2
- data/samples/extends.js +4 -1
- data/samples/googlelinks.coffee +4 -1
- data/samples/googlelinks.js +10 -3
- data/samples/googlematch.coffee +1 -1
- data/samples/googlematch.js +5 -2
- data/samples/googlepagination.js +4 -1
- data/samples/googletesting.js +3 -0
- data/samples/logcolor.js +3 -0
- data/samples/metaextract.js +3 -0
- data/samples/multirun.js +3 -0
- data/samples/screenshot.js +4 -1
- data/samples/statushandlers.js +4 -1
- data/samples/steptimeout.js +3 -0
- data/samples/timeout.js +4 -1
- data/samples/translate.coffee +23 -0
- data/samples/translate.js +30 -0
- data/tests/commands/mytest.js +14 -0
- data/tests/commands/script.js +3 -0
- data/tests/run.js +82 -37
- data/tests/sample_modules/config.json +1 -0
- data/tests/sample_modules/csmodule.coffee +1 -0
- data/tests/sample_modules/jsmodule.js +1 -0
- data/tests/selftest.js +57 -0
- data/tests/site/dummy.js +1 -0
- data/tests/site/field-array.html +14 -0
- data/tests/site/frame1.html +10 -0
- data/tests/site/frame2.html +11 -0
- data/tests/site/frame3.html +11 -0
- data/tests/site/frames.html +12 -0
- data/tests/site/global.html +6 -1
- data/tests/site/includes/include1.js +6 -0
- data/tests/site/includes/include2.js +6 -0
- data/tests/site/index.html +3 -0
- data/tests/site/popup.html +19 -0
- data/tests/site/resources.html +7 -8
- data/tests/site/urls.html +14 -0
- data/tests/suites/casper/agent.js +3 -1
- data/tests/suites/casper/alert.js +14 -0
- data/tests/suites/casper/auth.js +24 -0
- data/tests/suites/casper/capture.js +12 -12
- data/tests/suites/casper/click.js +11 -1
- data/tests/suites/casper/confirm.js +24 -16
- data/tests/suites/casper/debug.js +10 -0
- data/tests/suites/casper/elementattribute.js +3 -1
- data/tests/suites/casper/encode.js +6 -2
- data/tests/suites/casper/evaluate.js +78 -18
- data/tests/suites/casper/events.js +3 -1
- data/tests/suites/casper/exists.js +3 -1
- data/tests/suites/casper/fetchtext.js +3 -1
- data/tests/suites/casper/flow.coffee +1 -1
- data/tests/suites/casper/formfill.js +39 -4
- data/tests/suites/casper/frames.js +43 -0
- data/tests/suites/casper/global.js +9 -3
- data/tests/suites/casper/headers.js +41 -0
- data/tests/suites/casper/history.js +3 -1
- data/tests/suites/casper/hooks.js +3 -1
- data/tests/suites/casper/keys.js +15 -0
- data/tests/suites/casper/location.js +21 -0
- data/tests/suites/casper/logging.js +3 -1
- data/tests/suites/casper/mouseevents.js +3 -1
- data/tests/suites/casper/onerror.js +3 -1
- data/tests/suites/casper/open.js +63 -1
- data/tests/suites/casper/popup.js +86 -0
- data/tests/suites/casper/prompt.js +11 -15
- data/tests/suites/casper/request.js +36 -0
- data/tests/suites/casper/resources.coffee +5 -5
- data/tests/suites/casper/scripts.js +32 -0
- data/tests/suites/casper/start.js +3 -1
- data/tests/suites/casper/steps.js +4 -2
- data/tests/suites/casper/urls.js +21 -0
- data/tests/suites/casper/viewport.js +3 -1
- data/tests/suites/casper/visible.js +3 -1
- data/tests/suites/casper/wait.js +22 -12
- data/tests/suites/casper/xpath.js +3 -1
- data/tests/suites/cli.js +3 -1
- data/tests/suites/clientutils.js +57 -3
- data/tests/suites/coffee.coffee +1 -1
- data/tests/suites/fs.js +3 -1
- data/tests/suites/http_status.js +19 -3
- data/tests/suites/popup.js +33 -0
- data/tests/suites/require.js +31 -0
- data/tests/suites/tester.js +134 -29
- data/tests/suites/utils.js +108 -8
- data/tests/suites/xunit.js +37 -6
- metadata +49 -15
- data/modules/injector.js +0 -93
- data/tests/suites/injector.js +0 -64
@@ -1,17 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
}
|
6
|
-
casper.setFilter('page.prompt', function(message, value) {
|
7
|
-
return 'Chuck ' + value;
|
8
|
-
});
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
casper.setFilter('page.prompt', function(message, value) {
|
4
|
+
return 'Chuck ' + value;
|
5
|
+
});
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
casper.start('tests/site/prompt.html', function() {
|
8
|
+
this.test.assertEquals(this.getGlobal('name'), 'Chuck Norris', 'prompted value has been received');
|
9
|
+
});
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}
|
11
|
+
casper.run(function() {
|
12
|
+
this.test.done(1);
|
13
|
+
});
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
function testHeader(header) {
|
4
|
+
return header.name === 'Accept' && header.value === 'application/json';
|
5
|
+
}
|
6
|
+
|
7
|
+
var t = casper.test, current = 0, tests = [
|
8
|
+
function(request) {
|
9
|
+
t.assertNot(request.headers.some(testHeader), "Casper.open() sets no custom header by default");
|
10
|
+
},
|
11
|
+
function(request) {
|
12
|
+
t.assert(request.headers.some(testHeader), "Casper.open() can set a custom header");
|
13
|
+
},
|
14
|
+
function(request) {
|
15
|
+
t.assertNot(request.headers.some(testHeader), "Casper.open() custom headers option is not persistent");
|
16
|
+
}
|
17
|
+
];
|
18
|
+
|
19
|
+
casper.on('page.resource.requested', function(request) {
|
20
|
+
tests[current++](request);
|
21
|
+
});
|
22
|
+
|
23
|
+
casper.start();
|
24
|
+
|
25
|
+
casper.thenOpen('tests/site/index.html');
|
26
|
+
casper.thenOpen('tests/site/index.html', {
|
27
|
+
headers: {
|
28
|
+
Accept: 'application/json'
|
29
|
+
}
|
30
|
+
});
|
31
|
+
casper.thenOpen('tests/site/index.html');
|
32
|
+
|
33
|
+
casper.run(function() {
|
34
|
+
this.removeAllListeners('page.resource.requested');
|
35
|
+
t.done(3);
|
36
|
+
});
|
@@ -7,18 +7,18 @@ casper.start "tests/site/resources.html", ->
|
|
7
7
|
"two resources found"
|
8
8
|
)
|
9
9
|
@test.assertResourceExists(
|
10
|
-
/
|
10
|
+
/dummy\.js/i
|
11
11
|
"phantom image found via test RegExp"
|
12
12
|
)
|
13
13
|
@test.assertResourceExists(
|
14
|
-
(res) -> res.url.match "
|
14
|
+
(res) -> res.url.match "dummy.js"
|
15
15
|
"phantom image found via test Function"
|
16
16
|
)
|
17
17
|
@test.assertResourceExists(
|
18
|
-
"
|
18
|
+
"dummy.js"
|
19
19
|
"phantom image found via test String"
|
20
20
|
)
|
21
21
|
onTimeout = -> @test.fail "waitForResource timeout occured"
|
22
|
-
@waitForResource "
|
22
|
+
@waitForResource "dummy.js", onTime, onTimeout
|
23
23
|
|
24
|
-
casper.run(-> @test.done())
|
24
|
+
casper.run(-> @test.done(5))
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
casper.options.remoteScripts = [
|
4
|
+
'includes/include1.js', // local includes are actually served
|
5
|
+
'includes/include2.js', // through the local test webserver
|
6
|
+
'http://code.jquery.com/jquery-1.8.3.min.js'
|
7
|
+
];
|
8
|
+
|
9
|
+
casper.start('tests/site/index.html', function() {
|
10
|
+
this.test.assertSelectorHasText('#include1', 'include1',
|
11
|
+
'Casper.includeRemoteScripts() includes a first remote script on start');
|
12
|
+
this.test.assertSelectorHasText('#include2', 'include2',
|
13
|
+
'Casper.includeRemoteScripts() includes a second remote script on start');
|
14
|
+
this.test.assertEval(function() {
|
15
|
+
return 'jQuery' in window;
|
16
|
+
}, 'Casper.includeRemoteScripts() includes a really remote file on first step');
|
17
|
+
});
|
18
|
+
|
19
|
+
casper.thenOpen('tests/site/form.html', function() {
|
20
|
+
this.test.assertSelectorHasText('#include1', 'include1',
|
21
|
+
'Casper.includeRemoteScripts() includes a first remote script on second step');
|
22
|
+
this.test.assertSelectorHasText('#include2', 'include2',
|
23
|
+
'Casper.includeRemoteScripts() includes a second remote script on second step');
|
24
|
+
this.test.assertEval(function() {
|
25
|
+
return 'jQuery' in window;
|
26
|
+
}, 'Casper.includeRemoteScripts() includes a really remote file on second step');
|
27
|
+
});
|
28
|
+
|
29
|
+
casper.run(function() {
|
30
|
+
this.options.remoteScripts = [];
|
31
|
+
this.test.done(6);
|
32
|
+
});
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
casper.test.comment('Casper.start()');
|
2
4
|
|
3
5
|
casper.start('tests/site/index.html', function() {
|
@@ -11,5 +13,5 @@ casper.start('tests/site/index.html', function() {
|
|
11
13
|
casper.test.assert(casper.started, 'Casper.start() started');
|
12
14
|
|
13
15
|
casper.run(function() {
|
14
|
-
this.test.done();
|
16
|
+
this.test.done(4);
|
15
17
|
});
|
@@ -1,10 +1,12 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
casper.test.comment('Casper.then()');
|
2
4
|
|
3
5
|
casper.start('tests/site/index.html');
|
4
6
|
|
5
7
|
var nsteps = casper.steps.length;
|
6
8
|
|
7
|
-
casper.then(function(
|
9
|
+
casper.then(function(response) {
|
8
10
|
this.test.assertTitle('CasperJS test index', 'Casper.then() added a new step');
|
9
11
|
});
|
10
12
|
|
@@ -28,5 +30,5 @@ casper.each([1, 2, 3], function(self, item, i) {
|
|
28
30
|
});
|
29
31
|
|
30
32
|
casper.run(function() {
|
31
|
-
this.test.done();
|
33
|
+
this.test.done(8);
|
32
34
|
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
casper.start('tests/site/urls.html', function() {
|
4
|
+
this.clickLabel('raw unicode', 'a');
|
5
|
+
}).then(function() {
|
6
|
+
this.test.assertHttpStatus(200);
|
7
|
+
this.test.assertUrlMatches('Forlì', 'Casper.getCurrentUrl() retrieves a raw unicode URL');
|
8
|
+
this.clickLabel('escaped', 'a');
|
9
|
+
});
|
10
|
+
|
11
|
+
casper.then(function() {
|
12
|
+
this.test.assertHttpStatus(200);
|
13
|
+
this.test.assertUrlMatches('Forlì', 'Casper.getCurrentUrl() retrieves an escaped URL');
|
14
|
+
this.clickLabel('uri encoded', 'a');
|
15
|
+
});
|
16
|
+
|
17
|
+
casper.run(function() {
|
18
|
+
this.test.assertHttpStatus(200);
|
19
|
+
this.test.assertUrlMatches('Forlì', 'Casper.getCurrentUrl() retrieves a decoded URL');
|
20
|
+
this.test.done(6);
|
21
|
+
});
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
casper.test.comment('Casper.viewport()');
|
2
4
|
|
3
5
|
casper.start();
|
@@ -8,4 +10,4 @@ casper.test.assertEquals(casper.page.viewportSize.width, 1337, 'Casper.viewport(
|
|
8
10
|
casper.test.assertEquals(casper.page.viewportSize.height, 999, 'Casper.viewport() can change the height of page viewport');
|
9
11
|
casper.test.assertRaises(casper.viewport, ['a', 'b'], 'Casper.viewport() validates viewport size data');
|
10
12
|
|
11
|
-
casper.test.done();
|
13
|
+
casper.test.done(3);
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
casper.start('tests/site/visible.html', function() {
|
2
4
|
this.test.comment('Casper.visible()');
|
3
5
|
this.test.assert(this.visible('#img1'), 'Casper.visible() can detect if an element is visible');
|
@@ -13,5 +15,5 @@ casper.start('tests/site/visible.html', function() {
|
|
13
15
|
});
|
14
16
|
|
15
17
|
casper.run(function() {
|
16
|
-
this.test.done();
|
18
|
+
this.test.done(4);
|
17
19
|
});
|
data/tests/suites/casper/wait.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
var waitStart;
|
2
4
|
|
3
5
|
casper.start('tests/site/index.html', function() {
|
@@ -7,21 +9,29 @@ casper.start('tests/site/index.html', function() {
|
|
7
9
|
casper.wait(1000, function() {
|
8
10
|
this.test.comment('Casper.wait()');
|
9
11
|
this.test.assert(new Date().getTime() - waitStart > 1000, 'Casper.wait() can wait for a given amount of time');
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
}, function() {
|
18
|
-
this.test.pass('Casper.waitFor() can wait for something to happen');
|
19
|
-
}, function() {
|
20
|
-
this.test.fail('Casper.waitFor() can wait for something to happen');
|
12
|
+
});
|
13
|
+
|
14
|
+
casper.thenOpen('tests/site/waitFor.html', function() {
|
15
|
+
this.test.comment('Casper.waitFor()');
|
16
|
+
this.waitFor(function() {
|
17
|
+
return this.evaluate(function() {
|
18
|
+
return document.querySelectorAll('li').length === 4;
|
21
19
|
});
|
20
|
+
}, function() {
|
21
|
+
this.test.pass('Casper.waitFor() can wait for something to happen');
|
22
|
+
}, function() {
|
23
|
+
this.test.fail('Casper.waitFor() can wait for something to happen');
|
22
24
|
});
|
23
25
|
});
|
24
26
|
|
27
|
+
casper.thenOpen('tests/site/waitFor.html').waitForText('<li>four</li>', function() {
|
28
|
+
this.test.comment('Casper.waitForText()');
|
29
|
+
this.test.pass('Casper.waitForText() can wait for text');
|
30
|
+
}, function() {
|
31
|
+
this.test.comment('Casper.waitForText()');
|
32
|
+
this.test.fail('Casper.waitForText() can wait for text');
|
33
|
+
});
|
34
|
+
|
25
35
|
casper.run(function() {
|
26
|
-
this.test.done();
|
36
|
+
this.test.done(3);
|
27
37
|
});
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper __utils__*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
var x = require('casper').selectXPath;
|
2
4
|
|
3
5
|
casper.test.comment('XPath');
|
@@ -28,5 +30,5 @@ casper.thenClick(x('/html/body/a[2]'), function() {
|
|
28
30
|
});
|
29
31
|
|
30
32
|
casper.run(function() {
|
31
|
-
this.test.done();
|
33
|
+
this.test.done(6);
|
32
34
|
});
|
data/tests/suites/cli.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false maxstatements:99*/
|
1
3
|
var cli = require('cli'), t = casper.test;
|
2
4
|
|
3
5
|
t.comment('parse(), get(), has()');
|
@@ -122,4 +124,4 @@ t.comment('parse(), get(), has()');
|
|
122
124
|
}, 'drop() did not affect other raw options');
|
123
125
|
})(cli.parse(['foo & bar', 'baz & boz', '--universe=42', '--lap=13.37', '--chucknorris', '--oops=false']));
|
124
126
|
|
125
|
-
t.done();
|
127
|
+
t.done(76);
|
data/tests/suites/clientutils.js
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
var fs = require('fs');
|
2
4
|
var x = require('casper').selectXPath;
|
3
5
|
|
@@ -50,6 +52,8 @@ function fakeDocument(html) {
|
|
50
52
|
// scoped
|
51
53
|
var scope = clientutils.findOne('ul');
|
52
54
|
casper.test.assertType(clientutils.findAll('li', scope), 'nodelist', 'ClientUtils.findAll() can find matching DOM elements within a given scope');
|
55
|
+
casper.test.assertEquals(clientutils.findAll('li', scope).length, 2, 'ClientUtils.findAll() can find matching DOM elements within a given scope');
|
56
|
+
casper.test.assertType(clientutils.findAll(x('//li'), scope), 'array', 'ClientUtils.findAll() can find matching DOM elements using XPath within a given scope');
|
53
57
|
fakeDocument(null);
|
54
58
|
})(casper);
|
55
59
|
|
@@ -61,8 +65,8 @@ function fakeDocument(html) {
|
|
61
65
|
casper.test.assertNot(clientutils.findOne('ol'), 'ClientUtils.findOne() can find a matching DOM element');
|
62
66
|
// scoped
|
63
67
|
var scope = clientutils.findOne('ul');
|
64
|
-
casper.test.assertType(clientutils.
|
65
|
-
casper.test.
|
68
|
+
casper.test.assertType(clientutils.findOne('li', scope), 'htmllielement', 'ClientUtils.findOne() can find a matching DOM element within a given scope');
|
69
|
+
casper.test.assertType(clientutils.findOne(x('//li'), scope), 'htmllielement', 'ClientUtils.findOne() can find a matching DOM element using XPath within a given scope');
|
66
70
|
fakeDocument(null);
|
67
71
|
})(casper);
|
68
72
|
|
@@ -81,4 +85,54 @@ function fakeDocument(html) {
|
|
81
85
|
casper.test.assertEquals(xpathSelector.path, '//li[text()="blah"]', 'ClientUtils.processSelector() can process a XPath selector');
|
82
86
|
})(casper);
|
83
87
|
|
84
|
-
casper
|
88
|
+
(function(casper) {
|
89
|
+
casper.start();
|
90
|
+
// getElementBounds
|
91
|
+
casper.then(function() {
|
92
|
+
this.page.content = '<div id="b1" style="position:fixed;top:10px;left:11px;width:50px;height:60px"></div>';
|
93
|
+
this.test.assertEquals(this.getElementBounds('#b1'),
|
94
|
+
{ top: 10, left: 11, width: 50, height: 60 },
|
95
|
+
'ClientUtils.getElementBounds() retrieves element boundaries');
|
96
|
+
});
|
97
|
+
// getElementsBounds
|
98
|
+
casper.start();
|
99
|
+
casper.then(function() {
|
100
|
+
this.test.comment('Casper.getElementsBounds()');
|
101
|
+
var html = '<div id="boxes">';
|
102
|
+
html += ' <div style="position:fixed;top:10px;left:11px;width:50px;height:60px"></div>';
|
103
|
+
html += ' <div style="position:fixed;top:20px;left:21px;width:70px;height:80px"></div>';
|
104
|
+
html += '</div>';
|
105
|
+
this.page.content = html;
|
106
|
+
var bounds = this.getElementsBounds('#boxes div');
|
107
|
+
this.test.assertEquals(bounds[0], { top: 10, left: 11, width: 50, height: 60 },
|
108
|
+
'ClientUtils.getElementsBounds() retrieves multiple elements boundaries');
|
109
|
+
this.test.assertEquals(bounds[1], { top: 20, left: 21, width: 70, height: 80 },
|
110
|
+
'ClientUtils.getElementsBounds() retrieves multiple elements boundaries');
|
111
|
+
});
|
112
|
+
})(casper);
|
113
|
+
|
114
|
+
(function(casper) {
|
115
|
+
// element information
|
116
|
+
casper.test.comment('ClientUtils.getElementInfo()');
|
117
|
+
casper.page.content = '<a href="plop" class="plip plup"><i>paf</i></a>';
|
118
|
+
var info = casper.getElementInfo('a.plip');
|
119
|
+
casper.test.assertEquals(info.nodeName, 'a', 'ClientUtils.getElementInfo() retrieves element name');
|
120
|
+
casper.test.assertEquals(info.attributes, {
|
121
|
+
'href': 'plop',
|
122
|
+
'class': 'plip plup'
|
123
|
+
}, 'ClientUtils.getElementInfo() retrieves element attributes');
|
124
|
+
casper.test.assertEquals(info.html, '<i>paf</i>', 'ClientUtils.getElementInfo() retrieves element html content');
|
125
|
+
casper.test.assertEquals(info.text, 'paf', 'ClientUtils.getElementInfo() retrieves element text');
|
126
|
+
casper.test.assert(info.x > 0, 'ClientUtils.getElementInfo() retrieves element x pos');
|
127
|
+
casper.test.assert(info.y > 0, 'ClientUtils.getElementInfo() retrieves element y pos');
|
128
|
+
casper.test.assert(info.width > 0, 'ClientUtils.getElementInfo() retrieves element width');
|
129
|
+
casper.test.assert(info.height > 0, 'ClientUtils.getElementInfo() retrieves element height');
|
130
|
+
casper.test.assert(info.visible, 'ClientUtils.getElementInfo() retrieves element visibility');
|
131
|
+
casper.test.assertEquals(info.tag, '<a href="plop" class="plip plup"><i>paf</i></a>',
|
132
|
+
'ClientUtils.getElementInfo() retrieves element whole tag contents');
|
133
|
+
|
134
|
+
})(casper);
|
135
|
+
|
136
|
+
casper.run(function() {
|
137
|
+
this.test.done(40);
|
138
|
+
});
|
data/tests/suites/coffee.coffee
CHANGED
data/tests/suites/fs.js
CHANGED
data/tests/suites/http_status.js
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
/**
|
4
|
+
* Special test server to test for HTTP status codes
|
5
|
+
*
|
6
|
+
*/
|
1
7
|
var server = require('webserver').create();
|
2
8
|
var service = server.listen(8090, function (request, response) {
|
3
9
|
var code = parseInt(/^\/(\d+)$/.exec(request.url)[1], 10);
|
@@ -5,24 +11,34 @@ var service = server.listen(8090, function (request, response) {
|
|
5
11
|
response.write("");
|
6
12
|
response.close();
|
7
13
|
});
|
14
|
+
var fs = require("fs");
|
8
15
|
|
9
|
-
|
16
|
+
casper.start();
|
17
|
+
|
18
|
+
// file protocol
|
19
|
+
casper.thenOpen('file://' + phantom.casperPath + '/tests/site/index.html', function() {
|
20
|
+
this.test.assertHttpStatus(null, 'file:// protocol does not set a HTTP status');
|
21
|
+
});
|
22
|
+
|
23
|
+
// http protocol
|
24
|
+
var codes = [100, 101, 102, 118, 200, 201, 202, 203, 204, 205, 206, 207, 210,
|
10
25
|
300, 301, 302, 303, 304, 305, 307, 310,
|
11
26
|
400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413,
|
12
27
|
414, 415, 416, 417, 418, 422, 423, 424, 425, 426, 449, 450,
|
13
28
|
500, 501, 502, 503, 504, 505, 507, 509];
|
14
29
|
|
15
|
-
casper.
|
30
|
+
casper.each(codes, function(self, code) {
|
16
31
|
if (code === 100) {
|
17
32
|
// HTTP 100 is CONTINUE, so don't expect a terminated response
|
18
33
|
return;
|
19
34
|
}
|
20
35
|
this.thenOpen('http://localhost:8090/' + code, function() {
|
36
|
+
this.test.assertEquals(this.currentHTTPStatus, code);
|
21
37
|
this.test.assertHttpStatus(code);
|
22
38
|
});
|
23
39
|
});
|
24
40
|
|
25
41
|
casper.run(function() {
|
26
42
|
server.close();
|
27
|
-
this.test.done();
|
43
|
+
this.test.done(109);
|
28
44
|
});
|
@@ -0,0 +1,33 @@
|
|
1
|
+
/*jshint strict:false*/
|
2
|
+
/*global CasperError casper console phantom require*/
|
3
|
+
var pagestack = require('pagestack');
|
4
|
+
var utils = require('utils');
|
5
|
+
var webpage = require('webpage');
|
6
|
+
var t = casper.test;
|
7
|
+
var stack = pagestack.create();
|
8
|
+
|
9
|
+
|
10
|
+
var page1 = webpage.create();
|
11
|
+
page1.url = 'page1.html';
|
12
|
+
stack.push(page1);
|
13
|
+
t.assertEquals(stack.length, 1);
|
14
|
+
t.assert(utils.isWebPage(stack[0]));
|
15
|
+
t.assertEquals(stack[0], page1);
|
16
|
+
t.assertEquals(stack.list().length, 1);
|
17
|
+
t.assertEquals(stack.list()[0], page1.url);
|
18
|
+
|
19
|
+
var page2 = webpage.create();
|
20
|
+
page2.url = 'page2.html';
|
21
|
+
stack.push(page2);
|
22
|
+
t.assertEquals(stack.length, 2);
|
23
|
+
t.assert(utils.isWebPage(stack[1]));
|
24
|
+
t.assertEquals(stack[1], page2);
|
25
|
+
t.assertEquals(stack.list().length, 2);
|
26
|
+
t.assertEquals(stack.list()[1], page2.url);
|
27
|
+
|
28
|
+
t.assertEquals(stack.clean(page1), 1);
|
29
|
+
t.assertEquals(stack[0], page2);
|
30
|
+
t.assertEquals(stack.list().length, 1);
|
31
|
+
t.assertEquals(stack.list()[0], page2.url);
|
32
|
+
|
33
|
+
casper.test.done();
|