better output of casper test suite results
Showing
1 changed file
with
30 additions
and
29 deletions
... | @@ -26,28 +26,28 @@ casper.options.verbose = false; | ... | @@ -26,28 +26,28 @@ casper.options.verbose = false; |
26 | casper.log('foo', 'info'); | 26 | casper.log('foo', 'info'); |
27 | casper.test.assert(casper.result.log.some(function(e) { | 27 | casper.test.assert(casper.result.log.some(function(e) { |
28 | return e.message === 'foo' && e.level === 'info'; | 28 | return e.message === 'foo' && e.level === 'info'; |
29 | }), 'log() adds a log entry'); | 29 | }), 'Casper.log() adds a log entry'); |
30 | casper.options.logLevel = oldLevel; | 30 | casper.options.logLevel = oldLevel; |
31 | casper.options.verbose = true; | 31 | casper.options.verbose = true; |
32 | 32 | ||
33 | // Casper#start() | 33 | // Casper#start() |
34 | casper.test.comment('navigating'); | 34 | casper.test.comment('navigating'); |
35 | casper.start('tests/site/index.html', function(self) { | 35 | casper.start('tests/site/index.html', function(self) { |
36 | self.test.assert(self.exists('a') && !self.exists('chucknorriz'), 'exists() can check if an element exists'); | 36 | self.test.assert(self.exists('a') && !self.exists('chucknorriz'), 'Casper.exists() can check if an element exists'); |
37 | self.test.assertTitle('CasperJS test index', 'start() casper can start itself an open an url'); | 37 | self.test.assertTitle('CasperJS test index', 'Casper.start() casper can start itself an open an url'); |
38 | self.test.assertEval(function() { | 38 | self.test.assertEval(function() { |
39 | return typeof(__utils__) === "object"; | 39 | return typeof(__utils__) === "object"; |
40 | }, 'start() injects ClientUtils instance within remote DOM'); | 40 | }, 'Casper.start() injects ClientUtils instance within remote DOM'); |
41 | self.test.comment('fetching'); | 41 | self.test.comment('fetching'); |
42 | self.test.assertEquals(self.fetchText('ul li'), 'onetwothree', 'fetchText() can retrieves text contents'); | 42 | self.test.assertEquals(self.fetchText('ul li'), 'onetwothree', 'Casper.fetchText() can retrieves text contents'); |
43 | self.test.comment('encoding'); | 43 | self.test.comment('encoding'); |
44 | var image = self.base64encode('file://' + phantom.libraryPath + '/site/images/phantom.png'); | 44 | var image = self.base64encode('file://' + phantom.libraryPath + '/site/images/phantom.png'); |
45 | self.test.assertEquals(image.length, 6160, 'base64encode() can retrieve base64 contents'); | 45 | self.test.assertEquals(image.length, 6160, 'Casper.base64encode() can retrieve base64 contents'); |
46 | self.test.comment('clicking'); | 46 | self.test.comment('clicking'); |
47 | self.click('a[href="test.html"]'); | 47 | self.click('a[href="test.html"]'); |
48 | }); | 48 | }); |
49 | 49 | ||
50 | casper.test.assert(casper.steps.length === 1, 'start() can add a new navigation step'); | 50 | casper.test.assert(casper.steps.length === 1, 'Casper.start() can add a new navigation step'); |
51 | 51 | ||
52 | // Casper.viewport() | 52 | // Casper.viewport() |
53 | casper.test.comment('viewport'); | 53 | casper.test.comment('viewport'); |
... | @@ -59,11 +59,11 @@ casper.test.assertRaises(casper.viewport, ['a', 'b'], 'Casper.viewport() validat | ... | @@ -59,11 +59,11 @@ casper.test.assertRaises(casper.viewport, ['a', 'b'], 'Casper.viewport() validat |
59 | // Casper#then() | 59 | // Casper#then() |
60 | casper.test.comment('then'); | 60 | casper.test.comment('then'); |
61 | casper.then(function(self) { | 61 | casper.then(function(self) { |
62 | self.test.assertTitle('CasperJS test target', 'click() casper can click on a text link and react when it is loaded 1/2'); | 62 | self.test.assertTitle('CasperJS test target', 'Casper.click() casper can click on a text link and react when it is loaded 1/2'); |
63 | self.click('a[href="form.html"]'); | 63 | self.click('a[href="form.html"]'); |
64 | }); | 64 | }); |
65 | 65 | ||
66 | casper.test.assert(casper.steps.length === 2, 'then() adds a new navigation step'); | 66 | casper.test.assert(casper.steps.length === 2, 'Casper.then() adds a new navigation step'); |
67 | 67 | ||
68 | // Casper#capture() | 68 | // Casper#capture() |
69 | casper.test.comment('capturing'); | 69 | casper.test.comment('capturing'); |
... | @@ -101,7 +101,7 @@ casper.then(function(self) { | ... | @@ -101,7 +101,7 @@ casper.then(function(self) { |
101 | 101 | ||
102 | // Casper#fill() | 102 | // Casper#fill() |
103 | casper.then(function(self) { | 103 | casper.then(function(self) { |
104 | self.test.assertTitle('CasperJS test form', 'click() casper can click on a text link and react when it is loaded 2/2'); | 104 | self.test.assertTitle('CasperJS test form', 'Casper.click() casper can click on a text link and react when it is loaded 2/2'); |
105 | self.test.comment('filling a form'); | 105 | self.test.comment('filling a form'); |
106 | self.fill('form[action="result.html"]', { | 106 | self.fill('form[action="result.html"]', { |
107 | email: 'chuck@norris.com', | 107 | email: 'chuck@norris.com', |
... | @@ -113,57 +113,57 @@ casper.then(function(self) { | ... | @@ -113,57 +113,57 @@ casper.then(function(self) { |
113 | }); | 113 | }); |
114 | self.test.assertEvalEquals(function() { | 114 | self.test.assertEvalEquals(function() { |
115 | return document.querySelector('input[name="email"]').value; | 115 | return document.querySelector('input[name="email"]').value; |
116 | }, 'chuck@norris.com', 'fill() can fill an input[type=text] form field'); | 116 | }, 'chuck@norris.com', 'Casper.fill() can fill an input[type=text] form field'); |
117 | self.test.assertEvalEquals(function() { | 117 | self.test.assertEvalEquals(function() { |
118 | return document.querySelector('textarea[name="content"]').value; | 118 | return document.querySelector('textarea[name="content"]').value; |
119 | }, 'Am watching thou', 'fill() can fill a textarea form field'); | 119 | }, 'Am watching thou', 'Casper.fill() can fill a textarea form field'); |
120 | self.test.assertEvalEquals(function() { | 120 | self.test.assertEvalEquals(function() { |
121 | return document.querySelector('select[name="topic"]').value; | 121 | return document.querySelector('select[name="topic"]').value; |
122 | }, 'bar', 'fill() can pick a value from a select form field'); | 122 | }, 'bar', 'Casper.fill() can pick a value from a select form field'); |
123 | self.test.assertEvalEquals(function() { | 123 | self.test.assertEvalEquals(function() { |
124 | return document.querySelector('input[name="check"]').checked; | 124 | return document.querySelector('input[name="check"]').checked; |
125 | }, true, 'fill() can check a form checkbox'); | 125 | }, true, 'Casper.fill() can check a form checkbox'); |
126 | self.test.assertEvalEquals(function() { | 126 | self.test.assertEvalEquals(function() { |
127 | return document.querySelector('input[name="choice"][value="no"]').checked; | 127 | return document.querySelector('input[name="choice"][value="no"]').checked; |
128 | }, true, 'fill() can check a form radio button 1/2'); | 128 | }, true, 'Casper.fill() can check a form radio button 1/2'); |
129 | self.test.assertEvalEquals(function() { | 129 | self.test.assertEvalEquals(function() { |
130 | return document.querySelector('input[name="choice"][value="yes"]').checked; | 130 | return document.querySelector('input[name="choice"][value="yes"]').checked; |
131 | }, false, 'fill() can check a form radio button 2/2'); | 131 | }, false, 'Casper.fill() can check a form radio button 2/2'); |
132 | self.test.assertEvalEquals(function() { | 132 | self.test.assertEvalEquals(function() { |
133 | return document.querySelector('input[name="file"]').files.length === 1; | 133 | return document.querySelector('input[name="file"]').files.length === 1; |
134 | }, true, 'fill() can select a file to upload'); | 134 | }, true, 'Casper.fill() can select a file to upload'); |
135 | self.click('input[type="submit"]'); | 135 | self.click('input[type="submit"]'); |
136 | }); | 136 | }); |
137 | 137 | ||
138 | // Casper#click() | 138 | // Casper#click() |
139 | casper.then(function(self) { | 139 | casper.then(function(self) { |
140 | self.test.assertTitle('CasperJS test form result', 'click() casper can click on a submit button'); | 140 | self.test.assertTitle('CasperJS test form result', 'Casper.click() casper can click on a submit button'); |
141 | self.test.assertUrlMatch(/email=chuck@norris.com/, 'fill() input[type=email] field was submitted'); | 141 | self.test.assertUrlMatch(/email=chuck@norris.com/, 'Casper.fill() input[type=email] field was submitted'); |
142 | self.test.assertUrlMatch(/content=Am\+watching\+thou/, 'fill() textarea field was submitted'); | 142 | self.test.assertUrlMatch(/content=Am\+watching\+thou/, 'Casper.fill() textarea field was submitted'); |
143 | self.test.assertUrlMatch(/check=on/, 'fill() input[type=checkbox] field was submitted'); | 143 | self.test.assertUrlMatch(/check=on/, 'Casper.fill() input[type=checkbox] field was submitted'); |
144 | self.test.assertUrlMatch(/choice=no/, 'fill() input[type=radio] field was submitted'); | 144 | self.test.assertUrlMatch(/choice=no/, 'Casper.fill() input[type=radio] field was submitted'); |
145 | self.test.assertUrlMatch(/topic=bar/, 'fill() select field was submitted'); | 145 | self.test.assertUrlMatch(/topic=bar/, 'Casper.fill() select field was submitted'); |
146 | }); | 146 | }); |
147 | 147 | ||
148 | // Casper#thenClick() | 148 | // Casper#thenClick() |
149 | casper.thenClick('body a', function(self) { | 149 | casper.thenClick('body a', function(self) { |
150 | self.test.comment('Casper.thenClick()'); | 150 | self.test.comment('Casper.thenClick()'); |
151 | self.test.assertTitle('CasperJS test index', 'thenClick() casper can add a step for clicking a link'); | 151 | self.test.assertTitle('CasperJS test index', 'Casper.thenClick() casper can add a step for clicking a link'); |
152 | }); | 152 | }); |
153 | 153 | ||
154 | // Casper#each() | 154 | // Casper#each() |
155 | casper.test.comment('each'); | 155 | casper.test.comment('each'); |
156 | casper.each([1, 2, 3], function(self, item, i) { | 156 | casper.each([1, 2, 3], function(self, item, i) { |
157 | self.test.assertEquals(i, item - 1, 'each() passes a contextualized index'); | 157 | self.test.assertEquals(i, item - 1, 'Casper.each() passes a contextualized index'); |
158 | }); | 158 | }); |
159 | 159 | ||
160 | // Casper.XUnitExporter | 160 | // Casper.XUnitExporter |
161 | casper.test.comment('phantom.Casper.XUnitExporter'); | 161 | casper.test.comment('phantom.Casper.XUnitExporter'); |
162 | xunit = new phantom.Casper.XUnitExporter(); | 162 | xunit = new phantom.Casper.XUnitExporter(); |
163 | xunit.addSuccess('foo', 'bar'); | 163 | xunit.addSuccess('foo', 'bar'); |
164 | casper.test.assertMatch(xunit.getXML(), /<testcase classname="foo" name="bar"/, 'addSuccess() adds a successful testcase'); | 164 | casper.test.assertMatch(xunit.getXML(), /<testcase classname="foo" name="bar"/, 'XUnitExporter.addSuccess() adds a successful testcase'); |
165 | xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz'); | 165 | xunit.addFailure('bar', 'baz', 'wrong', 'chucknorriz'); |
166 | casper.test.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'addFailure() adds a failed testcase'); | 166 | casper.test.assertMatch(xunit.getXML(), /<testcase classname="bar" name="baz"><failure type="chucknorriz">wrong/, 'XUnitExporter.addFailure() adds a failed testcase'); |
167 | 167 | ||
168 | // Casper.ClientUtils.log() | 168 | // Casper.ClientUtils.log() |
169 | casper.then(function(self) { | 169 | casper.then(function(self) { |
... | @@ -210,12 +210,13 @@ casper.then(function() { | ... | @@ -210,12 +210,13 @@ casper.then(function() { |
210 | // Casper.getGlobal() | 210 | // Casper.getGlobal() |
211 | casper.thenOpen('tests/site/global.html', function(self) { | 211 | casper.thenOpen('tests/site/global.html', function(self) { |
212 | self.test.comment('Casper.getGlobal()'); | 212 | self.test.comment('Casper.getGlobal()'); |
213 | self.test.assertEquals(self.getGlobal('myGlobal'), 'awesome string', 'global retrieved') | 213 | self.test.assertEquals(self.getGlobal('myGlobal'), 'awesome string', 'Casper.getGlobal() can retrieve a remote global variable') |
214 | }); | 214 | }); |
215 | 215 | ||
216 | // Casper.options.onStepComplete | 216 | // Casper.options.onStepComplete |
217 | casper.then(function(self) { | 217 | casper.then(function(self) { |
218 | self.options.onStepComplete = function(self, stepResult) { | 218 | self.options.onStepComplete = function(self, stepResult) { |
219 | self.test.comment('Casper.options.onStepComplete()') | ||
219 | self.test.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete'); | 220 | self.test.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete'); |
220 | self.options.onStepComplete = null; | 221 | self.options.onStepComplete = null; |
221 | }; | 222 | }; |
... | @@ -245,6 +246,6 @@ casper.run(function(self) { | ... | @@ -245,6 +246,6 @@ casper.run(function(self) { |
245 | casper.test.assert(self.history.length > 0, 'Casper.history contains urls'); | 246 | casper.test.assert(self.history.length > 0, 'Casper.history contains urls'); |
246 | casper.test.assertMatch(self.history[0], /tests\/site\/index\.html$/, 'Casper.history has the correct first url'); | 247 | casper.test.assertMatch(self.history[0], /tests\/site\/index\.html$/, 'Casper.history has the correct first url'); |
247 | self.test.comment('logging, again'); | 248 | self.test.comment('logging, again'); |
248 | self.test.assertEquals(self.result.log.length, 3, 'log() logged messages'); | 249 | self.test.assertEquals(self.result.log.length, 3, 'Casper.log() logged messages'); |
249 | self.test.renderResults(true, 0, save); | 250 | self.test.renderResults(true, 0, save); |
250 | }); | 251 | }); | ... | ... |
-
Please register or sign in to post a comment