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
123f3128
...
123f3128ca2a1860b9ea3fb316cb2914582203e0
authored
2012-06-05 11:05:41 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
initial attempt at bringing default test messages
1 parent
3d2cbd5f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
33 deletions
modules/casper.js
modules/tester.js
modules/xunit.js
modules/casper.js
View file @
123f312
...
...
@@ -325,9 +325,7 @@ Casper.prototype.createStep = function createStep(fn, options) {
* @return Casper
*/
Casper
.
prototype
.
debugHTML
=
function
debugHTML
()
{
this
.
echo
(
this
.
evaluate
(
function
_evaluate
()
{
return
document
.
body
.
innerHTML
;
}));
this
.
echo
(
this
.
page
.
content
);
return
this
;
};
...
...
@@ -739,7 +737,7 @@ Casper.prototype.log = function log(message, level, space) {
Casper
.
prototype
.
mouseEvent
=
function
mouseEvent
(
type
,
selector
)
{
this
.
log
(
"Mouse event '"
+
type
+
"' on selector: "
+
selector
,
"debug"
);
if
(
!
this
.
exists
(
selector
))
{
throw
new
CasperError
(
"Cannot dispatch an event on nonexistent selector: "
+
selector
);
throw
new
CasperError
(
f
(
"Cannot dispatch %s event on nonexistent selector: %s"
,
type
,
selector
)
);
}
var
eventSuccess
=
this
.
evaluate
(
function
(
type
,
selector
)
{
return
__utils__
.
mouseEvent
(
type
,
selector
);
...
...
@@ -752,7 +750,7 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
try
{
this
.
mouse
.
processEvent
(
type
,
selector
);
}
catch
(
e
)
{
this
.
log
(
f
(
"Couldn't emulate
event '%s'
on %s: %s"
,
type
,
selector
,
e
),
"error"
);
this
.
log
(
f
(
"Couldn't emulate
'%s' event
on %s: %s"
,
type
,
selector
,
e
),
"error"
);
return
false
;
}
}
...
...
modules/tester.js
View file @
123f312
...
...
@@ -28,12 +28,15 @@
*
*/
/*global exports:false, phantom:false, require:false, CasperError:false*/
var
fs
=
require
(
'fs'
);
var
events
=
require
(
'events'
);
var
utils
=
require
(
'utils'
);
var
f
=
utils
.
format
;
exports
.
create
=
function
create
(
casper
,
options
)
{
"use strict"
;
return
new
Tester
(
casper
,
options
);
};
...
...
@@ -44,6 +47,8 @@ exports.create = function create(casper, options) {
* @param Object|null options Options object
*/
var
Tester
=
function
Tester
(
casper
,
options
)
{
"use strict"
;
if
(
!
utils
.
isCasperObject
(
casper
))
{
throw
new
CasperError
(
"Tester needs a Casper instance"
);
}
...
...
@@ -86,15 +91,17 @@ var Tester = function Tester(casper, options) {
this
.
on
(
'fail'
,
function
onFail
(
failure
)
{
// export
this
.
exporter
.
addFailure
(
fs
.
absolute
(
failure
.
file
),
failure
.
message
,
failure
.
details
||
"test failed"
,
failure
.
type
||
"unknown"
);
this
.
exporter
.
addFailure
(
fs
.
absolute
(
failure
.
file
),
failure
.
message
||
failure
.
standard
,
failure
.
standard
||
"test failed"
,
failure
.
type
||
"unknown"
);
this
.
testResults
.
failures
.
push
(
failure
);
// special printing
if
(
failure
.
type
)
{
this
.
comment
(
' type: '
+
failure
.
type
);
}
if
(
failure
.
details
)
{
this
.
comment
(
' details: '
+
failure
.
details
);
}
if
(
failure
.
values
&&
Object
.
keys
(
failure
.
values
).
length
>
0
)
{
for
(
var
name
in
failure
.
values
)
{
this
.
comment
(
' '
+
name
+
': '
+
utils
.
serialize
(
failure
.
values
[
name
]));
...
...
@@ -121,7 +128,7 @@ var Tester = function Tester(casper, options) {
return
this
.
processAssertionResult
(
utils
.
mergeObjects
({
success
:
subject
===
true
,
type
:
"assert"
,
details
:
"Subject's not a strict boolean
true"
,
standard
:
"Subject is strictly
true"
,
message
:
message
,
file
:
this
.
currentTestFile
,
values
:
{
...
...
@@ -141,7 +148,7 @@ var Tester = function Tester(casper, options) {
this
.
assertEquals
=
this
.
assertEqual
=
function
assertEquals
(
subject
,
expected
,
message
)
{
return
this
.
assert
(
this
.
testEquals
(
subject
,
expected
),
message
,
{
type
:
"assertEquals"
,
details
:
"Subject didn't equal
the expected value"
,
standard
:
"Subject equals
the expected value"
,
values
:
{
subject
:
subject
,
expected
:
expected
...
...
@@ -160,7 +167,7 @@ var Tester = function Tester(casper, options) {
this
.
assertNotEquals
=
function
assertNotEquals
(
subject
,
shouldnt
,
message
)
{
return
this
.
assert
(
!
this
.
testEquals
(
subject
,
shouldnt
),
message
,
{
type
:
"assertNotEquals"
,
details
:
"Subject actually equals to
what it shouldn't be"
,
standard
:
"Subject doesn't equal
what it shouldn't be"
,
values
:
{
subject
:
subject
,
shouldnt
:
shouldnt
...
...
@@ -179,7 +186,7 @@ var Tester = function Tester(casper, options) {
this
.
assertEval
=
this
.
assertEvaluate
=
function
assertEval
(
fn
,
message
,
params
)
{
return
this
.
assert
(
casper
.
evaluate
(
fn
,
params
),
message
,
{
type
:
"assertEval"
,
details
:
"Function didn't evaluate to
true"
,
standard
:
"Evaluated function returns
true"
,
values
:
{
fn
:
fn
,
params
:
params
...
...
@@ -201,7 +208,7 @@ var Tester = function Tester(casper, options) {
var
subject
=
casper
.
evaluate
(
fn
,
params
);
return
this
.
assert
(
this
.
testEquals
(
subject
,
expected
),
message
,
{
type
:
"assertEvalEquals"
,
details
:
"Evaluated function didn't return
the expected value"
,
standard
:
"Evaluated function returns
the expected value"
,
values
:
{
fn
:
fn
,
params
:
params
,
...
...
@@ -222,7 +229,7 @@ var Tester = function Tester(casper, options) {
this
.
assertExists
=
this
.
assertExist
=
this
.
assertSelectorExists
=
this
.
assertSelectorExist
=
function
assertExists
(
selector
,
message
)
{
return
this
.
assert
(
casper
.
exists
(
selector
),
message
,
{
type
:
"assertExists"
,
details
:
f
(
"No element matching selector %s was found
"
,
selector
),
standard
:
f
(
"Found an element matching %s
"
,
selector
),
values
:
{
selector
:
selector
}
...
...
@@ -240,7 +247,7 @@ var Tester = function Tester(casper, options) {
this
.
assertDoesntExist
=
this
.
assertNotExists
=
function
assertDoesntExist
(
selector
,
message
)
{
return
this
.
assert
(
!
casper
.
exists
(
selector
),
message
,
{
type
:
"assertDoesntExist"
,
details
:
f
(
"At least one element matching selector %s wa
s found"
,
selector
),
standard
:
f
(
"No element matching selector %s i
s found"
,
selector
),
values
:
{
selector
:
selector
}
...
...
@@ -258,7 +265,7 @@ var Tester = function Tester(casper, options) {
var
currentHTTPStatus
=
casper
.
currentHTTPStatus
;
return
this
.
assert
(
this
.
testEquals
(
casper
.
currentHTTPStatus
,
status
),
message
,
{
type
:
"assertHttpStatus"
,
details
:
f
(
"HTTP status code is not %s, but %s"
,
status
,
currentHTTPS
tatus
),
standard
:
f
(
"HTTP status code is %s"
,
s
tatus
),
values
:
{
current
:
currentHTTPStatus
,
expected
:
status
...
...
@@ -277,7 +284,7 @@ var Tester = function Tester(casper, options) {
this
.
assertMatch
=
this
.
assertMatches
=
function
assertMatch
(
subject
,
pattern
,
message
)
{
return
this
.
assert
(
pattern
.
test
(
subject
),
message
,
{
type
:
"assertMatch"
,
details
:
"Subject didn't match
the provided pattern"
,
standard
:
"Subject matches
the provided pattern"
,
values
:
{
subject
:
subject
,
pattern
:
pattern
...
...
@@ -295,7 +302,7 @@ var Tester = function Tester(casper, options) {
this
.
assertNot
=
function
assertNot
(
condition
,
message
)
{
return
this
.
assert
(
!
condition
,
message
,
{
type
:
"assertNot"
,
details
:
"The condition is not
falsy"
,
standard
:
"Subject is
falsy"
,
values
:
{
condition
:
condition
}
...
...
@@ -314,7 +321,7 @@ var Tester = function Tester(casper, options) {
this
.
assertRaises
=
this
.
assertRaise
=
this
.
assertThrows
=
function
assertRaises
(
fn
,
args
,
message
)
{
var
context
=
{
type
:
"assertRaises"
,
details
:
"Function didn't raise any
error"
standard
:
"Function raises an
error"
};
try
{
fn
.
apply
(
null
,
args
);
...
...
@@ -338,7 +345,7 @@ var Tester = function Tester(casper, options) {
this
.
assertResourceExists
=
this
.
assertResourceExist
=
function
assertResourceExists
(
test
,
message
)
{
return
this
.
assert
(
casper
.
resourceExists
(
test
),
message
,
{
type
:
"assertResourceExists"
,
details
:
"Resource was not
found"
,
standard
:
"Expected resource has been
found"
,
values
:
{
test
:
test
}
...
...
@@ -355,10 +362,10 @@ var Tester = function Tester(casper, options) {
this
.
assertTextExists
=
this
.
assertTextExist
=
function
assertTextExists
(
text
,
message
)
{
var
textFound
=
(
casper
.
evaluate
(
function
_evaluate
()
{
return
document
.
body
.
innerText
;
}).
indexOf
(
text
)
!=
-
1
);
}).
indexOf
(
text
)
!=
=
-
1
);
return
this
.
assert
(
textFound
,
message
,
{
type
:
"assertTextExists"
,
details
:
"Text was not found within the document body textual contents
"
,
standard
:
"Found expected text within the document body
"
,
values
:
{
text
:
text
}
...
...
@@ -376,7 +383,7 @@ var Tester = function Tester(casper, options) {
var
currentTitle
=
casper
.
getTitle
();
return
this
.
assert
(
this
.
testEquals
(
currentTitle
,
expected
),
message
,
{
type
:
"assertTitle"
,
details
:
"Page title is not the one expected"
,
standard
:
f
(
'Page title is "%s"'
,
expected
)
,
values
:
{
subject
:
currentTitle
,
expected
:
expected
...
...
@@ -396,7 +403,7 @@ var Tester = function Tester(casper, options) {
var
actual
=
utils
.
betterTypeOf
(
subject
);
return
this
.
assert
(
this
.
testEquals
(
actual
,
type
),
message
,
{
type
:
"assertType"
,
details
:
f
(
"Expected type %s, got %s"
,
typeof
subject
,
actual
),
standard
:
f
(
'Subject type is "%s"'
,
type
),
values
:
{
subject
:
subject
,
type
:
type
,
...
...
@@ -417,7 +424,7 @@ var Tester = function Tester(casper, options) {
var
currentUrl
=
casper
.
getCurrentUrl
();
return
this
.
assert
(
pattern
.
test
(
currentUrl
),
message
,
{
type
:
"assertUrlMatch"
,
details
:
"Current url did not match
the provided pattern"
,
standard
:
"Current url matches
the provided pattern"
,
values
:
{
currentUrl
:
currentUrl
,
pattern
:
pattern
...
...
@@ -492,7 +499,7 @@ var Tester = function Tester(casper, options) {
this
.
fail
=
function
fail
(
message
)
{
return
this
.
assert
(
false
,
message
,
{
type
:
"fail"
,
details
:
"explicit call to fail()"
standard
:
"explicit call to fail()"
});
};
...
...
@@ -552,7 +559,7 @@ var Tester = function Tester(casper, options) {
this
.
pass
=
function
pass
(
message
)
{
return
this
.
assert
(
true
,
message
,
{
type
:
"pass"
,
details
:
"explicit call to pass()"
standard
:
"explicit call to pass()"
});
};
...
...
@@ -576,7 +583,8 @@ var Tester = function Tester(casper, options) {
status
=
this
.
options
.
failText
;
this
.
testResults
.
failed
++
;
}
casper
.
echo
([
this
.
colorize
(
status
,
style
),
this
.
formatMessage
(
result
.
message
)].
join
(
' '
));
var
message
=
result
.
message
||
result
.
standard
;
casper
.
echo
([
this
.
colorize
(
status
,
style
),
this
.
formatMessage
(
message
)].
join
(
' '
));
this
.
emit
(
eventName
,
result
);
return
result
;
};
...
...
modules/xunit.js
View file @
123f312
...
...
@@ -27,24 +27,26 @@
* DEALINGS IN THE SOFTWARE.
*
*/
/*global exports, phantom, require, CasperError*/
var
utils
=
require
(
'utils'
);
var
fs
=
require
(
'fs'
);
exports
.
create
=
function
create
()
{
return
new
XUnitExporter
();
"use strict"
;
return
new
this
.
XUnitExporter
();
};
/**
* JUnit XML (xUnit) exporter for test results.
*
*/
XUnitExporter
=
function
XUnitExporter
()
{
function
XUnitExporter
()
{
"use strict"
;
this
.
_xml
=
utils
.
node
(
'testsuite'
);
this
.
_xml
.
toString
=
function
toString
()
{
return
this
.
outerHTML
;
// ouch
};
}
;
}
exports
.
XUnitExporter
=
XUnitExporter
;
/**
...
...
@@ -54,6 +56,7 @@ exports.XUnitExporter = XUnitExporter;
* @param String name
*/
XUnitExporter
.
prototype
.
addSuccess
=
function
addSuccess
(
classname
,
name
)
{
"use strict"
;
this
.
_xml
.
appendChild
(
utils
.
node
(
'testcase'
,
{
classname
:
generateClassName
(
classname
),
name
:
name
...
...
@@ -69,6 +72,7 @@ XUnitExporter.prototype.addSuccess = function addSuccess(classname, name) {
* @param String type
*/
XUnitExporter
.
prototype
.
addFailure
=
function
addFailure
(
classname
,
name
,
message
,
type
)
{
"use strict"
;
var
fnode
=
utils
.
node
(
'testcase'
,
{
classname
:
generateClassName
(
classname
),
name
:
name
...
...
@@ -91,6 +95,7 @@ XUnitExporter.prototype.addFailure = function addFailure(classname, name, messag
* @return String
*/
function
generateClassName
(
classname
)
{
"use strict"
;
classname
=
classname
.
replace
(
phantom
.
casperPath
,
""
).
trim
();
var
script
=
classname
||
phantom
.
casperScript
;
if
(
script
.
indexOf
(
fs
.
workingDirectory
)
===
0
)
{
...
...
@@ -111,5 +116,6 @@ function generateClassName(classname) {
* @return HTMLElement
*/
XUnitExporter
.
prototype
.
getXML
=
function
getXML
()
{
"use strict"
;
return
this
.
_xml
;
};
...
...
Please
register
or
sign in
to post a comment