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,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
|
+
<script>
|
7
|
+
setTimeout(function() {
|
8
|
+
document.querySelector('#img1').style.display = 'none';
|
9
|
+
}, 1000);
|
10
|
+
</script>
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<img src="images/phantom.png" id="img1">
|
14
|
+
<img src="images/phantom.png" id="img2" style="display:none">
|
15
|
+
<img src="images/phantom.png" id="img3" style="visibility:hidden">
|
16
|
+
</body>
|
17
|
+
</html>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
5
|
+
<title>waitFor test</title>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<img src="images/phantom.png"/>
|
9
|
+
<ul>
|
10
|
+
<li>one</li>
|
11
|
+
<li>two</li>
|
12
|
+
<li>three</li>
|
13
|
+
</ul>
|
14
|
+
<script>
|
15
|
+
setTimeout(function() {
|
16
|
+
var li = document.createElement('li')
|
17
|
+
li.appendChild(document.createTextNode('four'));
|
18
|
+
document.querySelector('ul').appendChild(li);
|
19
|
+
}, 2000);
|
20
|
+
</script>
|
21
|
+
</body>
|
22
|
+
</html>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
function testUA(ua, match) {
|
2
|
+
casper.test.assertMatch(
|
3
|
+
ua, match, 'Default user agent matches ' + match
|
4
|
+
);
|
5
|
+
}
|
6
|
+
|
7
|
+
function fetchUA(request) {
|
8
|
+
testUA(request.headers.filter(function(header) {
|
9
|
+
return header.name === "User-Agent";
|
10
|
+
}).pop().value, /plop/);
|
11
|
+
}
|
12
|
+
|
13
|
+
testUA(casper.options.pageSettings.userAgent, /CasperJS/);
|
14
|
+
|
15
|
+
casper.start();
|
16
|
+
|
17
|
+
casper.userAgent('plop').on('resource.requested', fetchUA);
|
18
|
+
|
19
|
+
casper.thenOpen('tests/site/index.html');
|
20
|
+
|
21
|
+
casper.run(function() {
|
22
|
+
this.removeListener('resource.requested', fetchUA);
|
23
|
+
this.test.done();
|
24
|
+
});
|
@@ -0,0 +1,31 @@
|
|
1
|
+
var fs = require('fs'), testFile = '/tmp/__casper_test_capture.png';
|
2
|
+
|
3
|
+
if (fs.exists(testFile) && fs.isFile(testFile)) {
|
4
|
+
fs.remove(testFile);
|
5
|
+
}
|
6
|
+
|
7
|
+
casper.start('tests/site/index.html', function() {
|
8
|
+
this.viewport(300, 200);
|
9
|
+
this.test.comment('Casper.capture()');
|
10
|
+
this.capture(testFile);
|
11
|
+
this.test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot');
|
12
|
+
});
|
13
|
+
|
14
|
+
if (phantom.version.major === 1 && phantom.version.minor >= 6) {
|
15
|
+
casper.thenOpen('tests/site/index.html', function() {
|
16
|
+
this.test.comment('Casper.captureBase64()');
|
17
|
+
this.test.assert(this.captureBase64('png').length > 0,
|
18
|
+
'Casper.captureBase64() rendered a page capture as base64');
|
19
|
+
this.test.assert(this.captureBase64('png', 'ul').length > 0,
|
20
|
+
'Casper.captureBase64() rendered a capture from a selector as base64');
|
21
|
+
this.test.assert(this.captureBase64('png', {top: 0, left: 0, width: 30, height: 30}).length > 0,
|
22
|
+
'Casper.captureBase64() rendered a capture from a clipRect as base64');
|
23
|
+
});
|
24
|
+
}
|
25
|
+
|
26
|
+
casper.run(function() {
|
27
|
+
try {
|
28
|
+
fs.remove(testFile);
|
29
|
+
} catch(e) {}
|
30
|
+
this.test.done();
|
31
|
+
});
|
@@ -0,0 +1,61 @@
|
|
1
|
+
casper.start('tests/site/index.html', function() {
|
2
|
+
this.click('a[href="test.html"]');
|
3
|
+
});
|
4
|
+
|
5
|
+
casper.then(function() {
|
6
|
+
this.test.comment('Casper.click()');
|
7
|
+
this.test.assertTitle('CasperJS test target', 'Casper.click() can click on a link');
|
8
|
+
}).thenClick('a', function() {
|
9
|
+
this.test.comment('Casper.thenClick()');
|
10
|
+
this.test.assertTitle('CasperJS test form', 'Casper.thenClick() can click on a link');
|
11
|
+
});
|
12
|
+
|
13
|
+
// onclick variants tests
|
14
|
+
casper.thenOpen('tests/site/click.html', function() {
|
15
|
+
this.test.comment('Casper.click()');
|
16
|
+
this.test.assert(this.click('#test1'), 'Casper.click() can click an `href="javascript:` link');
|
17
|
+
this.test.assert(this.click('#test2'), 'Casper.click() can click an `href="#"` link');
|
18
|
+
this.test.assert(this.click('#test3'), 'Casper.click() can click an `onclick=".*; return false"` link');
|
19
|
+
this.test.assert(this.click('#test4'), 'Casper.click() can click an unobstrusive js handled link');
|
20
|
+
var results = this.getGlobal('results');
|
21
|
+
this.test.assert(results.test1, 'Casper.click() has clicked an `href="javascript:` link');
|
22
|
+
this.test.assert(results.test2, 'Casper.click() has clicked an `href="#"` link');
|
23
|
+
this.test.assert(results.test3, 'Casper.click() has clicked an `onclick=".*; return false"` link');
|
24
|
+
this.test.assert(results.test4, 'Casper.click() has clicked an unobstrusive js handled link');
|
25
|
+
});
|
26
|
+
|
27
|
+
// clickLabel tests
|
28
|
+
casper.thenOpen('tests/site/click.html', function() {
|
29
|
+
this.test.comment('Casper.clickLabel()');
|
30
|
+
this.test.assert(this.clickLabel('test1'), 'Casper.clickLabel() can click an `href="javascript:` link');
|
31
|
+
this.test.assert(this.clickLabel('test2'), 'Casper.clickLabel() can click an `href="#"` link');
|
32
|
+
this.test.assert(this.clickLabel('test3'), 'Casper.clickLabel() can click an `onclick=".*; return false"` link');
|
33
|
+
this.test.assert(this.clickLabel('test4'), 'Casper.clickLabel() can click an unobstrusive js handled link');
|
34
|
+
var results = this.getGlobal('results');
|
35
|
+
this.test.assert(results.test1, 'Casper.clickLabel() has clicked an `href="javascript:` link');
|
36
|
+
this.test.assert(results.test2, 'Casper.clickLabel() has clicked an `href="#"` link');
|
37
|
+
this.test.assert(results.test3, 'Casper.clickLabel() has clicked an `onclick=".*; return false"` link');
|
38
|
+
this.test.assert(results.test4, 'Casper.clickLabel() has clicked an unobstrusive js handled link');
|
39
|
+
});
|
40
|
+
|
41
|
+
// casper.mouse
|
42
|
+
casper.then(function() {
|
43
|
+
this.test.comment('Mouse.down()');
|
44
|
+
this.mouse.down(200, 100);
|
45
|
+
var results = this.getGlobal('results');
|
46
|
+
this.test.assertEquals(results.testdown, [200, 100], 'Mouse.down() has pressed button to the specified position');
|
47
|
+
|
48
|
+
this.test.comment('Mouse.up()');
|
49
|
+
this.mouse.up(200, 100);
|
50
|
+
results = this.getGlobal('results');
|
51
|
+
this.test.assertEquals(results.testup, [200, 100], 'Mouse.up() has released button to the specified position');
|
52
|
+
|
53
|
+
this.test.comment('Mouse.move()');
|
54
|
+
this.mouse.move(200, 100);
|
55
|
+
results = this.getGlobal('results');
|
56
|
+
this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position');
|
57
|
+
});
|
58
|
+
|
59
|
+
casper.run(function() {
|
60
|
+
this.test.done();
|
61
|
+
});
|
@@ -0,0 +1,21 @@
|
|
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
|
+
var received;
|
7
|
+
|
8
|
+
casper.setFilter('page.confirm', function(message) {
|
9
|
+
received = message;
|
10
|
+
return true;
|
11
|
+
});
|
12
|
+
|
13
|
+
casper.start('tests/site/confirm.html', function() {
|
14
|
+
this.test.assert(this.getGlobal('confirmed'), 'confirmation received');
|
15
|
+
});
|
16
|
+
|
17
|
+
casper.run(function() {
|
18
|
+
this.test.assertEquals(received, 'are you sure?', 'confirmation message is ok');
|
19
|
+
this.test.done();
|
20
|
+
});
|
21
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
casper.start('tests/site/elementattribute.html', function() {
|
2
|
+
this.test.comment('Casper.getElementAttribute()');
|
3
|
+
this.test.assertEquals(this.getElementAttribute('.testo','data-stuff'), 'beautiful string', 'Casper.getElementAttribute() works as intended');
|
4
|
+
});
|
5
|
+
|
6
|
+
casper.run(function() {
|
7
|
+
this.test.done();
|
8
|
+
});
|
@@ -0,0 +1,20 @@
|
|
1
|
+
var fs = require('fs');
|
2
|
+
|
3
|
+
casper.start('tests/site/index.html', function() {
|
4
|
+
var imageUrl = 'file://' + phantom.casperPath + '/tests/site/images/phantom.png';
|
5
|
+
var image = this.base64encode(imageUrl);
|
6
|
+
|
7
|
+
this.test.comment('Casper.base64encode()');
|
8
|
+
this.test.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents');
|
9
|
+
|
10
|
+
this.test.comment('Casper.download()');
|
11
|
+
this.download(imageUrl, '__test_logo.png');
|
12
|
+
this.test.assert(fs.exists('__test_logo.png'), 'Casper.download() downloads a file');
|
13
|
+
if (fs.exists('__test_logo.png')) {
|
14
|
+
fs.remove('__test_logo.png');
|
15
|
+
}
|
16
|
+
});
|
17
|
+
|
18
|
+
casper.run(function() {
|
19
|
+
this.test.done();
|
20
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
casper.test.comment('Casper.evaluate()');
|
2
|
+
|
3
|
+
casper.start();
|
4
|
+
|
5
|
+
var params = {
|
6
|
+
"boolean true": true,
|
7
|
+
"boolean false": false,
|
8
|
+
"int number": 42,
|
9
|
+
"float number": 1337.42,
|
10
|
+
"string": "plop! \"Ÿ£$\" 'no'",
|
11
|
+
"array": [1, 2, 3],
|
12
|
+
"object": {a: 1, b: 2}
|
13
|
+
};
|
14
|
+
|
15
|
+
var casperParams = casper.evaluate(function() {
|
16
|
+
return __casper_params__;
|
17
|
+
}, params);
|
18
|
+
|
19
|
+
casper.test.assertType(casperParams, "object", 'Casper.evaluate() exposes parameters in a dedicated object');
|
20
|
+
casper.test.assertEquals(Object.keys(casperParams).length, 7, 'Casper.evaluate() object containing parameters has the correct length');
|
21
|
+
|
22
|
+
for (var param in casperParams) {
|
23
|
+
casper.test.assertEquals(JSON.stringify(casperParams[param]), JSON.stringify(params[param]), 'Casper.evaluate() can pass a ' + param);
|
24
|
+
casper.test.assertEquals(typeof casperParams[param], typeof params[param], 'Casper.evaluate() preserves the ' + param + ' type');
|
25
|
+
}
|
26
|
+
|
27
|
+
casper.test.done();
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// events
|
2
|
+
|
3
|
+
casper.test.comment("events");
|
4
|
+
|
5
|
+
casper.plopped = false;
|
6
|
+
|
7
|
+
casper.on("plop", function() {
|
8
|
+
this.plopped = true;
|
9
|
+
});
|
10
|
+
|
11
|
+
casper.test.assert(Object.keys(casper._events).some(function(i) {
|
12
|
+
return i === "plop";
|
13
|
+
}), "on() has set an event handler");
|
14
|
+
|
15
|
+
casper.emit("plop");
|
16
|
+
|
17
|
+
casper.test.assert(casper.plopped, "emit() emits an event");
|
18
|
+
|
19
|
+
// filters
|
20
|
+
|
21
|
+
casper.test.comment("filters");
|
22
|
+
|
23
|
+
casper.foo = 0;
|
24
|
+
casper.setFilter("test", function(a) {
|
25
|
+
this.foo = 42;
|
26
|
+
return a + 1;
|
27
|
+
});
|
28
|
+
|
29
|
+
casper.test.assert(Object.keys(casper._filters).some(function(i) {
|
30
|
+
return i === "test";
|
31
|
+
}), "setFilter() has set a filter");
|
32
|
+
|
33
|
+
casper.test.assertEquals(casper.filter("test", 1), 2, "filter() filters a value");
|
34
|
+
casper.test.assertEquals(casper.foo, 42, "filter() applies the correct context");
|
35
|
+
|
36
|
+
delete casper.foo;
|
37
|
+
|
38
|
+
casper.test.done();
|
@@ -0,0 +1,9 @@
|
|
1
|
+
casper.test.comment('Casper.exists()');
|
2
|
+
|
3
|
+
casper.start('tests/site/index.html', function() {
|
4
|
+
this.test.assert(this.exists('a') && !this.exists('chucknorriz'), 'Casper.exists() can check if an element exists');
|
5
|
+
});
|
6
|
+
|
7
|
+
casper.run(function() {
|
8
|
+
this.test.done();
|
9
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
casper.test.comment('Casper.fetchText()');
|
2
|
+
|
3
|
+
casper.start('tests/site/index.html', function() {
|
4
|
+
this.test.assertEquals(this.fetchText('ul li'), 'onetwothree', 'Casper.fetchText() can retrieve text contents');
|
5
|
+
});
|
6
|
+
|
7
|
+
casper.run(function() {
|
8
|
+
this.test.done();
|
9
|
+
});
|
@@ -0,0 +1,38 @@
|
|
1
|
+
step = 0
|
2
|
+
|
3
|
+
# testing resources
|
4
|
+
casper.start "tests/site/resources.html", ->
|
5
|
+
@test.assertEquals ++step, 1, "step 1"
|
6
|
+
@wait 400, ->
|
7
|
+
@test.assertEquals ++step, 2, "step 1.1"
|
8
|
+
@wait 200, ->
|
9
|
+
@test.assertEquals ++step, 3, "step 1.1.1"
|
10
|
+
@wait 200, ->
|
11
|
+
@test.assertEquals ++step, 4, "step 1.1.1.1"
|
12
|
+
@then ->
|
13
|
+
@test.assertEquals ++step, 5, "step 1.1.2.1"
|
14
|
+
@wait 400, ->
|
15
|
+
@test.assertEquals ++step, 6, "step 1.2"
|
16
|
+
|
17
|
+
casper.wait 200, ->
|
18
|
+
@test.assertEquals ++step, 7, "step 2"
|
19
|
+
|
20
|
+
casper.waitForSelector(
|
21
|
+
'#noneExistingSelector'
|
22
|
+
-> @test.fail "should run into timeout"
|
23
|
+
-> @test.assertEquals ++step, 8, "step 3 sucessfully timed out"
|
24
|
+
1000
|
25
|
+
)
|
26
|
+
casper.then ->
|
27
|
+
@test.assertEquals ++step, 9, "step 4"
|
28
|
+
@wait 300, ->
|
29
|
+
@test.assertEquals ++step, 10, "step 4.1"
|
30
|
+
@wait 300, ->
|
31
|
+
@test.assertEquals ++step, 11, "step 4.1.1"
|
32
|
+
@wait 100, ->
|
33
|
+
@test.assertEquals ++step, 12, "step 5.2"
|
34
|
+
|
35
|
+
casper.then ->
|
36
|
+
@test.assertEquals ++step, 13, "last step"
|
37
|
+
|
38
|
+
casper.run(-> @test.done())
|
@@ -0,0 +1,69 @@
|
|
1
|
+
casper.start('tests/site/form.html', function() {
|
2
|
+
this.test.comment('Casper.fill()');
|
3
|
+
this.fill('form[action="result.html"]', {
|
4
|
+
email: 'chuck@norris.com',
|
5
|
+
password: 'chuck',
|
6
|
+
content: 'Am watching thou',
|
7
|
+
check: true,
|
8
|
+
choice: 'no',
|
9
|
+
topic: 'bar',
|
10
|
+
file: phantom.libraryPath + '/README.md',
|
11
|
+
'checklist[]': ['1', '3']
|
12
|
+
});
|
13
|
+
this.test.assertEvalEquals(function() {
|
14
|
+
return document.querySelector('input[name="email"]').value;
|
15
|
+
}, 'chuck@norris.com', 'Casper.fill() can fill an input[type=text] form field');
|
16
|
+
this.test.assertEvalEquals(function() {
|
17
|
+
return document.querySelector('input[name="password"]').value;
|
18
|
+
}, 'chuck', 'Casper.fill() can fill an input[type=password] form field');
|
19
|
+
this.test.assertEvalEquals(function() {
|
20
|
+
return document.querySelector('textarea[name="content"]').value;
|
21
|
+
}, 'Am watching thou', 'Casper.fill() can fill a textarea form field');
|
22
|
+
this.test.assertEvalEquals(function() {
|
23
|
+
return document.querySelector('select[name="topic"]').value;
|
24
|
+
}, 'bar', 'Casper.fill() can pick a value from a select form field');
|
25
|
+
this.test.assertEvalEquals(function() {
|
26
|
+
return document.querySelector('input[name="check"]').checked;
|
27
|
+
}, true, 'Casper.fill() can check a form checkbox');
|
28
|
+
this.test.assertEvalEquals(function() {
|
29
|
+
return document.querySelector('input[name="choice"][value="no"]').checked;
|
30
|
+
}, true, 'Casper.fill() can check a form radio button 1/2');
|
31
|
+
this.test.assertEvalEquals(function() {
|
32
|
+
return document.querySelector('input[name="choice"][value="yes"]').checked;
|
33
|
+
}, false, 'Casper.fill() can check a form radio button 2/2');
|
34
|
+
this.test.assertEvalEquals(function() {
|
35
|
+
return document.querySelector('input[name="file"]').files.length === 1;
|
36
|
+
}, true, 'Casper.fill() can select a file to upload');
|
37
|
+
this.test.assertEvalEquals(function() {
|
38
|
+
return (document.querySelector('input[name="checklist[]"][value="1"]').checked &&
|
39
|
+
!document.querySelector('input[name="checklist[]"][value="2"]').checked &&
|
40
|
+
document.querySelector('input[name="checklist[]"][value="3"]').checked);
|
41
|
+
}, true, 'Casper.fill() can fill a list of checkboxes');
|
42
|
+
this.click('input[type="submit"]');
|
43
|
+
});
|
44
|
+
|
45
|
+
casper.then(function() {
|
46
|
+
this.test.comment('Form submitted');
|
47
|
+
this.test.assertUrlMatch(/email=chuck@norris.com/, 'Casper.fill() input[type=email] field was submitted');
|
48
|
+
this.test.assertUrlMatch(/password=chuck/, 'Casper.fill() input[type=password] field was submitted');
|
49
|
+
this.test.assertUrlMatch(/content=Am\+watching\+thou/, 'Casper.fill() textarea field was submitted');
|
50
|
+
this.test.assertUrlMatch(/check=on/, 'Casper.fill() input[type=checkbox] field was submitted');
|
51
|
+
this.test.assertUrlMatch(/choice=no/, 'Casper.fill() input[type=radio] field was submitted');
|
52
|
+
this.test.assertUrlMatch(/topic=bar/, 'Casper.fill() select field was submitted');
|
53
|
+
});
|
54
|
+
|
55
|
+
// multiple forms
|
56
|
+
casper.thenOpen('tests/site/multiple-forms.html', function() {
|
57
|
+
this.test.comment('Multiple forms');
|
58
|
+
this.fill('form[name="f2"]', {
|
59
|
+
yo: "ok"
|
60
|
+
}, true);
|
61
|
+
});
|
62
|
+
|
63
|
+
casper.then(function() {
|
64
|
+
this.test.assertUrlMatch(/\?f=f2&yo=ok$/, 'Casper.fill() handles multiple forms');
|
65
|
+
}),
|
66
|
+
|
67
|
+
casper.run(function() {
|
68
|
+
this.test.done();
|
69
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
casper.start('tests/site/global.html', function() {
|
2
|
+
this.test.comment('Casper.getGlobal()');
|
3
|
+
this.test.assertEquals(this.getGlobal('myGlobal'), 'awesome string', 'Casper.getGlobal() can retrieve a remote global variable');
|
4
|
+
this.test.assertRaises(this.getGlobal, ['myUnencodableGlobal'], 'Casper.getGlobal() does not fail trying to encode an unencodable global');
|
5
|
+
});
|
6
|
+
|
7
|
+
casper.run(function() {
|
8
|
+
this.test.done();
|
9
|
+
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
casper.start('tests/site/page1.html');
|
2
|
+
casper.thenOpen('tests/site/page2.html');
|
3
|
+
casper.thenOpen('tests/site/page3.html');
|
4
|
+
|
5
|
+
casper.back();
|
6
|
+
casper.then(function() {
|
7
|
+
this.test.comment('navigating history backward');
|
8
|
+
this.test.assertMatch(this.getCurrentUrl(), /tests\/site\/page2\.html$/, 'Casper.back() can go back an history step');
|
9
|
+
});
|
10
|
+
|
11
|
+
casper.forward();
|
12
|
+
casper.then(function() {
|
13
|
+
this.test.comment('navigating history forward');
|
14
|
+
this.test.assertMatch(this.getCurrentUrl(), /tests\/site\/page3\.html$/, 'Casper.forward() can go forward an history step');
|
15
|
+
});
|
16
|
+
|
17
|
+
casper.run(function() {
|
18
|
+
this.test.assert(this.history.length > 0, 'Casper.history contains urls');
|
19
|
+
this.test.assertMatch(this.history[0], /tests\/site\/page1\.html$/, 'Casper.history has the correct first url');
|
20
|
+
this.test.done();
|
21
|
+
});
|