Commit 08625bd0 08625bd0e3884cac45e7b3b3816519e402cd1c13 by Nicolas Perriault

migrated tester/asserts tests to new testing format

1 parent af9dcbc2
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false maxstatements:99*/ 2 /*jshint strict:false maxstatements:99*/
3 var fs = require('fs'); 3 var fs = require('fs');
4 var t = casper.test;
5 4
6 casper.start('tests/site/index.html', function() { 5 casper.test.begin('Common assertions tests', 40, function(test) {
7 t.comment('Tester.assertTextExists()'); 6 casper.start('tests/site/index.html', function() {
8 t.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text'); 7 test.assertTextExists('form', 'Tester.assertTextExists() checks that page body contains text');
9 8 test.assertTextExist('form', 'Tester.assertTextExist() checks that page body contains text [alias]');
10 t.comment('Tester.assertTextExist()'); 9 test.assertTextDoesntExist('blah', "Tester.assertTextDoesntExist() checks that page body doesn't contain provided text");
11 t.assertTextExist('form', 'Tester.assertTextExist() checks that page body contains text [alias]'); 10 test.assertSelectorHasText('h1', 'Title', 'Tester.assertSelectorHasText() works as expected');
12 11 test.assertSelectorDoesntHaveText('h1', 'Subtitle', 'Tester.assertSelectorDoesntHaveText() works as expected');
13 t.comment('Tester.assertTextDoesntExist()'); 12 test.assert(true, 'Tester.assert() works as expected');
14 t.assertTextDoesntExist('blah', "Tester.assertTextDoesntExist() checks that page body doesn't contain provided text"); 13 test.assertTrue(true, 'Tester.assertTrue() works as expected [alias]');
15 14 test.assertTruthy('1', 'Tester.assertTruthy() works as expected');
16 t.comment('Tester.assertSelectorHasText()'); 15 test.assertFalsy('', 'Tester.assertFalsy() works as expected');
17 t.assertSelectorHasText('h1', 'Title', 'Tester.assertSelectorHasText() works as expected'); 16 test.assertNot(false, 'Tester.assertNot() works as expected');
18 17 test.assertEquals(true, true, 'Tester.assertEquals() works as expected');
19 t.comment('Tester.assertSelectorDoesntHaveText()'); 18 test.assertEqual(true, true, 'Tester.assertEqual() works as expected [alias]');
20 t.assertSelectorDoesntHaveText('h1', 'Subtitle', 'Tester.assertSelectorDoesntHaveText() works as expected'); 19 test.assertNotEquals(true, false, 'Tester.assertNotEquals() works as expected');
21 20 test.assertEval(function() {
22 t.comment('Tester.assert()'); 21 return true;
23 t.assert(true, 'Tester.assert() works as expected'); 22 }, 'Tester.assertEval() works as expected');
24 23 test.assertEvaluate(function() {
25 t.comment('Tester.assertTrue()'); 24 return true;
26 t.assertTrue(true, 'Tester.assertTrue() works as expected [alias]'); 25 }, 'Tester.assertEvaluate() works as expected [alias]');
27 26 test.assertEvalEquals(function() {
28 t.comment('Tester.assertTruthy()'); 27 return 42;
29 t.assertTruthy('1', 'Tester.assertTruthy() works as expected'); 28 }, 42, 'Tester.assertEvalEquals() works as expected');
30 29 test.assertEvalEqual(function() {
31 t.comment('Tester.assertFalsy()'); 30 return 42;
32 t.assertFalsy('', 'Tester.assertFalsy() works as expected'); 31 }, 42, 'Tester.assertEvalEqual() works as expected [alias]');
33 32 test.assertExists('body', 'Tester.assertExists() works as expected');
34 t.comment('Tester.assertNot()'); 33 test.assertExist('body', 'Tester.assertExist() works as expected [alias]');
35 t.assertNot(false, 'Tester.assertNot() works as expected'); 34 test.assertSelectorExists('body', 'Tester.assertSelectorExists() works as expected [alias]');
36 35 test.assertSelectorExist('body', 'Tester.assertSelectorExist() works as expected [alias]');
37 t.comment('Tester.assertEquals()'); 36 test.assertDoesntExist('foobar', 'Tester.assertDoesntExist() works as expected');
38 t.assertEquals(true, true, 'Tester.assertEquals() works as expected'); 37 test.assertDoesntExist('foobar', 'Tester.assertNotExist() works as expected [alias]');
39 38 // using file:// protocol, HTTP status is always null
40 t.comment('Tester.assertEqual()'); 39 test.assertHttpStatus(200, 'Tester.assertHttpStatus() works as expected');
41 t.assertEqual(true, true, 'Tester.assertEqual() works as expected [alias]'); 40 test.assertMatch("the lazy dog", /lazy/, 'Tester.assertMatch() works as expected');
42 41 test.assertMatches("the lazy dog", /lazy/, 'Tester.assertMatches() works as expected [alias]');
43 t.comment('Tester.assertNotEquals()'); 42 test.assertRaises(function() {
44 t.assertNotEquals(true, false, 'Tester.assertNotEquals() works as expected'); 43 throw new Error('plop');
45 44 }, [], 'Tester.assertRaises() works as expected');
46 t.comment('Tester.assertEval()'); 45 test.assertRaise(function() {
47 t.assertEval(function() { 46 throw new Error('plop');
48 return true; 47 }, [], 'Tester.assertRaise() works as expected [alias]');
49 }, 'Tester.assertEval() works as expected'); 48 test.assertThrows(function() {
50 49 throw new Error('plop');
51 t.comment('Tester.assertEvaluate()'); 50 }, [], 'Tester.assertThrows() works as expected [alias]');
52 t.assertEvaluate(function() { 51 test.assertResourceExists(/index\.html/, 'Tester.assertResourceExists() works as expected');
53 return true; 52 test.assertResourceExist(/index\.html/, 'Tester.assertResourceExist() works as expected [alias]');
54 }, 'Tester.assertEvaluate() works as expected [alias]'); 53 test.assertTitle('CasperJS test index', 'Tester.assertTitle() works as expected');
55 54 test.assertTitleMatch(/test index/, 'Tester.assertTitleMatch() works as expected');
56 t.comment('Tester.assertEvalEquals()'); 55 test.assertTitleMatches(/test index/, 'Tester.assertTitleMatches() works as expected [alias]');
57 t.assertEvalEquals(function() { 56 test.assertType("plop", "string", "Tester.assertType() works as expected");
58 return 42; 57 test.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected");
59 }, 42, 'Tester.assertEvalEquals() works as expected'); 58 test.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]");
60 59 test.assertVisible('img', 'Tester.assertVisible() works as expected');
61 t.comment('Tester.assertEvalEqual()'); 60 test.assertNotVisible('p#hidden', 'Tester.assertNotVisible() works as expected');
62 t.assertEvalEqual(function() { 61 test.assertInvisible('p#hidden', 'Tester.assertInvisible() works as expected [alias]');
63 return 42; 62 }).run(function() {
64 }, 42, 'Tester.assertEvalEqual() works as expected [alias]'); 63 test.done();
65
66 t.comment('Tester.assertExists()');
67 t.assertExists('body', 'Tester.assertExists() works as expected');
68
69 t.comment('Tester.assertExist()');
70 t.assertExist('body', 'Tester.assertExist() works as expected [alias]');
71
72 t.comment('Tester.assertSelectorExists()');
73 t.assertSelectorExists('body', 'Tester.assertSelectorExists() works as expected [alias]');
74
75 t.comment('Tester.assertSelectorExists()');
76 t.assertSelectorExist('body', 'Tester.assertSelectorExist() works as expected [alias]');
77
78 t.comment('Tester.assertDoesntExist()');
79 t.assertDoesntExist('foobar', 'Tester.assertDoesntExist() works as expected');
80
81 t.comment('Tester.assertNotExist()');
82 t.assertDoesntExist('foobar', 'Tester.assertNotExist() works as expected [alias]');
83
84 t.comment('Tester.assertHttpStatus()');
85 // using file:// protocol, HTTP status is always null
86 t.assertHttpStatus(200, 'Tester.assertHttpStatus() works as expected');
87
88 t.comment('Tester.assertMatch()');
89 t.assertMatch("the lazy dog", /lazy/, 'Tester.assertMatch() works as expected');
90
91 t.comment('Tester.assertMatches()');
92 t.assertMatches("the lazy dog", /lazy/, 'Tester.assertMatches() works as expected [alias]');
93
94 t.comment('Tester.assertRaises()');
95 t.assertRaises(function() {
96 throw new Error('plop');
97 }, [], 'Tester.assertRaises() works as expected');
98
99 t.comment('Tester.assertRaise()');
100 t.assertRaise(function() {
101 throw new Error('plop');
102 }, [], 'Tester.assertRaise() works as expected [alias]');
103
104 t.comment('Tester.assertThrows()');
105 t.assertThrows(function() {
106 throw new Error('plop');
107 }, [], 'Tester.assertThrows() works as expected [alias]');
108
109 t.comment('Tester.assertResourceExists()');
110 t.assertResourceExists(/index\.html/, 'Tester.assertResourceExists() works as expected');
111
112 t.comment('Tester.assertResourceExist()');
113 t.assertResourceExist(/index\.html/, 'Tester.assertResourceExist() works as expected [alias]');
114
115 t.comment('Tester.assertTitle()');
116 t.assertTitle('CasperJS test index', 'Tester.assertTitle() works as expected');
117
118 t.comment('Tester.assertTitleMatch()');
119 t.assertTitleMatch(/test index/, 'Tester.assertTitleMatch() works as expected');
120
121 t.comment('Tester.assertTitleMatches()');
122 t.assertTitleMatches(/test index/, 'Tester.assertTitleMatches() works as expected [alias]');
123
124 t.comment('Tester.assertType()');
125 t.assertType("plop", "string", "Tester.assertType() works as expected");
126
127 t.comment('Tester.assertUrlMatch()');
128 t.assertUrlMatch(/index\.html$/, "Tester.assertUrlMatch() works as expected");
129
130 t.comment('Tester.assertUrlMatches()');
131 t.assertUrlMatches(/index\.html$/, "Tester.assertUrlMatches() works as expected [alias]");
132
133 t.comment('Tester.assertVisible()');
134 t.assertVisible('img', 'Tester.assertVisible() works as expected');
135
136 t.comment('Tester.assertNotVisible()');
137 t.assertNotVisible('p#hidden', 'Tester.assertNotVisible() works as expected');
138
139 t.comment('Tester.assertInvisible()');
140 t.assertInvisible('p#hidden', 'Tester.assertInvisible() works as expected [alias]');
141 });
142
143 casper.thenOpen('tests/site/form.html', function() {
144 t.comment('Tester.assertField()');
145 t.comment('1. Fill inputs');
146 var fpath = phantom.libraryPath + '/README.md';
147 this.fill('form[action="result.html"]', {
148 'email': 'chuck@norris.com',
149 'content': 'Am watching thou',
150 'check': true,
151 'choice': 'no',
152 'topic': 'bar',
153 'file': fpath,
154 'checklist[]': ['1', '3']
155 }); 64 });
156 t.assertField('email', 'chuck@norris.com', 'Tester.assertField() works as expected with inputs');
157 t.assertField('content', 'Am watching thou', 'Tester.assertField() works as expected with textarea');
158 t.assertField('check', true, 'Tester.assertField() works as expected with checkboxes');
159 t.assertField('choice', 'no', 'Tester.assertField() works as expected with radios');
160 t.assertField('topic', 'bar', 'Tester.assertField() works as expected with selects');
161 t.assertField('file', 'C:\\fakepath\\README.md', 'Tester.assertField() works as expected with file inputs');
162 t.assertField('checklist[]', ['1', '3'], 'Tester.assertField() works as expected with check lists');
163 }); 65 });
164 66
165 casper.reload(function() { 67 casper.test.begin('filled inputs', 7, function(test) {
166 t.comment('2. Unfill inputs'); 68 casper.start('tests/site/form.html', function() {
167 this.fill('form[action="result.html"]', { 69 this.fill('form[action="result.html"]', {
168 'email': '', 70 'email': '',
169 'content': '', 71 'content': '',
170 'check': false, 72 'check': false,
171 'choice': '', 73 'choice': '',
172 'topic': '', 74 'topic': '',
173 'file': '', 75 'file': '',
174 'checklist[]': [] 76 'checklist[]': []
77 });
78 test.assertField('email', '', 'Tester.assertField() works as expected with inputs');
79 test.assertField('content', '', 'Tester.assertField() works as expected with textarea');
80 test.assertField('check', false, 'Tester.assertField() works as expected with checkboxes');
81 test.assertField('choice', null, 'Tester.assertField() works as expected with radios');
82 test.assertField('topic', 'foo', 'Tester.assertField() works as expected with selects');
83 test.assertField('file', '', 'Tester.assertField() works as expected with file inputs');
84 test.assertField('checklist[]', [], 'Tester.assertField() works as expected with check lists');
85 }).run(function() {
86 test.done();
175 }); 87 });
176 t.assertField('email', '', 'Tester.assertField() works as expected with inputs');
177 t.assertField('content', '', 'Tester.assertField() works as expected with textarea');
178 t.assertField('check', false, 'Tester.assertField() works as expected with checkboxes');
179 t.assertField('choice', null, 'Tester.assertField() works as expected with radios');
180 t.assertField('topic', 'foo', 'Tester.assertField() works as expected with selects');
181 t.assertField('file', '', 'Tester.assertField() works as expected with file inputs');
182 t.assertField('checklist[]', [], 'Tester.assertField() works as expected with check lists');
183 }); 88 });
184 89
185 casper.run(function() { 90 casper.test.begin('unfilled inputs', 7, function(test) {
186 t.done(54); 91 var fpath = phantom.libraryPath + '/README.md';
92 casper.start('tests/site/form.html', function() {
93 this.fill('form[action="result.html"]', {
94 'email': 'chuck@norris.com',
95 'content': 'Am watching thou',
96 'check': true,
97 'choice': 'no',
98 'topic': 'bar',
99 'file': fpath,
100 'checklist[]': ['1', '3']
101 });
102 test.assertField('email', 'chuck@norris.com', 'Tester.assertField() works as expected with inputs');
103 test.assertField('content', 'Am watching thou', 'Tester.assertField() works as expected with textarea');
104 test.assertField('check', true, 'Tester.assertField() works as expected with checkboxes');
105 test.assertField('choice', 'no', 'Tester.assertField() works as expected with radios');
106 test.assertField('topic', 'bar', 'Tester.assertField() works as expected with selects');
107 test.assertField('file', 'C:\\fakepath\\README.md', 'Tester.assertField() works as expected with file inputs');
108 test.assertField('checklist[]', ['1', '3'], 'Tester.assertField() works as expected with check lists');
109 }).run(function() {
110 test.done();
111 });
187 }); 112 });
......
...@@ -3,15 +3,15 @@ ...@@ -3,15 +3,15 @@
3 var tester = require('tester'); 3 var tester = require('tester');
4 var testpage = require('webpage').create(); 4 var testpage = require('webpage').create();
5 5
6 casper.test.begin('XUnitReporter() initialization', 1, function suite() { 6 casper.test.begin('XUnitReporter() initialization', 1, function suite(test) {
7 var xunit = require('xunit').create(); 7 var xunit = require('xunit').create();
8 var results = new tester.TestSuiteResult(); 8 var results = new tester.TestSuiteResult();
9 xunit.setResults(results); 9 xunit.setResults(results);
10 this.assertTruthy(xunit.getXML()); 10 test.assertTruthy(xunit.getXML());
11 this.done(); 11 test.done();
12 }); 12 });
13 13
14 casper.test.begin('XUnitReporter() can hold test suites', 4, function suite() { 14 casper.test.begin('XUnitReporter() can hold test suites', 4, function suite(test) {
15 var xunit = require('xunit').create(); 15 var xunit = require('xunit').create();
16 var results = new tester.TestSuiteResult(); 16 var results = new tester.TestSuiteResult();
17 var suite1 = new tester.TestCaseResult({ 17 var suite1 = new tester.TestCaseResult({
...@@ -26,16 +26,16 @@ casper.test.begin('XUnitReporter() can hold test suites', 4, function suite() { ...@@ -26,16 +26,16 @@ casper.test.begin('XUnitReporter() can hold test suites', 4, function suite() {
26 results.push(suite2); 26 results.push(suite2);
27 xunit.setResults(results); 27 xunit.setResults(results);
28 casper.start().setContent(xunit.getXML()); 28 casper.start().setContent(xunit.getXML());
29 this.assertEvalEquals(function() { 29 test.assertEvalEquals(function() {
30 return __utils__.findAll('testsuite').length; 30 return __utils__.findAll('testsuite').length;
31 }, 2); 31 }, 2);
32 this.assertExists('testsuites[duration]'); 32 test.assertExists('testsuites[duration]');
33 this.assertExists('testsuite[name="foo"][package="foo"]'); 33 test.assertExists('testsuite[name="foo"][package="foo"]');
34 this.assertExists('testsuite[name="bar"][package="bar"]'); 34 test.assertExists('testsuite[name="bar"][package="bar"]');
35 this.done(); 35 test.done();
36 }); 36 });
37 37
38 casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, function suite() { 38 casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, function suite(test) {
39 var xunit = require('xunit').create(); 39 var xunit = require('xunit').create();
40 var results = new tester.TestSuiteResult(); 40 var results = new tester.TestSuiteResult();
41 var suite1 = new tester.TestCaseResult({ 41 var suite1 = new tester.TestCaseResult({
...@@ -51,11 +51,11 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, f ...@@ -51,11 +51,11 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, f
51 results.push(suite1); 51 results.push(suite1);
52 xunit.setResults(results); 52 xunit.setResults(results);
53 casper.start().setContent(xunit.getXML()); 53 casper.start().setContent(xunit.getXML());
54 this.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]'); 54 test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]');
55 casper.test.done(); 55 test.done();
56 }); 56 });
57 57
58 casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite() { 58 casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite(test) {
59 var xunit = require('xunit').create(); 59 var xunit = require('xunit').create();
60 var results = new tester.TestSuiteResult(); 60 var results = new tester.TestSuiteResult();
61 var suite1 = new tester.TestCaseResult({ 61 var suite1 = new tester.TestCaseResult({
...@@ -71,7 +71,7 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite( ...@@ -71,7 +71,7 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite(
71 results.push(suite1); 71 results.push(suite1);
72 xunit.setResults(results); 72 xunit.setResults(results);
73 casper.start().setContent(xunit.getXML()); 73 casper.start().setContent(xunit.getXML());
74 this.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]'); 74 test.assertExists('testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]');
75 this.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext'); 75 test.assertEquals(casper.getElementInfo('failure[type="footype"]').text, 'footext');
76 casper.test.done(); 76 test.done();
77 }); 77 });
......