casperjs 1.0.0.RC1
Sign up to get free protection for your applications and to get access to all the features.
- 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,41 @@
|
|
1
|
+
// Dear curious test reader,
|
2
|
+
// The on* family of methods is considered deprecated since 0.6.0; please use events instead
|
3
|
+
|
4
|
+
// Casper.options.onStepComplete
|
5
|
+
casper.start('tests/site/index.html', function() {
|
6
|
+
this.options.onStepComplete = function(self, stepResult) {
|
7
|
+
this.test.comment('Casper.options.onStepComplete()');
|
8
|
+
this.test.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete');
|
9
|
+
self.options.onStepComplete = null;
|
10
|
+
};
|
11
|
+
return 'ok';
|
12
|
+
});
|
13
|
+
|
14
|
+
// Casper.options.onResourceRequested & Casper.options.onResourceReceived
|
15
|
+
casper.then(function() {
|
16
|
+
this.options.onResourceReceived = function(self, resource) {
|
17
|
+
this.test.comment('Casper.options.onResourceReceived()');
|
18
|
+
this.test.assertType(resource, 'object', 'Casper.options.onResourceReceived() retrieve a resource object');
|
19
|
+
this.test.assert('status' in resource, 'Casper.options.onResourceReceived() retrieve a valid resource object');
|
20
|
+
self.options.onResourceReceived = null;
|
21
|
+
};
|
22
|
+
this.options.onResourceRequested = function(self, request) {
|
23
|
+
this.test.comment('Casper.options.onResourceRequested()');
|
24
|
+
this.test.assertType(request, 'object', 'Casper.options.onResourceRequested() retrieve a request object');
|
25
|
+
this.test.assert('method' in request, 'Casper.options.onResourceRequested() retrieve a valid request object');
|
26
|
+
self.options.onResourceRequested = null;
|
27
|
+
};
|
28
|
+
this.thenOpen('tests/site/page1.html');
|
29
|
+
});
|
30
|
+
|
31
|
+
// Casper.options.onAlert()
|
32
|
+
casper.then(function() {
|
33
|
+
this.options.onAlert = function(self, message) {
|
34
|
+
self.test.assertEquals(message, 'plop', 'Casper.options.onAlert() can intercept an alert message');
|
35
|
+
};
|
36
|
+
});
|
37
|
+
|
38
|
+
casper.run(function() {
|
39
|
+
this.options.onAlert = null;
|
40
|
+
this.test.done();
|
41
|
+
});
|
@@ -0,0 +1,38 @@
|
|
1
|
+
casper.start('tests/site/index.html');
|
2
|
+
|
3
|
+
var oldLevel = casper.options.logLevel;
|
4
|
+
|
5
|
+
casper.options.logLevel = 'info';
|
6
|
+
casper.options.verbose = false;
|
7
|
+
|
8
|
+
casper.test.comment('Casper.log()');
|
9
|
+
casper.log('foo', 'info');
|
10
|
+
casper.test.assert(casper.result.log.some(function(e) {
|
11
|
+
return e.message === 'foo' && e.level === 'info';
|
12
|
+
}), 'Casper.log() adds a log entry');
|
13
|
+
|
14
|
+
casper.options.logLevel = oldLevel;
|
15
|
+
casper.options.verbose = true;
|
16
|
+
|
17
|
+
casper.then(function() {
|
18
|
+
var oldLevel = casper.options.logLevel;
|
19
|
+
casper.options.logLevel = 'debug';
|
20
|
+
casper.options.verbose = false;
|
21
|
+
casper.evaluate(function() {
|
22
|
+
__utils__.log('debug message');
|
23
|
+
__utils__.log('info message', 'info');
|
24
|
+
});
|
25
|
+
this.test.assert(casper.result.log.some(function(e) {
|
26
|
+
return e.message === 'debug message' && e.level === 'debug' && e.space === 'remote';
|
27
|
+
}), 'ClientUtils.log() adds a log entry');
|
28
|
+
this.test.assert(casper.result.log.some(function(e) {
|
29
|
+
return e.message === 'info message' && e.level === 'info' && e.space === 'remote';
|
30
|
+
}), 'ClientUtils.log() adds a log entry at a given level');
|
31
|
+
casper.options.logLevel = oldLevel;
|
32
|
+
casper.options.verbose = true;
|
33
|
+
});
|
34
|
+
|
35
|
+
casper.run(function() {
|
36
|
+
this.test.assertEquals(this.result.log.length, 3, 'Casper.log() logged messages');
|
37
|
+
this.test.done();
|
38
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
casper.start('tests/site/mouse-events.html');
|
2
|
+
|
3
|
+
casper.then(function() {
|
4
|
+
this.test.comment('CasperUtils.mouseEvent()');
|
5
|
+
this.test.assert(this.mouseEvent('mousedown', '#test1'), 'CasperUtils.mouseEvent() can dispatch a mousedown event');
|
6
|
+
this.test.assert(this.mouseEvent('mousedown', '#test2'), 'CasperUtils.mouseEvent() can dispatch a mousedown event handled by unobstrusive js');
|
7
|
+
this.test.assert(this.mouseEvent('mouseup', '#test3'), 'CasperUtils.mouseEvent() can dispatch a mouseup event');
|
8
|
+
this.test.assert(this.mouseEvent('mouseup', '#test4'), 'CasperUtils.mouseEvent() can dispatch a mouseup event handled by unobstrusive js');
|
9
|
+
this.test.assert(this.mouseEvent('mouseover', '#test5'), 'CasperUtils.mouseEvent() can dispatch a mouseover event');
|
10
|
+
this.test.assert(this.mouseEvent('mouseover', '#test6'), 'CasperUtils.mouseEvent() can dispatch a mouseover event handled by unobstrusive js');
|
11
|
+
this.test.assert(this.mouseEvent('mouseout', '#test7'), 'CasperUtils.mouseEvent() can dispatch a mouseout event');
|
12
|
+
this.test.assert(this.mouseEvent('mouseout', '#test8'), 'CasperUtils.mouseEvent() can dispatch a mouseout event handled by unobstrusive js');
|
13
|
+
|
14
|
+
var results = this.getGlobal('results');
|
15
|
+
this.test.assert(results.test1, 'CasperUtils.mouseEvent() triggered mousedown');
|
16
|
+
this.test.assert(results.test2, 'CasperUtils.mouseEvent() triggered mousedown via unobstrusive js');
|
17
|
+
this.test.assert(results.test3, 'CasperUtils.mouseEvent() triggered mouseup');
|
18
|
+
this.test.assert(results.test4, 'CasperUtils.mouseEvent() triggered mouseup via unobstrusive js');
|
19
|
+
this.test.assert(results.test5, 'CasperUtils.mouseEvent() triggered mouseover');
|
20
|
+
this.test.assert(results.test6, 'CasperUtils.mouseEvent() triggered mouseover via unobstrusive js');
|
21
|
+
this.test.assert(results.test7, 'CasperUtils.mouseEvent() triggered mouseout');
|
22
|
+
this.test.assert(results.test8, 'CasperUtils.mouseEvent() triggered mouseout via unobstrusive js');
|
23
|
+
});
|
24
|
+
|
25
|
+
casper.run(function() {
|
26
|
+
this.test.done();
|
27
|
+
});
|
@@ -0,0 +1,19 @@
|
|
1
|
+
casper.test.comment("page.error event");
|
2
|
+
|
3
|
+
var error = {};
|
4
|
+
|
5
|
+
casper.start();
|
6
|
+
|
7
|
+
casper.on("page.error", function onError(msg, trace) {
|
8
|
+
error.msg = msg;
|
9
|
+
error.trace = trace;
|
10
|
+
});
|
11
|
+
|
12
|
+
casper.thenOpen('tests/site/error.html', function() {
|
13
|
+
this.test.assertEquals(error.msg, "ReferenceError: Can't find variable: plop", 'page.error event has been caught OK');
|
14
|
+
this.test.assertMatch(error.trace[0].file, /error.html/, 'page.error retrieves correct stack trace');
|
15
|
+
});
|
16
|
+
|
17
|
+
casper.run(function() {
|
18
|
+
this.test.done();
|
19
|
+
});
|
@@ -0,0 +1,73 @@
|
|
1
|
+
var t = casper.test, current = 0, tests = [
|
2
|
+
function(settings) {
|
3
|
+
t.assertEquals(settings, {
|
4
|
+
method: "get"
|
5
|
+
}, "Casper.open() used the expected GET settings");
|
6
|
+
},
|
7
|
+
function(settings) {
|
8
|
+
t.assertEquals(settings, {
|
9
|
+
method: "post",
|
10
|
+
data: "plop=42&chuck=norris"
|
11
|
+
}, "Casper.open() used the expected POST settings");
|
12
|
+
},
|
13
|
+
function(settings) {
|
14
|
+
t.assertEquals(settings, {
|
15
|
+
method: "put",
|
16
|
+
data: "plop=42&chuck=norris"
|
17
|
+
}, "Casper.open() used the expected PUT settings");
|
18
|
+
},
|
19
|
+
function(settings) {
|
20
|
+
t.assertEquals(settings, {
|
21
|
+
method: "get",
|
22
|
+
username: 'bob',
|
23
|
+
password: 'sinclar'
|
24
|
+
}, "Casper.open() used the expected HTTP auth settings");
|
25
|
+
}
|
26
|
+
];
|
27
|
+
|
28
|
+
casper.start();
|
29
|
+
|
30
|
+
casper.on('open', function(url, settings) {
|
31
|
+
tests[current++](settings);
|
32
|
+
});
|
33
|
+
|
34
|
+
// GET
|
35
|
+
casper.open('tests/site/index.html').then(function() {
|
36
|
+
t.pass("Casper.open() can open and load a location using GET");
|
37
|
+
});
|
38
|
+
|
39
|
+
// POST
|
40
|
+
casper.open('tests/site/index.html', {
|
41
|
+
method: 'post',
|
42
|
+
data: {
|
43
|
+
plop: 42,
|
44
|
+
chuck: 'norris'
|
45
|
+
}
|
46
|
+
}).then(function() {
|
47
|
+
t.pass("Casper.open() can open and load a location using POST");
|
48
|
+
});
|
49
|
+
|
50
|
+
// PUT
|
51
|
+
casper.open('tests/site/index.html', {
|
52
|
+
method: 'put',
|
53
|
+
data: {
|
54
|
+
plop: 42,
|
55
|
+
chuck: 'norris'
|
56
|
+
}
|
57
|
+
}).then(function() {
|
58
|
+
t.pass("Casper.open() can open and load a location using PUT");
|
59
|
+
});
|
60
|
+
|
61
|
+
// HTTP Auth
|
62
|
+
casper.open('tests/site/index.html', {
|
63
|
+
method: 'get',
|
64
|
+
username: 'bob',
|
65
|
+
password: 'sinclar'
|
66
|
+
}).then(function() {
|
67
|
+
t.pass("Casper.open() can open and load a location using HTTP auth");
|
68
|
+
});
|
69
|
+
|
70
|
+
casper.run(function() {
|
71
|
+
this.removeAllListeners('open');
|
72
|
+
t.done();
|
73
|
+
});
|
@@ -0,0 +1,17 @@
|
|
1
|
+
// skip this test for phantom versions < 1.5
|
2
|
+
if (phantom.version.major === 1 && phantom.version.minor < 6) {
|
3
|
+
casper.test.comment('Skipped tests, PhantomJS 1.6 required');
|
4
|
+
casper.test.done();
|
5
|
+
} else {
|
6
|
+
casper.setFilter('page.prompt', function(message, value) {
|
7
|
+
return 'Chuck ' + value;
|
8
|
+
});
|
9
|
+
|
10
|
+
casper.start('tests/site/prompt.html', function() {
|
11
|
+
this.test.assertEquals(this.getGlobal('name'), 'Chuck Norris', 'prompted value has been received');
|
12
|
+
});
|
13
|
+
|
14
|
+
casper.run(function() {
|
15
|
+
this.test.done();
|
16
|
+
});
|
17
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
casper.start "tests/site/resources.html", ->
|
2
|
+
@test.assertEquals @resources.length, 1, "only one resource found"
|
3
|
+
onTime = ->
|
4
|
+
@test.assertEquals(
|
5
|
+
@resources.length
|
6
|
+
2
|
7
|
+
"two resources found"
|
8
|
+
)
|
9
|
+
@test.assertResourceExists(
|
10
|
+
/phantom\.png/i
|
11
|
+
"phantom image found via test RegExp"
|
12
|
+
)
|
13
|
+
@test.assertResourceExists(
|
14
|
+
(res) -> res.url.match "phantom.png"
|
15
|
+
"phantom image found via test Function"
|
16
|
+
)
|
17
|
+
@test.assertResourceExists(
|
18
|
+
"phantom.png"
|
19
|
+
"phantom image found via test String"
|
20
|
+
)
|
21
|
+
onTimeout = -> @test.fail "waitForResource timeout occured"
|
22
|
+
@waitForResource "phantom.png", onTime, onTimeout
|
23
|
+
|
24
|
+
casper.run(-> @test.done())
|
@@ -0,0 +1,15 @@
|
|
1
|
+
casper.test.comment('Casper.start()');
|
2
|
+
|
3
|
+
casper.start('tests/site/index.html', function() {
|
4
|
+
this.test.pass('Casper.start() can chain a next step');
|
5
|
+
this.test.assertTitle('CasperJS test index', 'Casper.start() opened the passed url');
|
6
|
+
this.test.assertEval(function() {
|
7
|
+
return typeof(__utils__) === "object";
|
8
|
+
}, 'Casper.start() injects ClientUtils instance within remote DOM');
|
9
|
+
});
|
10
|
+
|
11
|
+
casper.test.assert(casper.started, 'Casper.start() started');
|
12
|
+
|
13
|
+
casper.run(function() {
|
14
|
+
this.test.done();
|
15
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
casper.test.comment('Casper.then()');
|
2
|
+
|
3
|
+
casper.start('tests/site/index.html');
|
4
|
+
|
5
|
+
var nsteps = casper.steps.length;
|
6
|
+
|
7
|
+
casper.then(function(self) {
|
8
|
+
this.test.assertTitle('CasperJS test index', 'Casper.then() added a new step');
|
9
|
+
});
|
10
|
+
|
11
|
+
casper.test.assertEquals(casper.steps.length, nsteps + 1, 'Casper.then() can add a new step');
|
12
|
+
|
13
|
+
casper.test.comment('Casper.thenOpen()');
|
14
|
+
|
15
|
+
casper.thenOpen('tests/site/test.html');
|
16
|
+
|
17
|
+
casper.test.assertEquals(casper.steps.length, nsteps + 2, 'Casper.thenOpen() can add a new step');
|
18
|
+
|
19
|
+
casper.thenOpen('tests/site/test.html', function() {
|
20
|
+
this.test.assertTitle('CasperJS test target', 'Casper.thenOpen() opened a location and executed a step');
|
21
|
+
});
|
22
|
+
|
23
|
+
casper.test.assertEquals(casper.steps.length, nsteps + 4, 'Casper.thenOpen() can add a new step for opening, plus another step');
|
24
|
+
|
25
|
+
casper.test.comment('Casper.each()');
|
26
|
+
casper.each([1, 2, 3], function(self, item, i) {
|
27
|
+
self.test.assertEquals(i, item - 1, 'Casper.each() passes a contextualized index');
|
28
|
+
});
|
29
|
+
|
30
|
+
casper.run(function() {
|
31
|
+
this.test.done();
|
32
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
casper.test.comment('Casper.viewport()');
|
2
|
+
|
3
|
+
casper.start();
|
4
|
+
|
5
|
+
casper.viewport(1337, 999);
|
6
|
+
|
7
|
+
casper.test.assertEquals(casper.page.viewportSize.width, 1337, 'Casper.viewport() can change the width of page viewport');
|
8
|
+
casper.test.assertEquals(casper.page.viewportSize.height, 999, 'Casper.viewport() can change the height of page viewport');
|
9
|
+
casper.test.assertRaises(casper.viewport, ['a', 'b'], 'Casper.viewport() validates viewport size data');
|
10
|
+
|
11
|
+
casper.test.done();
|
@@ -0,0 +1,17 @@
|
|
1
|
+
casper.start('tests/site/visible.html', function() {
|
2
|
+
this.test.comment('Casper.visible()');
|
3
|
+
this.test.assert(this.visible('#img1'), 'Casper.visible() can detect if an element is visible');
|
4
|
+
this.test.assert(!this.visible('#img2'), 'Casper.visible() can detect if an element is invisible');
|
5
|
+
this.test.assert(!this.visible('#img3'), 'Casper.visible() can detect if an element is invisible');
|
6
|
+
this.waitWhileVisible('#img1', function() {
|
7
|
+
this.test.comment('Casper.waitWhileVisible()');
|
8
|
+
this.test.pass('Casper.waitWhileVisible() can wait while an element is visible');
|
9
|
+
}, function() {
|
10
|
+
this.test.comment('Casper.waitWhileVisible()');
|
11
|
+
this.test.fail('Casper.waitWhileVisible() can wait while an element is visible');
|
12
|
+
}, 2000);
|
13
|
+
});
|
14
|
+
|
15
|
+
casper.run(function() {
|
16
|
+
this.test.done();
|
17
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
var waitStart;
|
2
|
+
|
3
|
+
casper.start('tests/site/index.html', function() {
|
4
|
+
waitStart = new Date().getTime();
|
5
|
+
});
|
6
|
+
|
7
|
+
casper.wait(1000, function() {
|
8
|
+
this.test.comment('Casper.wait()');
|
9
|
+
this.test.assert(new Date().getTime() - waitStart > 1000, 'Casper.wait() can wait for a given amount of time');
|
10
|
+
// Casper.waitFor()
|
11
|
+
casper.thenOpen('tests/site/waitFor.html', function() {
|
12
|
+
this.test.comment('Casper.waitFor()');
|
13
|
+
this.waitFor(function() {
|
14
|
+
return this.evaluate(function() {
|
15
|
+
return document.querySelectorAll('li').length === 4;
|
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');
|
21
|
+
});
|
22
|
+
});
|
23
|
+
});
|
24
|
+
|
25
|
+
casper.run(function() {
|
26
|
+
this.test.done();
|
27
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
var x = require('casper').selectXPath;
|
2
|
+
|
3
|
+
casper.test.comment('XPath');
|
4
|
+
|
5
|
+
casper.start('tests/site/index.html', function() {
|
6
|
+
this.test.assertExists({
|
7
|
+
type: 'xpath',
|
8
|
+
path: '/html/body/ul/li[2]'
|
9
|
+
}, 'XPath selector can find an element');
|
10
|
+
this.test.assertDoesntExist({
|
11
|
+
type: 'xpath',
|
12
|
+
path: '/html/body/ol/li[2]'
|
13
|
+
}, 'XPath selector does not retrieve an unexistent element');
|
14
|
+
this.test.assertExists(x('/html/body/ul/li[2]'), 'selectXPath() shortcut can find an element as well');
|
15
|
+
this.test.assertEvalEquals(function() {
|
16
|
+
return __utils__.findAll({type: 'xpath', path: '/html/body/ul/li'}).length;
|
17
|
+
}, 3, 'Correct number of elements are found');
|
18
|
+
});
|
19
|
+
|
20
|
+
casper.thenClick(x('/html/body/a[2]'), function() {
|
21
|
+
this.test.assertTitle('CasperJS test form', 'Clicking XPath works as expected');
|
22
|
+
this.fill(x('/html/body/form'), {
|
23
|
+
email: 'chuck@norris.com'
|
24
|
+
});
|
25
|
+
this.test.assertEvalEquals(function() {
|
26
|
+
return document.querySelector('input[name="email"]').value;
|
27
|
+
}, 'chuck@norris.com', 'Casper.fill() can fill an input[type=text] form field');
|
28
|
+
});
|
29
|
+
|
30
|
+
casper.run(function() {
|
31
|
+
this.test.done();
|
32
|
+
});
|
data/tests/suites/cli.js
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
var cli = require('cli'), t = casper.test;
|
2
|
+
|
3
|
+
t.comment('parse(), get(), has()');
|
4
|
+
|
5
|
+
(function(parsed) {
|
6
|
+
// clean
|
7
|
+
t.assertEquals(parsed.args, [], 'parse() returns expected positional args array');
|
8
|
+
t.assertEquals(parsed.options, {}, 'parse() returns expected options object');
|
9
|
+
t.assertEquals(parsed.get(0), undefined, 'parse() does not return inexistant positional arg');
|
10
|
+
t.assertEquals(parsed.get('blah'), undefined, 'parse() does not return inexistant option');
|
11
|
+
t.assert(!parsed.has(0), 'has() checks if an arg is set');
|
12
|
+
t.assert(!parsed.has('blah'), 'has() checks if an option is set');
|
13
|
+
// raw
|
14
|
+
t.assertEquals(parsed.raw.args, [], 'parse() returns expected positional args array');
|
15
|
+
t.assertEquals(parsed.raw.options, {}, 'parse() returns expected options object');
|
16
|
+
t.assertEquals(parsed.raw.get(0), undefined, 'parse() does not return inexistant positional arg');
|
17
|
+
t.assertEquals(parsed.raw.get('blah'), undefined, 'parse() does not return inexistant option');
|
18
|
+
t.assert(!parsed.raw.has(0), 'has() checks if a raw arg is set');
|
19
|
+
t.assert(!parsed.raw.has('blah'), 'has() checks if a raw option is set');
|
20
|
+
})(cli.parse([]));
|
21
|
+
|
22
|
+
(function(parsed) {
|
23
|
+
// clean
|
24
|
+
t.assertEquals(parsed.args, ['foo', 'bar'], 'parse() returns expected positional args array');
|
25
|
+
t.assertEquals(parsed.options, {}, 'parse() returns expected options object');
|
26
|
+
t.assertEquals(parsed.get(0), 'foo', 'parse() retrieve first positional arg');
|
27
|
+
t.assertEquals(parsed.get(1), 'bar', 'parse() retrieve second positional arg');
|
28
|
+
t.assert(parsed.has(0), 'has() checks if an arg is set');
|
29
|
+
t.assert(parsed.has(1), 'has() checks if an arg is set');
|
30
|
+
t.assert(!parsed.has(2), 'has() checks if an arg is not set');
|
31
|
+
// raw
|
32
|
+
t.assertEquals(parsed.raw.args, ['foo', 'bar'], 'parse() returns expected positional raw args array');
|
33
|
+
t.assertEquals(parsed.raw.options, {}, 'parse() returns expected raw options object');
|
34
|
+
t.assertEquals(parsed.raw.get(0), 'foo', 'parse() retrieve first positional raw arg');
|
35
|
+
t.assertEquals(parsed.raw.get(1), 'bar', 'parse() retrieve second positional raw arg');
|
36
|
+
t.assert(parsed.raw.has(0), 'has() checks if a arw arg is set');
|
37
|
+
t.assert(parsed.raw.has(1), 'has() checks if a arw arg is set');
|
38
|
+
t.assert(!parsed.raw.has(2), 'has() checks if a arw arg is not set');
|
39
|
+
})(cli.parse(['foo', 'bar']));
|
40
|
+
|
41
|
+
(function(parsed) {
|
42
|
+
// clean
|
43
|
+
t.assertEquals(parsed.args, [], 'parse() returns expected positional args array');
|
44
|
+
t.assertEquals(parsed.options, {foo: 'bar', baz: true}, 'parse() returns expected options object');
|
45
|
+
t.assertEquals(parsed.get('foo'), 'bar', 'parse() retrieve an option value');
|
46
|
+
t.assert(parsed.get('baz'), 'parse() retrieve boolean option flag');
|
47
|
+
t.assert(parsed.has("foo"), 'has() checks if an option is set');
|
48
|
+
t.assert(parsed.has("baz"), 'has() checks if an option is set');
|
49
|
+
// raw
|
50
|
+
t.assertEquals(parsed.raw.args, [], 'parse() returns expected positional raw args array');
|
51
|
+
t.assertEquals(parsed.raw.options, {foo: 'bar', baz: true}, 'parse() returns expected options raw object');
|
52
|
+
t.assertEquals(parsed.raw.get('foo'), 'bar', 'parse() retrieve an option raw value');
|
53
|
+
t.assert(parsed.raw.get('baz'), 'parse() retrieve boolean raw option flag');
|
54
|
+
t.assert(parsed.raw.has("foo"), 'has() checks if a raw option is set');
|
55
|
+
t.assert(parsed.raw.has("baz"), 'has() checks if a raw option is set');
|
56
|
+
})(cli.parse(['--foo=bar', '--baz']));
|
57
|
+
|
58
|
+
(function(parsed) {
|
59
|
+
// clean
|
60
|
+
t.assertEquals(parsed.args, [], 'parse() returns expected positional args array');
|
61
|
+
t.assertEquals(parsed.options, { '&é"à': "42===42" }, 'parse() returns expected options object');
|
62
|
+
t.assertEquals(parsed.get('&é"à'), "42===42", 'parse() handles options with exotic names');
|
63
|
+
t.assert(parsed.has('&é"à'), 'has() checks if an option is set');
|
64
|
+
// raw
|
65
|
+
t.assertEquals(parsed.raw.args, [], 'parse() returns expected positional raw args array');
|
66
|
+
t.assertEquals(parsed.raw.options, { '&é"à': "42===42" }, 'parse() returns expected options raw object');
|
67
|
+
t.assertEquals(parsed.raw.get('&é"à'), "42===42", 'parse() handles raw options with exotic names');
|
68
|
+
t.assert(parsed.raw.has('&é"à'), 'has() checks if a raw option is set');
|
69
|
+
})(cli.parse(['--&é"à=42===42']));
|
70
|
+
|
71
|
+
(function(parsed) {
|
72
|
+
// clean
|
73
|
+
t.assertEquals(parsed.args, ['foo & bar', 'baz & boz'], 'parse() returns expected positional args array');
|
74
|
+
t.assertEquals(parsed.options, { universe: 42, lap: 13.37, chucknorris: true, oops: false }, 'parse() returns expected options object');
|
75
|
+
t.assertEquals(parsed.get('universe'), 42, 'parse() can cast a numeric option value');
|
76
|
+
t.assertEquals(parsed.get('lap'), 13.37, 'parse() can cast a float option value');
|
77
|
+
t.assertType(parsed.get('lap'), "number", 'parse() can cast a boolean value');
|
78
|
+
t.assert(parsed.get('chucknorris'), 'parse() can get a flag value by its option name');
|
79
|
+
t.assertType(parsed.get('oops'), "boolean", 'parse() can cast a boolean value');
|
80
|
+
t.assertEquals(parsed.get('oops'), false, 'parse() can cast a boolean value');
|
81
|
+
t.assert(parsed.has(0), 'has() checks if an arg is set');
|
82
|
+
t.assert(parsed.has(1), 'has() checks if an arg is set');
|
83
|
+
t.assert(parsed.has("universe"), 'has() checks if an option is set');
|
84
|
+
t.assert(parsed.has("lap"), 'has() checks if an option is set');
|
85
|
+
t.assert(parsed.has("chucknorris"), 'has() checks if an option is set');
|
86
|
+
t.assert(parsed.has("oops"), 'has() checks if an option is set');
|
87
|
+
|
88
|
+
t.comment('drop()');
|
89
|
+
|
90
|
+
parsed.drop(0);
|
91
|
+
t.assertEquals(parsed.get(0), 'baz & boz', 'drop() dropped arg');
|
92
|
+
parsed.drop("universe");
|
93
|
+
t.assert(!parsed.has("universe"), 'drop() dropped option');
|
94
|
+
t.assertEquals(parsed.args, ["baz & boz"], 'drop() did not affect other args');
|
95
|
+
t.assertEquals(parsed.options, {
|
96
|
+
lap: 13.37,
|
97
|
+
chucknorris: true,
|
98
|
+
oops: false
|
99
|
+
}, 'drop() did not affect other options');
|
100
|
+
|
101
|
+
// raw
|
102
|
+
t.assertEquals(parsed.raw.args, ['foo & bar', 'baz & boz'], 'parse() returns expected positional raw args array');
|
103
|
+
t.assertEquals(parsed.raw.options, { universe: "42", lap: "13.37", chucknorris: true, oops: "false" }, 'parse() returns expected options raw object');
|
104
|
+
t.assertEquals(parsed.raw.get('universe'), "42", 'parse() does not a raw numeric option value');
|
105
|
+
t.assertEquals(parsed.raw.get('lap'), "13.37", 'parse() does not cast a raw float option value');
|
106
|
+
t.assertType(parsed.raw.get('lap'), "string", 'parse() does not cast a numeric value');
|
107
|
+
t.assert(parsed.raw.get('chucknorris'), 'parse() can get a flag value by its option name');
|
108
|
+
t.assertType(parsed.raw.get('oops'), "string", 'parse() can cast a boolean value');
|
109
|
+
t.assertEquals(parsed.raw.get('oops'), "false", 'parse() can cast a boolean value');
|
110
|
+
|
111
|
+
t.comment('drop() for raw');
|
112
|
+
|
113
|
+
parsed.raw.drop(0);
|
114
|
+
t.assertEquals(parsed.raw.get(0), 'baz & boz', 'drop() dropped raw arg');
|
115
|
+
parsed.raw.drop("universe");
|
116
|
+
t.assert(!parsed.raw.has("universe"), 'drop() dropped raw option');
|
117
|
+
t.assertEquals(parsed.raw.args, ["baz & boz"], 'drop() did not affect other raw args');
|
118
|
+
t.assertEquals(parsed.raw.options, {
|
119
|
+
lap: "13.37",
|
120
|
+
chucknorris: true,
|
121
|
+
oops: "false"
|
122
|
+
}, 'drop() did not affect other raw options');
|
123
|
+
})(cli.parse(['foo & bar', 'baz & boz', '--universe=42', '--lap=13.37', '--chucknorris', '--oops=false']));
|
124
|
+
|
125
|
+
t.done();
|