Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
08625bd0
...
08625bd0e3884cac45e7b3b3816519e402cd1c13
authored
2012-12-28 13:43:07 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
migrated tester/asserts tests to new testing format
1 parent
af9dcbc2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
192 deletions
tests/suites/tester/assert.js
tests/suites/xunit.js
tests/suites/tester/assert.js
View file @
08625bd
/*global casper*/
/*jshint strict:false maxstatements:99*/
var
fs
=
require
(
'fs'
);
var
t
=
casper
.
test
;
casper
.
start
(
'tests/site/index.html'
,
function
()
{
t
.
comment
(
'Tester.assertTextExists()'
);
t
.
assertTextExists
(
'form'
,
'Tester.assertTextExists() checks that page body contains text'
);
t
.
comment
(
'Tester.assertTextExist()'
);
t
.
assertTextExist
(
'form'
,
'Tester.assertTextExist() checks that page body contains text [alias]'
);
t
.
comment
(
'Tester.assertTextDoesntExist()'
);
t
.
assertTextDoesntExist
(
'blah'
,
"Tester.assertTextDoesntExist() checks that page body doesn't contain provided text"
);
t
.
comment
(
'Tester.assertSelectorHasText()'
);
t
.
assertSelectorHasText
(
'h1'
,
'Title'
,
'Tester.assertSelectorHasText() works as expected'
);
t
.
comment
(
'Tester.assertSelectorDoesntHaveText()'
);
t
.
assertSelectorDoesntHaveText
(
'h1'
,
'Subtitle'
,
'Tester.assertSelectorDoesntHaveText() works as expected'
);
t
.
comment
(
'Tester.assert()'
);
t
.
assert
(
true
,
'Tester.assert() works as expected'
);
t
.
comment
(
'Tester.assertTrue()'
);
t
.
assertTrue
(
true
,
'Tester.assertTrue() works as expected [alias]'
);
t
.
comment
(
'Tester.assertTruthy()'
);
t
.
assertTruthy
(
'1'
,
'Tester.assertTruthy() works as expected'
);
t
.
comment
(
'Tester.assertFalsy()'
);
t
.
assertFalsy
(
''
,
'Tester.assertFalsy() works as expected'
);
t
.
comment
(
'Tester.assertNot()'
);
t
.
assertNot
(
false
,
'Tester.assertNot() works as expected'
);
t
.
comment
(
'Tester.assertEquals()'
);
t
.
assertEquals
(
true
,
true
,
'Tester.assertEquals() works as expected'
);
t
.
comment
(
'Tester.assertEqual()'
);
t
.
assertEqual
(
true
,
true
,
'Tester.assertEqual() works as expected [alias]'
);
t
.
comment
(
'Tester.assertNotEquals()'
);
t
.
assertNotEquals
(
true
,
false
,
'Tester.assertNotEquals() works as expected'
);
t
.
comment
(
'Tester.assertEval()'
);
t
.
assertEval
(
function
()
{
return
true
;
},
'Tester.assertEval() works as expected'
);
t
.
comment
(
'Tester.assertEvaluate()'
);
t
.
assertEvaluate
(
function
()
{
return
true
;
},
'Tester.assertEvaluate() works as expected [alias]'
);
t
.
comment
(
'Tester.assertEvalEquals()'
);
t
.
assertEvalEquals
(
function
()
{
return
42
;
},
42
,
'Tester.assertEvalEquals() works as expected'
);
t
.
comment
(
'Tester.assertEvalEqual()'
);
t
.
assertEvalEqual
(
function
()
{
return
42
;
},
42
,
'Tester.assertEvalEqual() works as expected [alias]'
);
t
.
comment
(
'Tester.assertExists()'
);
t
.
assertExists
(
'body'
,
'Tester.assertExists() works as expected'
);
t
.
comment
(
'Tester.assertExist()'
);
t
.
assertExist
(
'body'
,
'Tester.assertExist() works as expected [alias]'
);
t
.
comment
(
'Tester.assertSelectorExists()'
);
t
.
assertSelectorExists
(
'body'
,
'Tester.assertSelectorExists() works as expected [alias]'
);
t
.
comment
(
'Tester.assertSelectorExists()'
);
t
.
assertSelectorExist
(
'body'
,
'Tester.assertSelectorExist() works as expected [alias]'
);
t
.
comment
(
'Tester.assertDoesntExist()'
);
t
.
assertDoesntExist
(
'foobar'
,
'Tester.assertDoesntExist() works as expected'
);
t
.
comment
(
'Tester.assertNotExist()'
);
t
.
assertDoesntExist
(
'foobar'
,
'Tester.assertNotExist() works as expected [alias]'
);
t
.
comment
(
'Tester.assertHttpStatus()'
);
// using file:// protocol, HTTP status is always null
t
.
assertHttpStatus
(
200
,
'Tester.assertHttpStatus() works as expected'
);
t
.
comment
(
'Tester.assertMatch()'
);
t
.
assertMatch
(
"the lazy dog"
,
/lazy/
,
'Tester.assertMatch() works as expected'
);
t
.
comment
(
'Tester.assertMatches()'
);
t
.
assertMatches
(
"the lazy dog"
,
/lazy/
,
'Tester.assertMatches() works as expected [alias]'
);
t
.
comment
(
'Tester.assertRaises()'
);
t
.
assertRaises
(
function
()
{
throw
new
Error
(
'plop'
);
},
[],
'Tester.assertRaises() works as expected'
);
t
.
comment
(
'Tester.assertRaise()'
);
t
.
assertRaise
(
function
()
{
throw
new
Error
(
'plop'
);
},
[],
'Tester.assertRaise() works as expected [alias]'
);
t
.
comment
(
'Tester.assertThrows()'
);
t
.
assertThrows
(
function
()
{
throw
new
Error
(
'plop'
);
},
[],
'Tester.assertThrows() works as expected [alias]'
);
t
.
comment
(
'Tester.assertResourceExists()'
);
t
.
assertResourceExists
(
/index
\.
html/
,
'Tester.assertResourceExists() works as expected'
);
t
.
comment
(
'Tester.assertResourceExist()'
);
t
.
assertResourceExist
(
/index
\.
html/
,
'Tester.assertResourceExist() works as expected [alias]'
);
t
.
comment
(
'Tester.assertTitle()'
);
t
.
assertTitle
(
'CasperJS test index'
,
'Tester.assertTitle() works as expected'
);
t
.
comment
(
'Tester.assertTitleMatch()'
);
t
.
assertTitleMatch
(
/test index/
,
'Tester.assertTitleMatch() works as expected'
);
t
.
comment
(
'Tester.assertTitleMatches()'
);
t
.
assertTitleMatches
(
/test index/
,
'Tester.assertTitleMatches() works as expected [alias]'
);
t
.
comment
(
'Tester.assertType()'
);
t
.
assertType
(
"plop"
,
"string"
,
"Tester.assertType() works as expected"
);
t
.
comment
(
'Tester.assertUrlMatch()'
);
t
.
assertUrlMatch
(
/index
\.
html$/
,
"Tester.assertUrlMatch() works as expected"
);
t
.
comment
(
'Tester.assertUrlMatches()'
);
t
.
assertUrlMatches
(
/index
\.
html$/
,
"Tester.assertUrlMatches() works as expected [alias]"
);
t
.
comment
(
'Tester.assertVisible()'
);
t
.
assertVisible
(
'img'
,
'Tester.assertVisible() works as expected'
);
t
.
comment
(
'Tester.assertNotVisible()'
);
t
.
assertNotVisible
(
'p#hidden'
,
'Tester.assertNotVisible() works as expected'
);
t
.
comment
(
'Tester.assertInvisible()'
);
t
.
assertInvisible
(
'p#hidden'
,
'Tester.assertInvisible() works as expected [alias]'
);
});
casper
.
thenOpen
(
'tests/site/form.html'
,
function
()
{
t
.
comment
(
'Tester.assertField()'
);
t
.
comment
(
'1. Fill inputs'
);
var
fpath
=
phantom
.
libraryPath
+
'/README.md'
;
this
.
fill
(
'form[action="result.html"]'
,
{
'email'
:
'chuck@norris.com'
,
'content'
:
'Am watching thou'
,
'check'
:
true
,
'choice'
:
'no'
,
'topic'
:
'bar'
,
'file'
:
fpath
,
'checklist[]'
:
[
'1'
,
'3'
]
casper
.
test
.
begin
(
'Common assertions tests'
,
40
,
function
(
test
)
{
casper
.
start
(
'tests/site/index.html'
,
function
()
{
test
.
assertTextExists
(
'form'
,
'Tester.assertTextExists() checks that page body contains text'
);
test
.
assertTextExist
(
'form'
,
'Tester.assertTextExist() checks that page body contains text [alias]'
);
test
.
assertTextDoesntExist
(
'blah'
,
"Tester.assertTextDoesntExist() checks that page body doesn't contain provided text"
);
test
.
assertSelectorHasText
(
'h1'
,
'Title'
,
'Tester.assertSelectorHasText() works as expected'
);
test
.
assertSelectorDoesntHaveText
(
'h1'
,
'Subtitle'
,
'Tester.assertSelectorDoesntHaveText() works as expected'
);
test
.
assert
(
true
,
'Tester.assert() works as expected'
);
test
.
assertTrue
(
true
,
'Tester.assertTrue() works as expected [alias]'
);
test
.
assertTruthy
(
'1'
,
'Tester.assertTruthy() works as expected'
);
test
.
assertFalsy
(
''
,
'Tester.assertFalsy() works as expected'
);
test
.
assertNot
(
false
,
'Tester.assertNot() works as expected'
);
test
.
assertEquals
(
true
,
true
,
'Tester.assertEquals() works as expected'
);
test
.
assertEqual
(
true
,
true
,
'Tester.assertEqual() works as expected [alias]'
);
test
.
assertNotEquals
(
true
,
false
,
'Tester.assertNotEquals() works as expected'
);
test
.
assertEval
(
function
()
{
return
true
;
},
'Tester.assertEval() works as expected'
);
test
.
assertEvaluate
(
function
()
{
return
true
;
},
'Tester.assertEvaluate() works as expected [alias]'
);
test
.
assertEvalEquals
(
function
()
{
return
42
;
},
42
,
'Tester.assertEvalEquals() works as expected'
);
test
.
assertEvalEqual
(
function
()
{
return
42
;
},
42
,
'Tester.assertEvalEqual() works as expected [alias]'
);
test
.
assertExists
(
'body'
,
'Tester.assertExists() works as expected'
);
test
.
assertExist
(
'body'
,
'Tester.assertExist() works as expected [alias]'
);
test
.
assertSelectorExists
(
'body'
,
'Tester.assertSelectorExists() works as expected [alias]'
);
test
.
assertSelectorExist
(
'body'
,
'Tester.assertSelectorExist() works as expected [alias]'
);
test
.
assertDoesntExist
(
'foobar'
,
'Tester.assertDoesntExist() works as expected'
);
test
.
assertDoesntExist
(
'foobar'
,
'Tester.assertNotExist() works as expected [alias]'
);
// using file:// protocol, HTTP status is always null
test
.
assertHttpStatus
(
200
,
'Tester.assertHttpStatus() works as expected'
);
test
.
assertMatch
(
"the lazy dog"
,
/lazy/
,
'Tester.assertMatch() works as expected'
);
test
.
assertMatches
(
"the lazy dog"
,
/lazy/
,
'Tester.assertMatches() works as expected [alias]'
);
test
.
assertRaises
(
function
()
{
throw
new
Error
(
'plop'
);
},
[],
'Tester.assertRaises() works as expected'
);
test
.
assertRaise
(
function
()
{
throw
new
Error
(
'plop'
);
},
[],
'Tester.assertRaise() works as expected [alias]'
);
test
.
assertThrows
(
function
()
{
throw
new
Error
(
'plop'
);
},
[],
'Tester.assertThrows() works as expected [alias]'
);
test
.
assertResourceExists
(
/index
\.
html/
,
'Tester.assertResourceExists() works as expected'
);
test
.
assertResourceExist
(
/index
\.
html/
,
'Tester.assertResourceExist() works as expected [alias]'
);
test
.
assertTitle
(
'CasperJS test index'
,
'Tester.assertTitle() works as expected'
);
test
.
assertTitleMatch
(
/test index/
,
'Tester.assertTitleMatch() works as expected'
);
test
.
assertTitleMatches
(
/test index/
,
'Tester.assertTitleMatches() works as expected [alias]'
);
test
.
assertType
(
"plop"
,
"string"
,
"Tester.assertType() works as expected"
);
test
.
assertUrlMatch
(
/index
\.
html$/
,
"Tester.assertUrlMatch() works as expected"
);
test
.
assertUrlMatches
(
/index
\.
html$/
,
"Tester.assertUrlMatches() works as expected [alias]"
);
test
.
assertVisible
(
'img'
,
'Tester.assertVisible() works as expected'
);
test
.
assertNotVisible
(
'p#hidden'
,
'Tester.assertNotVisible() works as expected'
);
test
.
assertInvisible
(
'p#hidden'
,
'Tester.assertInvisible() works as expected [alias]'
);
}).
run
(
function
()
{
test
.
done
();
});
t
.
assertField
(
'email'
,
'chuck@norris.com'
,
'Tester.assertField() works as expected with inputs'
);
t
.
assertField
(
'content'
,
'Am watching thou'
,
'Tester.assertField() works as expected with textarea'
);
t
.
assertField
(
'check'
,
true
,
'Tester.assertField() works as expected with checkboxes'
);
t
.
assertField
(
'choice'
,
'no'
,
'Tester.assertField() works as expected with radios'
);
t
.
assertField
(
'topic'
,
'bar'
,
'Tester.assertField() works as expected with selects'
);
t
.
assertField
(
'file'
,
'C:\\fakepath\\README.md'
,
'Tester.assertField() works as expected with file inputs'
);
t
.
assertField
(
'checklist[]'
,
[
'1'
,
'3'
],
'Tester.assertField() works as expected with check lists'
);
});
casper
.
reload
(
function
()
{
t
.
comment
(
'2. Unfill inputs'
);
this
.
fill
(
'form[action="result.html"]'
,
{
'email'
:
''
,
'content'
:
''
,
'check'
:
false
,
'choice'
:
''
,
'topic'
:
''
,
'file'
:
''
,
'checklist[]'
:
[]
casper
.
test
.
begin
(
'filled inputs'
,
7
,
function
(
test
)
{
casper
.
start
(
'tests/site/form.html'
,
function
()
{
this
.
fill
(
'form[action="result.html"]'
,
{
'email'
:
''
,
'content'
:
''
,
'check'
:
false
,
'choice'
:
''
,
'topic'
:
''
,
'file'
:
''
,
'checklist[]'
:
[]
});
test
.
assertField
(
'email'
,
''
,
'Tester.assertField() works as expected with inputs'
);
test
.
assertField
(
'content'
,
''
,
'Tester.assertField() works as expected with textarea'
);
test
.
assertField
(
'check'
,
false
,
'Tester.assertField() works as expected with checkboxes'
);
test
.
assertField
(
'choice'
,
null
,
'Tester.assertField() works as expected with radios'
);
test
.
assertField
(
'topic'
,
'foo'
,
'Tester.assertField() works as expected with selects'
);
test
.
assertField
(
'file'
,
''
,
'Tester.assertField() works as expected with file inputs'
);
test
.
assertField
(
'checklist[]'
,
[],
'Tester.assertField() works as expected with check lists'
);
}).
run
(
function
()
{
test
.
done
();
});
t
.
assertField
(
'email'
,
''
,
'Tester.assertField() works as expected with inputs'
);
t
.
assertField
(
'content'
,
''
,
'Tester.assertField() works as expected with textarea'
);
t
.
assertField
(
'check'
,
false
,
'Tester.assertField() works as expected with checkboxes'
);
t
.
assertField
(
'choice'
,
null
,
'Tester.assertField() works as expected with radios'
);
t
.
assertField
(
'topic'
,
'foo'
,
'Tester.assertField() works as expected with selects'
);
t
.
assertField
(
'file'
,
''
,
'Tester.assertField() works as expected with file inputs'
);
t
.
assertField
(
'checklist[]'
,
[],
'Tester.assertField() works as expected with check lists'
);
});
casper
.
run
(
function
()
{
t
.
done
(
54
);
casper
.
test
.
begin
(
'unfilled inputs'
,
7
,
function
(
test
)
{
var
fpath
=
phantom
.
libraryPath
+
'/README.md'
;
casper
.
start
(
'tests/site/form.html'
,
function
()
{
this
.
fill
(
'form[action="result.html"]'
,
{
'email'
:
'chuck@norris.com'
,
'content'
:
'Am watching thou'
,
'check'
:
true
,
'choice'
:
'no'
,
'topic'
:
'bar'
,
'file'
:
fpath
,
'checklist[]'
:
[
'1'
,
'3'
]
});
test
.
assertField
(
'email'
,
'chuck@norris.com'
,
'Tester.assertField() works as expected with inputs'
);
test
.
assertField
(
'content'
,
'Am watching thou'
,
'Tester.assertField() works as expected with textarea'
);
test
.
assertField
(
'check'
,
true
,
'Tester.assertField() works as expected with checkboxes'
);
test
.
assertField
(
'choice'
,
'no'
,
'Tester.assertField() works as expected with radios'
);
test
.
assertField
(
'topic'
,
'bar'
,
'Tester.assertField() works as expected with selects'
);
test
.
assertField
(
'file'
,
'C:\\fakepath\\README.md'
,
'Tester.assertField() works as expected with file inputs'
);
test
.
assertField
(
'checklist[]'
,
[
'1'
,
'3'
],
'Tester.assertField() works as expected with check lists'
);
}).
run
(
function
()
{
test
.
done
();
});
});
...
...
tests/suites/xunit.js
View file @
08625bd
...
...
@@ -3,15 +3,15 @@
var
tester
=
require
(
'tester'
);
var
testpage
=
require
(
'webpage'
).
create
();
casper
.
test
.
begin
(
'XUnitReporter() initialization'
,
1
,
function
suite
()
{
casper
.
test
.
begin
(
'XUnitReporter() initialization'
,
1
,
function
suite
(
test
)
{
var
xunit
=
require
(
'xunit'
).
create
();
var
results
=
new
tester
.
TestSuiteResult
();
xunit
.
setResults
(
results
);
t
his
.
assertTruthy
(
xunit
.
getXML
());
t
his
.
done
();
t
est
.
assertTruthy
(
xunit
.
getXML
());
t
est
.
done
();
});
casper
.
test
.
begin
(
'XUnitReporter() can hold test suites'
,
4
,
function
suite
()
{
casper
.
test
.
begin
(
'XUnitReporter() can hold test suites'
,
4
,
function
suite
(
test
)
{
var
xunit
=
require
(
'xunit'
).
create
();
var
results
=
new
tester
.
TestSuiteResult
();
var
suite1
=
new
tester
.
TestCaseResult
({
...
...
@@ -26,16 +26,16 @@ casper.test.begin('XUnitReporter() can hold test suites', 4, function suite() {
results
.
push
(
suite2
);
xunit
.
setResults
(
results
);
casper
.
start
().
setContent
(
xunit
.
getXML
());
t
his
.
assertEvalEquals
(
function
()
{
t
est
.
assertEvalEquals
(
function
()
{
return
__utils__
.
findAll
(
'testsuite'
).
length
;
},
2
);
t
his
.
assertExists
(
'testsuites[duration]'
);
t
his
.
assertExists
(
'testsuite[name="foo"][package="foo"]'
);
t
his
.
assertExists
(
'testsuite[name="bar"][package="bar"]'
);
t
his
.
done
();
t
est
.
assertExists
(
'testsuites[duration]'
);
t
est
.
assertExists
(
'testsuite[name="foo"][package="foo"]'
);
t
est
.
assertExists
(
'testsuite[name="bar"][package="bar"]'
);
t
est
.
done
();
});
casper
.
test
.
begin
(
'XUnitReporter() can hold a suite with a succesful test'
,
1
,
function
suite
()
{
casper
.
test
.
begin
(
'XUnitReporter() can hold a suite with a succesful test'
,
1
,
function
suite
(
test
)
{
var
xunit
=
require
(
'xunit'
).
create
();
var
results
=
new
tester
.
TestSuiteResult
();
var
suite1
=
new
tester
.
TestCaseResult
({
...
...
@@ -51,11 +51,11 @@ casper.test.begin('XUnitReporter() can hold a suite with a succesful test', 1, f
results
.
push
(
suite1
);
xunit
.
setResults
(
results
);
casper
.
start
().
setContent
(
xunit
.
getXML
());
t
his
.
assertExists
(
'testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]'
);
casper
.
test
.
done
();
t
est
.
assertExists
(
'testsuite[name="foo"][package="foo"][tests="1"][failures="0"] testcase[name="footext"]'
);
test
.
done
();
});
casper
.
test
.
begin
(
'XUnitReporter() can handle a failed test'
,
2
,
function
suite
()
{
casper
.
test
.
begin
(
'XUnitReporter() can handle a failed test'
,
2
,
function
suite
(
test
)
{
var
xunit
=
require
(
'xunit'
).
create
();
var
results
=
new
tester
.
TestSuiteResult
();
var
suite1
=
new
tester
.
TestCaseResult
({
...
...
@@ -71,7 +71,7 @@ casper.test.begin('XUnitReporter() can handle a failed test', 2, function suite(
results
.
push
(
suite1
);
xunit
.
setResults
(
results
);
casper
.
start
().
setContent
(
xunit
.
getXML
());
t
his
.
assertExists
(
'testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]'
);
t
his
.
assertEquals
(
casper
.
getElementInfo
(
'failure[type="footype"]'
).
text
,
'footext'
);
casper
.
test
.
done
();
t
est
.
assertExists
(
'testsuite[name="foo"][package="foo"][tests="1"][failures="1"] testcase[name="footext"] failure[type="footype"]'
);
t
est
.
assertEquals
(
casper
.
getElementInfo
(
'failure[type="footype"]'
).
text
,
'footext'
);
test
.
done
();
});
...
...
Please
register
or
sign in
to post a comment