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
d3741b49
...
d3741b492c1ca03b25de711190cbcc41b7128949
authored
2011-10-10 13:23:33 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added more tests
1 parent
3622f3e2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
8 deletions
tests/assert.js
tests/run.js
tests/site/images/phantom.png
tests/site/index.html
tests/assert.js
View file @
d3741b4
...
...
@@ -37,8 +37,9 @@ phantom.Casper.extend({
renderResults
:
function
()
{
this
.
echo
(
"=========================================="
);
var
total
=
testResults
.
passed
+
testResults
.
failed
;
this
.
echo
(
total
+
' tests executed, '
+
testResults
.
passed
+
' passed, '
+
testResults
.
failed
+
' failed.'
);
var
total
=
testResults
.
passed
+
testResults
.
failed
,
status
=
testResults
.
failed
>
0
?
'FAIL'
:
'OK'
;
this
.
echo
(
status
+
': '
+
total
+
' tests executed, '
+
testResults
.
passed
+
' passed, '
+
testResults
.
failed
+
' failed.'
);
this
.
exit
();
}
});
\ No newline at end of file
...
...
tests/run.js
View file @
d3741b4
...
...
@@ -13,25 +13,44 @@ phantom.args.forEach(function(arg) {
}
});
// Casper#log()
var
oldLevel
=
casper
.
options
.
logLevel
;
casper
.
options
.
logLevel
=
'info'
;
casper
.
options
.
verbose
=
false
;
casper
.
log
(
'foo'
,
'info'
);
casper
.
assert
(
casper
.
result
.
log
.
some
(
function
(
e
)
{
return
e
.
message
===
'foo'
&&
e
.
level
===
'info'
;
}),
'log() adds a log entry'
);
casper
.
options
.
logLevel
=
oldLevel
;
casper
.
options
.
verbose
=
true
;
// Casper#start()
casper
.
start
(
'tests/site/index.html'
,
function
(
self
)
{
self
.
assertEvalEquals
(
function
()
{
return
document
.
title
;
},
'CasperJS test index'
,
'start() casper can start itself an open an url'
);
self
.
click
(
'a:first-child'
);
var
image
=
self
.
base64encode
(
'file://'
+
phantom
.
libraryPath
+
'/site/images/phantom.png'
);
self
.
assertEquals
(
image
.
length
,
6160
,
'base64encode() can retrieve base64 contents'
);
self
.
click
(
'a[href="test.html"]'
);
});
casper
.
assert
(
casper
.
steps
.
length
===
1
,
'start() can add a new navigation step'
);
// Casper#then()
casper
.
then
(
function
(
self
)
{
self
.
assertEvalEquals
(
function
()
{
return
document
.
title
;
},
'CasperJS test target'
,
'click() casper can click on a text link and react when it is loaded'
);
self
.
click
(
'a
:first-child
'
);
},
'CasperJS test target'
,
'click() casper can click on a text link and react when it is loaded
1/2
'
);
self
.
click
(
'a
[href="form.html"]
'
);
});
casper
.
assert
(
casper
.
steps
.
length
===
2
,
'then() adds a new navigation step'
);
// Casper#fill()
casper
.
then
(
function
(
self
)
{
self
.
assertEvalEquals
(
function
()
{
return
document
.
title
;
},
'CasperJS test form'
,
'click() casper can click on a text link and react when it is loaded 2/2'
);
self
.
fill
(
'form[action="form.html"]'
,
{
email
:
'chuck@norris.com'
,
content
:
'Am watching thou'
,
...
...
@@ -50,10 +69,10 @@ casper.then(function(self) {
},
true
,
'fill() can check a form checkbox'
);
self
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="choice"][value="no"]'
).
checked
;
},
true
,
'fill() can check a form radio button'
);
},
true
,
'fill() can check a form radio button
1/2
'
);
self
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="choice"][value="
no
"]'
).
checked
;
},
true
,
'fill() can check a form radio button
'
);
return
document
.
querySelector
(
'input[name="choice"][value="
yes
"]'
).
checked
;
},
false
,
'fill() can check a form radio button 2/2
'
);
self
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="file"]'
).
files
.
length
===
1
;
},
true
,
'fill() can select a file to upload'
);
...
...
@@ -63,5 +82,6 @@ casper.then(function(self) {
});
casper
.
run
(
function
(
self
)
{
self
.
assert
(
self
.
result
.
log
.
length
>
0
,
'log() logged messages'
);
self
.
renderResults
();
});
...
...
tests/site/images/phantom.png
0 → 100644
View file @
d3741b4
4.51 KB
tests/site/index.html
View file @
d3741b4
...
...
@@ -5,6 +5,7 @@
<title>
CasperJS test index
</title>
</head>
<body>
<img
src=
"images/phantom.png"
/>
<a
href=
"test.html"
>
test
</a>
<a
href=
"form.html"
>
form
</a>
</body>
...
...
Please
register
or
sign in
to post a comment