casperjs 1.0.0.RC1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +179 -0
- data/LICENSE.md +19 -0
- data/README.md +30 -0
- data/bin/bootstrap.js +292 -0
- data/bin/usage.txt +10 -0
- data/casperjs.gemspec +21 -0
- data/modules/casper.js +1679 -0
- data/modules/cli.js +138 -0
- data/modules/clientutils.js +595 -0
- data/modules/colorizer.js +129 -0
- data/modules/events.js +247 -0
- data/modules/injector.js +93 -0
- data/modules/mouse.js +110 -0
- data/modules/querystring.js +187 -0
- data/modules/tester.js +807 -0
- data/modules/utils.js +429 -0
- data/modules/vendors/coffee-script.js +8 -0
- data/modules/xunit.js +123 -0
- data/package.json +35 -0
- data/rubybin/casperjs +57 -0
- data/samples/bbcshots.coffee +64 -0
- data/samples/bbcshots.js +80 -0
- data/samples/cliplay.coffee +19 -0
- data/samples/cliplay.js +21 -0
- data/samples/customevents.coffee +11 -0
- data/samples/customevents.js +13 -0
- data/samples/customlogging.coffee +33 -0
- data/samples/customlogging.js +42 -0
- data/samples/download.coffee +10 -0
- data/samples/download.js +11 -0
- data/samples/dynamic.coffee +60 -0
- data/samples/dynamic.js +65 -0
- data/samples/each.coffee +14 -0
- data/samples/each.js +17 -0
- data/samples/events.coffee +34 -0
- data/samples/events.js +41 -0
- data/samples/extends.coffee +29 -0
- data/samples/extends.js +37 -0
- data/samples/googlelinks.coffee +27 -0
- data/samples/googlelinks.js +33 -0
- data/samples/googlematch.coffee +47 -0
- data/samples/googlematch.js +65 -0
- data/samples/googlepagination.coffee +40 -0
- data/samples/googlepagination.js +51 -0
- data/samples/googletesting.coffee +17 -0
- data/samples/googletesting.js +23 -0
- data/samples/logcolor.coffee +10 -0
- data/samples/logcolor.js +11 -0
- data/samples/metaextract.coffee +23 -0
- data/samples/metaextract.js +29 -0
- data/samples/multirun.coffee +37 -0
- data/samples/multirun.js +56 -0
- data/samples/screenshot.coffee +28 -0
- data/samples/screenshot.js +33 -0
- data/samples/statushandlers.coffee +15 -0
- data/samples/statushandlers.js +19 -0
- data/samples/steptimeout.coffee +37 -0
- data/samples/steptimeout.js +45 -0
- data/samples/timeout.coffee +39 -0
- data/samples/timeout.js +47 -0
- data/tests/run.js +76 -0
- data/tests/site/alert.html +10 -0
- data/tests/site/click.html +40 -0
- data/tests/site/confirm.html +12 -0
- data/tests/site/elementattribute.html +6 -0
- data/tests/site/error.html +10 -0
- data/tests/site/form.html +26 -0
- data/tests/site/global.html +9 -0
- data/tests/site/images/phantom.png +0 -0
- data/tests/site/index.html +17 -0
- data/tests/site/mouse-events.html +47 -0
- data/tests/site/multiple-forms.html +16 -0
- data/tests/site/page1.html +8 -0
- data/tests/site/page2.html +8 -0
- data/tests/site/page3.html +8 -0
- data/tests/site/prompt.html +12 -0
- data/tests/site/resources.html +16 -0
- data/tests/site/result.html +11 -0
- data/tests/site/test.html +10 -0
- data/tests/site/visible.html +17 -0
- data/tests/site/waitFor.html +22 -0
- data/tests/suites/casper/agent.js +24 -0
- data/tests/suites/casper/capture.js +31 -0
- data/tests/suites/casper/click.js +61 -0
- data/tests/suites/casper/confirm.js +21 -0
- data/tests/suites/casper/elementattribute.js +8 -0
- data/tests/suites/casper/encode.js +20 -0
- data/tests/suites/casper/evaluate.js +27 -0
- data/tests/suites/casper/events.js +38 -0
- data/tests/suites/casper/exists.js +9 -0
- data/tests/suites/casper/fetchtext.js +9 -0
- data/tests/suites/casper/flow.coffee +38 -0
- data/tests/suites/casper/formfill.js +69 -0
- data/tests/suites/casper/global.js +9 -0
- data/tests/suites/casper/history.js +21 -0
- data/tests/suites/casper/hooks.js +41 -0
- data/tests/suites/casper/logging.js +38 -0
- data/tests/suites/casper/mouseevents.js +27 -0
- data/tests/suites/casper/onerror.js +19 -0
- data/tests/suites/casper/open.js +73 -0
- data/tests/suites/casper/prompt.js +17 -0
- data/tests/suites/casper/resources.coffee +24 -0
- data/tests/suites/casper/start.js +15 -0
- data/tests/suites/casper/steps.js +32 -0
- data/tests/suites/casper/viewport.js +11 -0
- data/tests/suites/casper/visible.js +17 -0
- data/tests/suites/casper/wait.js +27 -0
- data/tests/suites/casper/xpath.js +32 -0
- data/tests/suites/cli.js +125 -0
- data/tests/suites/clientutils.js +84 -0
- data/tests/suites/coffee.coffee +19 -0
- data/tests/suites/fs.js +36 -0
- data/tests/suites/http_status.js +28 -0
- data/tests/suites/injector.js +64 -0
- data/tests/suites/tester.js +121 -0
- data/tests/suites/utils.js +209 -0
- data/tests/suites/xunit.js +16 -0
- data/tests/testdir/01_a/abc.js +0 -0
- data/tests/testdir/01_a/def.js +0 -0
- data/tests/testdir/02_b/abc.js +0 -0
- data/tests/testdir/03_a.js +0 -0
- data/tests/testdir/03_b.js +0 -0
- data/tests/testdir/04/01_init.js +0 -0
- data/tests/testdir/04/02_do.js +0 -0
- metadata +192 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
###
|
|
2
|
+
Just a silly game.
|
|
3
|
+
|
|
4
|
+
$ casperjs samples/timeout.js 500
|
|
5
|
+
Will google.com load in less than 500ms?
|
|
6
|
+
NOPE.
|
|
7
|
+
|
|
8
|
+
$ casperjs samples/timeout.js 1000
|
|
9
|
+
Will google.com load in less than 1000ms?
|
|
10
|
+
NOPE.
|
|
11
|
+
|
|
12
|
+
$ casperjs samples/timeout.js 1500
|
|
13
|
+
Will google.com load in less than 1500ms?
|
|
14
|
+
NOPE.
|
|
15
|
+
|
|
16
|
+
$ casperjs samples/timeout.js 2000
|
|
17
|
+
Will google.com load in less than 2000ms?
|
|
18
|
+
YES!
|
|
19
|
+
###
|
|
20
|
+
|
|
21
|
+
casper = require("casper").create
|
|
22
|
+
onTimeout: ->
|
|
23
|
+
@echo "NOPE.", "RED_BAR"
|
|
24
|
+
@exit()
|
|
25
|
+
|
|
26
|
+
timeout = ~~casper.cli.get 0
|
|
27
|
+
if timeout < 1
|
|
28
|
+
casper
|
|
29
|
+
.echo("You must pass a valid timeout value")
|
|
30
|
+
.exit(1)
|
|
31
|
+
|
|
32
|
+
casper.echo "Will google.com load in less than #{timeout}ms?"
|
|
33
|
+
casper.options.timeout = timeout
|
|
34
|
+
|
|
35
|
+
casper.start "http://www.google.com/", ->
|
|
36
|
+
@echo "YES!", "GREEN_BAR"
|
|
37
|
+
@exit()
|
|
38
|
+
|
|
39
|
+
casper.run()
|
data/samples/timeout.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Just a silly game.
|
|
3
|
+
*
|
|
4
|
+
* $ casperjs samples/timeout.js 500
|
|
5
|
+
* Will google.com load in less than 500ms?
|
|
6
|
+
* NOPE.
|
|
7
|
+
*
|
|
8
|
+
* $ casperjs samples/timeout.js 1000
|
|
9
|
+
* Will google.com load in less than 1000ms?
|
|
10
|
+
* NOPE.
|
|
11
|
+
*
|
|
12
|
+
* $ casperjs samples/timeout.js 1500
|
|
13
|
+
* Will google.com load in less than 1500ms?
|
|
14
|
+
* NOPE.
|
|
15
|
+
*
|
|
16
|
+
* $ casperjs samples/timeout.js 2000
|
|
17
|
+
* Will google.com load in less than 2000ms?
|
|
18
|
+
* YES!
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
var casper = require("casper").create({
|
|
22
|
+
onTimeout: function() {
|
|
23
|
+
this
|
|
24
|
+
.echo("NOPE.", "RED_BAR")
|
|
25
|
+
.exit()
|
|
26
|
+
;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
var timeout = ~~casper.cli.get(0);
|
|
31
|
+
|
|
32
|
+
if (timeout < 1) {
|
|
33
|
+
casper
|
|
34
|
+
.echo("You must pass a valid timeout value")
|
|
35
|
+
.exit(1)
|
|
36
|
+
;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
casper.echo("Will google.com load in less than " + timeout + "ms?");
|
|
40
|
+
casper.options.timeout = timeout;
|
|
41
|
+
|
|
42
|
+
casper.start("http://www.google.com/", function() {
|
|
43
|
+
this.echo("YES!", "GREEN_BAR");
|
|
44
|
+
this.exit();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
casper.run();
|
data/tests/run.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
if (!phantom.casperLoaded) {
|
|
2
|
+
console.log('This script must be invoked using the casperjs executable');
|
|
3
|
+
phantom.exit(1);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
var fs = require('fs');
|
|
7
|
+
var utils = require('utils');
|
|
8
|
+
var f = utils.format;
|
|
9
|
+
var includes = [];
|
|
10
|
+
var tests = [];
|
|
11
|
+
var casper = require('casper').create({
|
|
12
|
+
exitOnError: false
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// local utils
|
|
16
|
+
function checkIncludeFile(include) {
|
|
17
|
+
var absInclude = fs.absolute(include.trim());
|
|
18
|
+
if (!fs.exists(absInclude)) {
|
|
19
|
+
casper.warn("%s file not found, can't be included", absInclude);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!utils.isJsFile(absInclude)) {
|
|
23
|
+
casper.warn("%s is not a supported file type, can't be included", absInclude);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (fs.isDirectory(absInclude)) {
|
|
27
|
+
casper.warn("%s is a directory, can't be included", absInclude);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (tests.indexOf(include) > -1 || tests.indexOf(absInclude) > -1) {
|
|
31
|
+
casper.warn("%s is a test file, can't be included", absInclude);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
return absInclude;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// parse some options from cli
|
|
38
|
+
casper.options.verbose = casper.cli.get('direct') || false;
|
|
39
|
+
casper.options.logLevel = casper.cli.get('log-level') || "error";
|
|
40
|
+
|
|
41
|
+
// overriding Casper.open to prefix all test urls
|
|
42
|
+
casper.setFilter('open.location', function(location) {
|
|
43
|
+
if (!/^http/.test(location)) {
|
|
44
|
+
return f('file://%s/%s', fs.workingDirectory, location);
|
|
45
|
+
}
|
|
46
|
+
return location;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// test paths are passed as args
|
|
50
|
+
if (casper.cli.args.length) {
|
|
51
|
+
tests = casper.cli.args.filter(function(path) {
|
|
52
|
+
return fs.isFile(path) || fs.isDirectory(path);
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
casper.echo('No test path passed, exiting.', 'RED_BAR', 80);
|
|
56
|
+
casper.exit(1);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// includes handling
|
|
60
|
+
if (casper.cli.has('includes')) {
|
|
61
|
+
includes = casper.cli.get('includes').split(',').map(function(include) {
|
|
62
|
+
// we can't use filter() directly because of abspath transformation
|
|
63
|
+
return checkIncludeFile(include);
|
|
64
|
+
}).filter(function(include) {
|
|
65
|
+
return utils.isString(include);
|
|
66
|
+
});
|
|
67
|
+
casper.test.includes = utils.unique(includes);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// test suites completion listener
|
|
71
|
+
casper.test.on('tests.complete', function() {
|
|
72
|
+
this.renderResults(true, undefined, casper.cli.get('xunit') || undefined);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// run all the suites
|
|
76
|
+
casper.test.runSuites.apply(casper.test, tests);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
5
|
+
<title>CasperJS test click</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<a id="test1" href="javascript:results.test1 = true;">test1</a>
|
|
9
|
+
<a id="test2" href="#" onclick="results.test2 = true;">test2</a>
|
|
10
|
+
<a id="test3" href="page1.html" onclick="results.test3 = true; return false">test3</a>
|
|
11
|
+
<a id="test4" href="http://www.google.com/">test4</a>
|
|
12
|
+
<script>
|
|
13
|
+
(function(window) {
|
|
14
|
+
window.results = {
|
|
15
|
+
test1: false,
|
|
16
|
+
test2: false,
|
|
17
|
+
test3: false,
|
|
18
|
+
test4: false,
|
|
19
|
+
testdown: [],
|
|
20
|
+
testup: [],
|
|
21
|
+
testmove: [],
|
|
22
|
+
testclick: []
|
|
23
|
+
};
|
|
24
|
+
document.querySelector('#test4').onclick = function(event) {
|
|
25
|
+
results.test4 = true;
|
|
26
|
+
event.preventDefault();
|
|
27
|
+
};
|
|
28
|
+
window.onmousedown = function(event) {
|
|
29
|
+
results.testdown = [event.x, event.y];
|
|
30
|
+
};
|
|
31
|
+
window.onmouseup = function(event) {
|
|
32
|
+
results.testup = [event.x, event.y];
|
|
33
|
+
};
|
|
34
|
+
window.onmousemove = function(event) {
|
|
35
|
+
results.testmove = [event.x, event.y];
|
|
36
|
+
};
|
|
37
|
+
})(window);
|
|
38
|
+
</script>
|
|
39
|
+
</body>
|
|
40
|
+
</html>
|
|
@@ -0,0 +1,26 @@
|
|
|
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="email" placeholder="email">
|
|
10
|
+
<input type="password" name="password" placeholder="password">
|
|
11
|
+
<textarea name="content"></textarea>
|
|
12
|
+
<select name="topic">
|
|
13
|
+
<option>foo</option>
|
|
14
|
+
<option value="bar">baz</option>
|
|
15
|
+
</select>
|
|
16
|
+
<input type="checkbox" name="check">
|
|
17
|
+
<input type="radio" name="choice" value="yes">
|
|
18
|
+
<input type="radio" name="choice" value="no">
|
|
19
|
+
<input type="file" name="file">
|
|
20
|
+
<input type="checkbox" name="checklist[]" value="1">
|
|
21
|
+
<input type="checkbox" name="checklist[]" value="2">
|
|
22
|
+
<input type="checkbox" name="checklist[]" value="3">
|
|
23
|
+
<input type="submit" name="submit" value="submit">
|
|
24
|
+
</form>
|
|
25
|
+
</body>
|
|
26
|
+
</html>
|
|
Binary file
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
5
|
+
<title>CasperJS test index</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<img src="images/phantom.png"/>
|
|
9
|
+
<a href="test.html">test</a>
|
|
10
|
+
<a href="form.html">form</a>
|
|
11
|
+
<ul>
|
|
12
|
+
<li>one</li>
|
|
13
|
+
<li>two</li>
|
|
14
|
+
<li>three</li>
|
|
15
|
+
</ul>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
5
|
+
<title>CasperJS test mouse events</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<a id="test1" href="#" onmousedown="results.test1 = true;">test</a>
|
|
9
|
+
<a id="test2" href="#">test</a>
|
|
10
|
+
<a id="test3" href="#" onmouseup="results.test3 = true;">test</a>
|
|
11
|
+
<a id="test4" href="#">test</a>
|
|
12
|
+
<a id="test5" href="#" onmouseover="results.test5 = true;">test</a>
|
|
13
|
+
<a id="test6" href="#">test</a>
|
|
14
|
+
<a id="test7" href="#" onmouseout="results.test7 = true;">test</a>
|
|
15
|
+
<a id="test8" href="#">test</a>
|
|
16
|
+
<script>
|
|
17
|
+
(function(window) {
|
|
18
|
+
window.results = {
|
|
19
|
+
test1: false,
|
|
20
|
+
test2: false,
|
|
21
|
+
test3: false,
|
|
22
|
+
test4: false,
|
|
23
|
+
test5: false,
|
|
24
|
+
test6: false,
|
|
25
|
+
test7: false,
|
|
26
|
+
test8: false
|
|
27
|
+
};
|
|
28
|
+
document.querySelector('#test2').onmousedown = function(event) {
|
|
29
|
+
results.test2 = true;
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
};
|
|
32
|
+
document.querySelector('#test4').onmouseup = function(event) {
|
|
33
|
+
results.test4 = true;
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
};
|
|
36
|
+
document.querySelector('#test6').onmouseover = function(event) {
|
|
37
|
+
results.test6 = true;
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
};
|
|
40
|
+
document.querySelector('#test8').onmouseout = function(event) {
|
|
41
|
+
results.test8 = true;
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
};
|
|
44
|
+
})(window);
|
|
45
|
+
</script>
|
|
46
|
+
</body>
|
|
47
|
+
</html>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Multiple forms test</title>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<form name="f1">
|
|
8
|
+
<input type="hidden" name="f" value="f1">
|
|
9
|
+
<input type="text" name="yo">
|
|
10
|
+
</form>
|
|
11
|
+
<form name="f2">
|
|
12
|
+
<input type="hidden" name="f" value="f2">
|
|
13
|
+
<input type="text" name="yo">
|
|
14
|
+
</form>
|
|
15
|
+
</body>
|
|
16
|
+
</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 prompt</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<script>
|
|
9
|
+
var name = prompt('what is your name?', 'Norris');
|
|
10
|
+
</script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
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
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<img width="55" height="55" border="1">
|
|
15
|
+
</body>
|
|
16
|
+
</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 test form result</title>
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<p>this is the result page</p>
|
|
9
|
+
<p><a href="index.html">Return back home</a></p>
|
|
10
|
+
</body>
|
|
11
|
+
</html>
|