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
@@ -0,0 +1 @@
|
|
1
|
+
{"ok": true}
|
@@ -0,0 +1 @@
|
|
1
|
+
exports.ok = true
|
@@ -0,0 +1 @@
|
|
1
|
+
exports.ok = true;
|
data/tests/selftest.js
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
/**
|
2
|
+
* CasperJS local HTTP test server
|
3
|
+
*/
|
4
|
+
|
5
|
+
/*global phantom casper require*/
|
6
|
+
|
7
|
+
var colorizer = require('colorizer').create('Colorizer');
|
8
|
+
var fs = require('fs');
|
9
|
+
var utils = require('utils');
|
10
|
+
var server = require('webserver').create();
|
11
|
+
var service;
|
12
|
+
var testServerPort = 54321;
|
13
|
+
|
14
|
+
function info(message) {
|
15
|
+
"use strict";
|
16
|
+
console.log(colorizer.colorize('INFO', 'INFO_BAR') + ' ' + message);
|
17
|
+
}
|
18
|
+
|
19
|
+
service = server.listen(testServerPort, function(request, response) {
|
20
|
+
"use strict";
|
21
|
+
var requestPath = request.url;
|
22
|
+
if (requestPath.indexOf('?') !== -1) {
|
23
|
+
requestPath = request.url.split('?')[0];
|
24
|
+
}
|
25
|
+
var pageFile = fs.pathJoin(phantom.casperPath, requestPath);
|
26
|
+
if (!fs.exists(pageFile) || !fs.isFile(pageFile)) {
|
27
|
+
response.statusCode = 404;
|
28
|
+
console.log(utils.format('Test server url not found: %s (file: %s)', request.url, pageFile), "warning");
|
29
|
+
response.write("404 - NOT FOUND");
|
30
|
+
} else {
|
31
|
+
var headers = {};
|
32
|
+
if (/js$/.test(pageFile)) {
|
33
|
+
headers['Content-Type'] = "application/javascript";
|
34
|
+
}
|
35
|
+
response.writeHead(200, headers);
|
36
|
+
response.write(fs.read(pageFile));
|
37
|
+
}
|
38
|
+
response.close();
|
39
|
+
});
|
40
|
+
|
41
|
+
// overriding Casper.open to prefix all test urls
|
42
|
+
casper.setFilter('open.location', function(location) {
|
43
|
+
"use strict";
|
44
|
+
if (/^file/.test(location)) {
|
45
|
+
return location;
|
46
|
+
}
|
47
|
+
if (!/^http/.test(location)) {
|
48
|
+
return utils.format('http://localhost:%d/%s', testServerPort, location);
|
49
|
+
}
|
50
|
+
return location;
|
51
|
+
});
|
52
|
+
|
53
|
+
// test suites completion listener
|
54
|
+
casper.test.on('tests.complete', function() {
|
55
|
+
"use strict";
|
56
|
+
server.close();
|
57
|
+
});
|
data/tests/site/dummy.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
document.write('foo');
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
5
|
+
<title>CasperJS test form</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<form action="result.html" enctype="multipart/form-data">
|
9
|
+
<input type="text" name="foo[bar]">
|
10
|
+
<input type="text" name="foo[baz]">
|
11
|
+
<input type="submit" name="submit" value="submit">
|
12
|
+
</form>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<title>CasperJS frame 2</title>
|
6
|
+
</head>
|
7
|
+
<body id="f2">
|
8
|
+
<h1>This is frame 2.</h1>
|
9
|
+
<p><a href="frame3.html" target="frame2">frame 3</a></p>
|
10
|
+
</body>
|
11
|
+
</html>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<title>CasperJS frame 3</title>
|
6
|
+
</head>
|
7
|
+
<body id="f3">
|
8
|
+
<h1>This is frame 3.</h1>
|
9
|
+
<p><a href="frame2.html">frame 2</a></p>
|
10
|
+
</body>
|
11
|
+
</html>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
5
|
+
<title>CasperJS test frames</title>
|
6
|
+
</head>
|
7
|
+
<frameset cols="50%,50%%">
|
8
|
+
<frame src="frame1.html" name="frame1">
|
9
|
+
<frame src="frame2.html" name="frame2">
|
10
|
+
</frameset>
|
11
|
+
</html>
|
12
|
+
|
data/tests/site/global.html
CHANGED
data/tests/site/index.html
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<title>CasperJS test popup</title>
|
6
|
+
</head>
|
7
|
+
<a href="." class="close">close</a>
|
8
|
+
<body>
|
9
|
+
<a href="/tests/site/form.html" target="_blank">new window</a>
|
10
|
+
<script>
|
11
|
+
var w = window.open("http://localhost:54321/tests/site/index.html",
|
12
|
+
"popup", "menubar=no, status=no, scrollbars=no, menubar=no, width=400, height=300");
|
13
|
+
document.querySelector('a').onclick = function onclick(evt) {
|
14
|
+
evt.preventDefault();
|
15
|
+
w.close();
|
16
|
+
};
|
17
|
+
</script>
|
18
|
+
</body>
|
19
|
+
</html>
|
data/tests/site/resources.html
CHANGED
@@ -3,14 +3,13 @@
|
|
3
3
|
<head>
|
4
4
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
5
|
<title>CasperJS test resource</title>
|
6
|
-
<script>
|
7
|
-
setTimeout(function () {
|
8
|
-
var path = "images/phantom.png?" + new Date();
|
9
|
-
document.querySelector("img").setAttribute("src", path);
|
10
|
-
}, 1000);
|
11
|
-
</script>
|
12
6
|
</head>
|
13
7
|
<body>
|
14
|
-
<
|
8
|
+
<script id="loader"></script>
|
9
|
+
<script>
|
10
|
+
setTimeout(function () {
|
11
|
+
document.querySelector("#loader").setAttribute("src", "dummy.js");
|
12
|
+
}, 1000);
|
13
|
+
</script>
|
15
14
|
</body>
|
16
|
-
</html>
|
15
|
+
</html>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<title>CasperJS url tests</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<ul>
|
9
|
+
<li><a href="?test=Forlì">raw unicode</a></li>
|
10
|
+
<li><a href="?test=Forl%EC">escaped</a></li>
|
11
|
+
<li><a href="?test=Forl%C3%AC">uri encoded</a></li>
|
12
|
+
</ul>
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
function testUA(ua, match) {
|
2
4
|
casper.test.assertMatch(
|
3
5
|
ua, match, 'Default user agent matches ' + match
|
@@ -20,5 +22,5 @@ casper.thenOpen('tests/site/index.html');
|
|
20
22
|
|
21
23
|
casper.run(function() {
|
22
24
|
this.removeListener('resource.requested', fetchUA);
|
23
|
-
this.test.done();
|
25
|
+
this.test.done(3);
|
24
26
|
});
|
@@ -0,0 +1,14 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
|
4
|
+
var ok = false;
|
5
|
+
|
6
|
+
casper.on('remote.alert', function(message) {
|
7
|
+
ok = message === 'plop';
|
8
|
+
});
|
9
|
+
|
10
|
+
casper.start('tests/site/alert.html').run(function() {
|
11
|
+
this.test.assert(ok, 'alert event has been intercepted');
|
12
|
+
this.removeAllListeners('remote.alert');
|
13
|
+
this.test.done(1);
|
14
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false maxstatements:99*/
|
3
|
+
|
4
|
+
casper.start('tests/site/index.html');
|
5
|
+
|
6
|
+
casper.configureHttpAuth('http://localhost/');
|
7
|
+
casper.test.assertEquals(casper.page.settings.userName, undefined);
|
8
|
+
casper.test.assertEquals(casper.page.settings.password, undefined);
|
9
|
+
|
10
|
+
casper.configureHttpAuth('http://niko:plop@localhost/');
|
11
|
+
casper.test.assertEquals(casper.page.settings.userName, 'niko');
|
12
|
+
casper.test.assertEquals(casper.page.settings.password, 'plop');
|
13
|
+
|
14
|
+
casper.configureHttpAuth('http://localhost/', {username: 'john', password: 'doe'});
|
15
|
+
casper.test.assertEquals(casper.page.settings.userName, 'john');
|
16
|
+
casper.test.assertEquals(casper.page.settings.password, 'doe');
|
17
|
+
|
18
|
+
casper.configureHttpAuth('http://niko:plop@localhost/', {username: 'john', password: 'doe'});
|
19
|
+
casper.test.assertEquals(casper.page.settings.userName, 'niko');
|
20
|
+
casper.test.assertEquals(casper.page.settings.password, 'plop');
|
21
|
+
|
22
|
+
casper.run(function() {
|
23
|
+
this.test.done(8);
|
24
|
+
});
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
var fs = require('fs'), testFile = '/tmp/__casper_test_capture.png';
|
2
4
|
|
3
5
|
if (fs.exists(testFile) && fs.isFile(testFile)) {
|
@@ -11,21 +13,19 @@ casper.start('tests/site/index.html', function() {
|
|
11
13
|
this.test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot');
|
12
14
|
});
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
});
|
24
|
-
}
|
16
|
+
casper.thenOpen('tests/site/index.html', function() {
|
17
|
+
this.test.comment('Casper.captureBase64()');
|
18
|
+
this.test.assert(this.captureBase64('png').length > 0,
|
19
|
+
'Casper.captureBase64() rendered a page capture as base64');
|
20
|
+
this.test.assert(this.captureBase64('png', 'ul').length > 0,
|
21
|
+
'Casper.captureBase64() rendered a capture from a selector as base64');
|
22
|
+
this.test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0,
|
23
|
+
'Casper.captureBase64() rendered a capture from a clipRect as base64');
|
24
|
+
});
|
25
25
|
|
26
26
|
casper.run(function() {
|
27
27
|
try {
|
28
28
|
fs.remove(testFile);
|
29
29
|
} catch(e) {}
|
30
|
-
this.test.done();
|
30
|
+
this.test.done(4);
|
31
31
|
});
|
@@ -1,3 +1,5 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
casper.start('tests/site/index.html', function() {
|
2
4
|
this.click('a[href="test.html"]');
|
3
5
|
});
|
@@ -56,6 +58,14 @@ casper.then(function() {
|
|
56
58
|
this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position');
|
57
59
|
});
|
58
60
|
|
61
|
+
// element focus on click
|
62
|
+
casper.then(function() {
|
63
|
+
this.page.content = '<form><input type="text" name="foo"></form>'
|
64
|
+
this.click('form input[name=foo]')
|
65
|
+
this.page.sendEvent('keypress', 'bar');
|
66
|
+
this.test.assertEquals(this.getFormValues('form')['foo'], 'bar', 'Casper.click() sets the focus on clicked element');
|
67
|
+
});
|
68
|
+
|
59
69
|
casper.run(function() {
|
60
|
-
this.test.done();
|
70
|
+
this.test.done(22);
|
61
71
|
});
|
@@ -1,21 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
casper.test.done();
|
5
|
-
} else {
|
6
|
-
var received;
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
var received;
|
7
4
|
|
5
|
+
casper.setFilter('page.confirm', function(message) {
|
6
|
+
received = message;
|
7
|
+
return true;
|
8
|
+
});
|
9
|
+
|
10
|
+
casper.start('tests/site/confirm.html', function() {
|
11
|
+
this.test.assert(this.getGlobal('confirmed'), 'confirmation dialog accepted');
|
12
|
+
});
|
13
|
+
|
14
|
+
casper.then(function() {
|
15
|
+
//remove the page.confirm event filter so we can add a new one
|
16
|
+
casper.removeAllFilters('page.confirm')
|
8
17
|
casper.setFilter('page.confirm', function(message) {
|
9
|
-
|
10
|
-
return true;
|
18
|
+
return false;
|
11
19
|
});
|
20
|
+
});
|
12
21
|
|
13
|
-
|
14
|
-
|
15
|
-
|
22
|
+
casper.thenOpen('/tests/site/confirm.html', function() {
|
23
|
+
this.test.assertNot(this.getGlobal('confirmed'), 'confirmation dialog canceled');
|
24
|
+
});
|
16
25
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
}
|
26
|
+
casper.run(function() {
|
27
|
+
this.test.assertEquals(received, 'are you sure?', 'confirmation message is ok');
|
28
|
+
this.test.done(3);
|
29
|
+
});
|
@@ -0,0 +1,10 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
3
|
+
casper.start('tests/site/index.html', function() {
|
4
|
+
this.test.assertEquals(this.getHTML('ul li'), 'one', 'Casper.getHTML() retrieves inner HTML by default');
|
5
|
+
this.test.assertEquals(this.getHTML('ul li', true), '<li>one</li>', 'Casper.getHTML() can retrieve outer HTML');
|
6
|
+
});
|
7
|
+
|
8
|
+
casper.run(function() {
|
9
|
+
casper.test.done(2);
|
10
|
+
});
|
@@ -1,8 +1,10 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
casper.start('tests/site/elementattribute.html', function() {
|
2
4
|
this.test.comment('Casper.getElementAttribute()');
|
3
5
|
this.test.assertEquals(this.getElementAttribute('.testo','data-stuff'), 'beautiful string', 'Casper.getElementAttribute() works as intended');
|
4
6
|
});
|
5
7
|
|
6
8
|
casper.run(function() {
|
7
|
-
this.test.done();
|
9
|
+
this.test.done(1);
|
8
10
|
});
|
@@ -1,6 +1,10 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false*/
|
1
3
|
var fs = require('fs');
|
2
4
|
|
3
|
-
|
5
|
+
// FIXME: we're using local url scheme until https://github.com/ariya/phantomjs/pull/288 is
|
6
|
+
// possibly merged
|
7
|
+
casper.start('file://' + phantom.casperPath + '/tests/site/index.html', function() {
|
4
8
|
var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png';
|
5
9
|
var image = this.base64encode(imageUrl);
|
6
10
|
|
@@ -16,5 +20,5 @@ casper.start('tests/site/index.html', function() {
|
|
16
20
|
});
|
17
21
|
|
18
22
|
casper.run(function() {
|
19
|
-
this.test.done();
|
23
|
+
this.test.done(2);
|
20
24
|
});
|
@@ -1,27 +1,87 @@
|
|
1
|
+
/*global casper*/
|
2
|
+
/*jshint strict:false maxparams:99*/
|
1
3
|
casper.test.comment('Casper.evaluate()');
|
2
4
|
|
3
5
|
casper.start();
|
4
6
|
|
5
|
-
var
|
6
|
-
"
|
7
|
-
"
|
8
|
-
"
|
9
|
-
"
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
7
|
+
var context = {
|
8
|
+
"_boolean_true": true,
|
9
|
+
"_boolean_false": false,
|
10
|
+
"_int_number": 42,
|
11
|
+
"_float_number": 1337.42,
|
12
|
+
"_string": "plop! \"Ÿ£$\" 'no'",
|
13
|
+
"_array": [1, 2, 3],
|
14
|
+
"_object": {a: 1, b: 2},
|
15
|
+
"_function": function(){console.log('ok');}
|
13
16
|
};
|
14
17
|
|
15
|
-
var
|
16
|
-
|
17
|
-
|
18
|
+
var result = casper.evaluate(function(_boolean_true,
|
19
|
+
_boolean_false,
|
20
|
+
_int_number,
|
21
|
+
_float_number,
|
22
|
+
_string,
|
23
|
+
_array,
|
24
|
+
_object,
|
25
|
+
_function) {
|
26
|
+
return [].map.call(arguments, function(arg) {
|
27
|
+
return typeof(arg);
|
28
|
+
});
|
29
|
+
}, context);
|
18
30
|
|
19
|
-
casper.test.
|
20
|
-
|
31
|
+
casper.test.assertEquals(result.toString(),
|
32
|
+
['boolean', 'boolean', 'number', 'number', 'string', 'object', 'object', 'function'].toString(),
|
33
|
+
'Casper.evaluate() handles passed argument context correcly');
|
21
34
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
35
|
+
// no context
|
36
|
+
casper.test.assertEquals(casper.evaluate(function() {
|
37
|
+
return 42;
|
38
|
+
}), 42, 'Casper.evaluate() handles evaluation with no context passed');
|
26
39
|
|
27
|
-
|
40
|
+
// object context (previous casperjs versions compatibility mode)
|
41
|
+
casper.test.assertEquals(casper.evaluate(function(a) {
|
42
|
+
return [a];
|
43
|
+
}, {a: "foo"}), ["foo"], 'Casper.evaluate() accepts an object as arguments context');
|
44
|
+
casper.test.assertEquals(casper.evaluate(function(a, b) {
|
45
|
+
return [a, b];
|
46
|
+
}, {a: "foo", b: "bar"}), ["foo", "bar"], 'Casper.evaluate() accepts an object as arguments context');
|
47
|
+
casper.test.assertEquals(casper.evaluate(function(a, b, c) {
|
48
|
+
return [a, b, c];
|
49
|
+
}, {a: "foo", b: "bar", c: "baz"}), ["foo", "bar", "baz"], 'Casper.evaluate() accepts an object as arguments context');
|
50
|
+
|
51
|
+
// array context
|
52
|
+
casper.test.assertEquals(casper.evaluate(function(a) {
|
53
|
+
return [a];
|
54
|
+
}, ["foo"]), ["foo"], 'Casper.evaluate() accepts an array as arguments context');
|
55
|
+
casper.test.assertEquals(casper.evaluate(function(a, b) {
|
56
|
+
return [a, b];
|
57
|
+
}, ["foo", "bar"]), ["foo", "bar"], 'Casper.evaluate() accepts an array as arguments context');
|
58
|
+
casper.test.assertEquals(casper.evaluate(function(a, b, c) {
|
59
|
+
return [a, b, c];
|
60
|
+
}, ["foo", "bar", "baz"]), ["foo", "bar", "baz"], 'Casper.evaluate() accepts an array as arguments context');
|
61
|
+
|
62
|
+
// natural arguments context (phantomjs equivalent)
|
63
|
+
casper.test.assertEquals(casper.evaluate(function(a) {
|
64
|
+
return [a];
|
65
|
+
}, "foo"), ["foo"], 'Casper.evaluate() accepts natural arguments context');
|
66
|
+
casper.test.assertEquals(casper.evaluate(function(a, b) {
|
67
|
+
return [a, b];
|
68
|
+
}, "foo", "bar"), ["foo", "bar"], 'Casper.evaluate() accepts natural arguments context');
|
69
|
+
casper.test.assertEquals(casper.evaluate(function(a, b, c) {
|
70
|
+
return [a, b, c];
|
71
|
+
}, "foo", "bar", "baz"), ["foo", "bar", "baz"], 'Casper.evaluate() accepts natural arguments context');
|
72
|
+
|
73
|
+
casper.start().thenEvaluate(function(a, b) {
|
74
|
+
window.a = a
|
75
|
+
window.b = b;
|
76
|
+
}, "foo", "bar");
|
77
|
+
|
78
|
+
casper.then(function() {
|
79
|
+
this.test.comment('Casper.thenEvaluate()');
|
80
|
+
this.test.assertEquals(this.getGlobal('a'), "foo", "Casper.thenEvaluate() sets args");
|
81
|
+
this.test.assertEquals(this.getGlobal('b'), "bar",
|
82
|
+
"Casper.thenEvaluate() sets args the same way evaluate() does");
|
83
|
+
});
|
84
|
+
|
85
|
+
casper.run(function() {
|
86
|
+
this.test.done(13);
|
87
|
+
});
|