migrated so tests to use setUp/tearDown - refs #397
Showing
5 changed files
with
55 additions
and
24 deletions
... | @@ -14,12 +14,19 @@ function fetchUA(request) { | ... | @@ -14,12 +14,19 @@ function fetchUA(request) { |
14 | testUA(headers.pop().value, /plop/); | 14 | testUA(headers.pop().value, /plop/); |
15 | } | 15 | } |
16 | 16 | ||
17 | casper.test.begin('userAgent() tests', 3, function(test) { | 17 | casper.test.begin('userAgent() tests', 3, { |
18 | originalUA: casper.options.pageSettings.userAgent, | ||
19 | |||
20 | tearDown: function(test) { | ||
21 | casper.userAgent(this.originalUA); | ||
22 | }, | ||
23 | |||
24 | test: function(test) { | ||
18 | testUA(casper.options.pageSettings.userAgent, /CasperJS/); | 25 | testUA(casper.options.pageSettings.userAgent, /CasperJS/); |
19 | casper.start(); | 26 | casper.start().userAgent('plop').once('resource.requested', fetchUA); |
20 | casper.userAgent('plop').once('resource.requested', fetchUA); | 27 | casper.thenOpen('tests/site/index.html').run(function() { |
21 | casper.thenOpen('tests/site/index.html'); | ||
22 | casper.run(function() { | ||
23 | test.done(); | 28 | test.done(); |
24 | }); | 29 | }); |
30 | } | ||
25 | }); | 31 | }); |
32 | ... | ... |
1 | /*global casper*/ | 1 | /*global casper*/ |
2 | /*jshint strict:false*/ | 2 | /*jshint strict:false*/ |
3 | casper.test.begin('alert events', 1, function(test) { | 3 | casper.test.begin('alert events', 1, { |
4 | var ok = false; | 4 | ok: false, |
5 | |||
6 | tearDown: function(test) { | ||
7 | casper.removeAllListeners('remote.alert'); | ||
8 | }, | ||
9 | |||
10 | test: function(test) { | ||
11 | var self = this; | ||
12 | |||
5 | casper.once('remote.alert', function(message) { | 13 | casper.once('remote.alert', function(message) { |
6 | ok = message === 'plop'; | 14 | self.ok = (message === 'plop'); |
7 | }); | 15 | }); |
16 | |||
8 | casper.start('tests/site/alert.html', function() { | 17 | casper.start('tests/site/alert.html', function() { |
9 | test.assert(ok, 'alert event has been intercepted'); | 18 | test.assert(self.ok, 'alert event has been intercepted'); |
10 | }); | 19 | }); |
20 | |||
11 | casper.run(function() { | 21 | casper.run(function() { |
12 | this.removeAllListeners('remote.alert'); | ||
13 | test.done(); | 22 | test.done(); |
14 | }); | 23 | }); |
24 | } | ||
15 | }); | 25 | }); | ... | ... |
1 | /*global casper*/ | 1 | /*global casper*/ |
2 | /*jshint strict:false*/ | 2 | /*jshint strict:false*/ |
3 | var fs = require('fs'), | 3 | var fs = require('fs'); |
4 | testFile = '/tmp/__casper_test_capture.png'; | ||
5 | 4 | ||
6 | if (fs.exists(testFile) && fs.isFile(testFile)) { | 5 | casper.test.begin('Casper.capture() tests', 1, { |
7 | fs.remove(testFile); | 6 | testFile: '/tmp/__casper_test_capture.png', |
8 | } | ||
9 | 7 | ||
10 | casper.test.begin('Casper.capture() tests', 1, function(test) { | 8 | setUp: function(test) { |
11 | casper.start('tests/site/index.html', function() { | 9 | if (fs.exists(this.testFile) && fs.isFile(this.testFile)) { |
12 | this.viewport(300, 200); | 10 | try { |
13 | this.capture(testFile); | 11 | fs.remove(this.testFile); |
14 | test.assert(fs.isFile(testFile), 'Casper.capture() captured a screenshot'); | 12 | } catch (e) { |
15 | }).run(function() { | 13 | } |
14 | } | ||
15 | }, | ||
16 | |||
17 | tearDown: function(test) { | ||
16 | try { | 18 | try { |
17 | fs.remove(testFile); | 19 | fs.remove(this.testFile); |
18 | } catch(e) { | 20 | } catch(e) { |
19 | this.warn('Unable to delete test file ' + testFile + '; please delete it manually'); | ||
20 | } | 21 | } |
22 | }, | ||
23 | |||
24 | test: function(test) { | ||
25 | var self = this; | ||
26 | |||
27 | casper.start('tests/site/index.html', function() { | ||
28 | this.viewport(300, 200); | ||
29 | this.capture(self.testFile); | ||
30 | test.assert(fs.isFile(self.testFile), 'Casper.capture() captured a screenshot'); | ||
31 | }); | ||
32 | |||
33 | casper.run(function() { | ||
21 | test.done(); | 34 | test.done(); |
22 | }); | 35 | }); |
36 | } | ||
23 | }); | 37 | }); |
24 | 38 | ||
25 | casper.test.begin('Casper.captureBase64() tests', 3, function(test) { | 39 | casper.test.begin('Casper.captureBase64() tests', 3, function(test) { | ... | ... |
tests/suites/tester/.casper
0 → 100644
File mode changed
-
Please register or sign in to post a comment