Commit 00896185 008961853230e54304725244fe33c09d2046c7f6 by Nicolas Perriault

migrated casper/click tests to new test format

1 parent ff4624e2
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false*/
3 casper.start('tests/site/index.html', function() { 3 casper.test.begin('click() tests', 2, function(test) {
4 this.click('a[href="test.html"]'); 4 casper.start('tests/site/index.html', function() {
5 this.click('a[href="test.html"]');
6 }).then(function() {
7 test.assertTitle('CasperJS test target', 'Casper.click() can click on a link');
8 }).thenClick('a', function() {
9 test.assertTitle('CasperJS test form', 'Casper.thenClick() can click on a link');
10 }).run(function() {
11 test.done();
12 });
5 }); 13 });
6 14
7 casper.then(function() { 15 casper.test.begin('onclick variants tests', 8, function(test) {
8 this.test.comment('Casper.click()'); 16 casper.start('tests/site/click.html', function() {
9 this.test.assertTitle('CasperJS test target', 'Casper.click() can click on a link'); 17 test.assert(this.click('#test1'), 'Casper.click() can click an `href="javascript:` link');
10 }).thenClick('a', function() { 18 test.assert(this.click('#test2'), 'Casper.click() can click an `href="#"` link');
11 this.test.comment('Casper.thenClick()'); 19 test.assert(this.click('#test3'), 'Casper.click() can click an `onclick=".*; return false"` link');
12 this.test.assertTitle('CasperJS test form', 'Casper.thenClick() can click on a link'); 20 test.assert(this.click('#test4'), 'Casper.click() can click an unobstrusive js handled link');
21 var results = this.getGlobal('results');
22 test.assert(results.test1, 'Casper.click() has clicked an `href="javascript:` link');
23 test.assert(results.test2, 'Casper.click() has clicked an `href="#"` link');
24 test.assert(results.test3, 'Casper.click() has clicked an `onclick=".*; return false"` link');
25 test.assert(results.test4, 'Casper.click() has clicked an unobstrusive js handled link');
26 }).run(function() {
27 test.done();
28 });
13 }); 29 });
14 30
15 // onclick variants tests 31 casper.test.begin('clickLabel tests tests', 8, function(test) {
16 casper.thenOpen('tests/site/click.html', function() { 32 casper.start('tests/site/click.html', function() {
17 this.test.comment('Casper.click()'); 33 test.assert(this.clickLabel('test1'),
18 this.test.assert(this.click('#test1'), 'Casper.click() can click an `href="javascript:` link'); 34 'Casper.clickLabel() can click an `href="javascript:` link');
19 this.test.assert(this.click('#test2'), 'Casper.click() can click an `href="#"` link'); 35 test.assert(this.clickLabel('test2'),
20 this.test.assert(this.click('#test3'), 'Casper.click() can click an `onclick=".*; return false"` link'); 36 'Casper.clickLabel() can click an `href="#"` link');
21 this.test.assert(this.click('#test4'), 'Casper.click() can click an unobstrusive js handled link'); 37 test.assert(this.clickLabel('test3'),
22 var results = this.getGlobal('results'); 38 'Casper.clickLabel() can click an `onclick=".*; return false"` link');
23 this.test.assert(results.test1, 'Casper.click() has clicked an `href="javascript:` link'); 39 test.assert(this.clickLabel('test4'),
24 this.test.assert(results.test2, 'Casper.click() has clicked an `href="#"` link'); 40 'Casper.clickLabel() can click an unobstrusive js handled link');
25 this.test.assert(results.test3, 'Casper.click() has clicked an `onclick=".*; return false"` link'); 41 var results = this.getGlobal('results');
26 this.test.assert(results.test4, 'Casper.click() has clicked an unobstrusive js handled link'); 42 test.assert(results.test1,
43 'Casper.clickLabel() has clicked an `href="javascript:` link');
44 test.assert(results.test2,
45 'Casper.clickLabel() has clicked an `href="#"` link');
46 test.assert(results.test3,
47 'Casper.clickLabel() has clicked an `onclick=".*; return false"` link');
48 test.assert(results.test4,
49 'Casper.clickLabel() has clicked an unobstrusive js handled link');
50 }).run(function() {
51 test.done();
52 });
27 }); 53 });
28 54
29 // clickLabel tests 55 casper.test.begin('casper.mouse tests', 3, function(test) {
30 casper.thenOpen('tests/site/click.html', function() { 56 casper.start('tests/site/click.html', function() {
31 this.test.comment('Casper.clickLabel()'); 57 this.mouse.down(200, 100);
32 this.test.assert(this.clickLabel('test1'), 'Casper.clickLabel() can click an `href="javascript:` link'); 58 var results = this.getGlobal('results');
33 this.test.assert(this.clickLabel('test2'), 'Casper.clickLabel() can click an `href="#"` link'); 59 test.assertEquals(results.testdown, [200, 100],
34 this.test.assert(this.clickLabel('test3'), 'Casper.clickLabel() can click an `onclick=".*; return false"` link'); 60 'Mouse.down() has pressed button to the specified position');
35 this.test.assert(this.clickLabel('test4'), 'Casper.clickLabel() can click an unobstrusive js handled link'); 61 this.mouse.up(200, 100);
36 var results = this.getGlobal('results'); 62 results = this.getGlobal('results');
37 this.test.assert(results.test1, 'Casper.clickLabel() has clicked an `href="javascript:` link'); 63 test.assertEquals(results.testup, [200, 100],
38 this.test.assert(results.test2, 'Casper.clickLabel() has clicked an `href="#"` link'); 64 'Mouse.up() has released button to the specified position');
39 this.test.assert(results.test3, 'Casper.clickLabel() has clicked an `onclick=".*; return false"` link'); 65 this.mouse.move(200, 100);
40 this.test.assert(results.test4, 'Casper.clickLabel() has clicked an unobstrusive js handled link'); 66 results = this.getGlobal('results');
67 test.assertEquals(results.testmove, [200, 100],
68 'Mouse.move() has moved to the specified position');
69 }).run(function() {
70 test.done();
71 });
41 }); 72 });
42 73
43 // casper.mouse 74 casper.test.begin('element focus on click', 1, function(test) {
44 casper.then(function() { 75 casper.start().then(function() {
45 this.test.comment('Mouse.down()'); 76 this.page.content = '<form><input type="text" name="foo"></form>'
46 this.mouse.down(200, 100); 77 this.click('form input[name=foo]')
47 var results = this.getGlobal('results'); 78 this.page.sendEvent('keypress', 'bar');
48 this.test.assertEquals(results.testdown, [200, 100], 'Mouse.down() has pressed button to the specified position'); 79 test.assertEquals(this.getFormValues('form')['foo'], 'bar',
49 80 'Casper.click() sets the focus on clicked element');
50 this.test.comment('Mouse.up()'); 81 }).run(function() {
51 this.mouse.up(200, 100); 82 test.done();
52 results = this.getGlobal('results'); 83 });
53 this.test.assertEquals(results.testup, [200, 100], 'Mouse.up() has released button to the specified position');
54
55 this.test.comment('Mouse.move()');
56 this.mouse.move(200, 100);
57 results = this.getGlobal('results');
58 this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position');
59 });
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
69 casper.run(function() {
70 this.test.done(22);
71 }); 84 });
......