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