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
244f1a9c
...
244f1a9c689226cedc2cc16f652b3514d90ec932
authored
2011-11-12 21:01:20 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
added Casper.back() and .forward() for navigating history
1 parent
4cb79a2c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
10 deletions
casper.js
tests/run.js
casper.js
View file @
244f1a9
...
...
@@ -89,6 +89,19 @@
*/
phantom
.
Casper
.
prototype
=
{
/**
* Go a step back in browser's history
*
* @return Casper
*/
back
:
function
()
{
return
this
.
then
(
function
(
self
)
{
self
.
evaluate
(
function
()
{
history
.
back
();
});
});
},
/**
* Encodes a resource using the base64 algorithm synchroneously using
* client-side XMLHttpRequest.
*
...
...
@@ -465,6 +478,19 @@
},
/**
* Go a step forward in browser's history
*
* @return Casper
*/
forward
:
function
(
then
)
{
return
this
.
then
(
function
(
self
)
{
self
.
evaluate
(
function
()
{
history
.
forward
();
});
});
},
/**
* Retrieve current document url.
*
* @return String
...
...
@@ -1250,8 +1276,8 @@
exporter
.
addSuccess
(
"unknown"
,
message
);
}
else
{
casper
.
echo
(
this
.
colorize
(
FAIL
,
'RED_BAR'
)
+
' '
+
this
.
formatMessage
(
message
,
'WARNING'
));
this
.
comment
(
'
got: '
+
testValue
);
this
.
comment
(
'
expected: '
+
expected
);
this
.
comment
(
' got: '
+
testValue
);
this
.
comment
(
' expected: '
+
expected
);
this
.
testResults
.
failed
++
;
exporter
.
addFailure
(
"unknown"
,
message
,
"test failed; expected: "
+
expected
+
"; got: "
+
testValue
,
"assertEquals"
);
}
...
...
@@ -1298,7 +1324,17 @@
* @param String message Test description
*/
this
.
assertMatch
=
function
(
subject
,
pattern
,
message
)
{
return
this
.
assert
(
pattern
.
test
(
subject
),
message
);
if
(
pattern
.
test
(
subject
))
{
casper
.
echo
(
this
.
colorize
(
PASS
,
'INFO'
)
+
' '
+
this
.
formatMessage
(
message
));
this
.
testResults
.
passed
++
;
exporter
.
addSuccess
(
"unknown"
,
message
);
}
else
{
casper
.
echo
(
this
.
colorize
(
FAIL
,
'RED_BAR'
)
+
' '
+
this
.
formatMessage
(
message
,
'WARNING'
));
this
.
comment
(
' subject: '
+
subject
);
this
.
comment
(
' pattern: '
+
pattern
.
toString
());
this
.
testResults
.
failed
++
;
exporter
.
addFailure
(
"unknown"
,
message
,
"test failed; subject: "
+
subject
+
"; pattern: "
+
pattern
.
toString
(),
"assertMatch"
);
}
};
/**
...
...
tests/run.js
View file @
244f1a9
...
...
@@ -186,11 +186,12 @@ casper.then(function(self) {
});
// Casper.wait()
var
start
=
new
Date
().
getTime
();
casper
.
wait
(
1000
,
function
(
self
)
{
var
waitStart
;
casper
.
then
(
function
()
{
waitStart
=
new
Date
().
getTime
();
}).
wait
(
1000
,
function
(
self
)
{
self
.
test
.
comment
(
'wait'
);
self
.
test
.
assert
(
new
Date
().
getTime
()
-
start
>
1000
,
'Casper.wait() can wait for a given amount of time'
);
self
.
test
.
assert
(
new
Date
().
getTime
()
-
waitStart
>
1000
,
'Casper.wait() can wait for a given amount of time'
);
// Casper.waitFor()
casper
.
thenOpen
(
'tests/site/waitFor.html'
,
function
(
self
)
{
casper
.
test
.
comment
(
'waitFor'
);
...
...
@@ -206,12 +207,29 @@ casper.wait(1000, function(self) {
});
});
// History
casper
.
thenOpen
(
'tests/site/page1.html'
)
.
thenOpen
(
'tests/site/page2.html'
)
.
thenOpen
(
'tests/site/page3.html'
)
.
back
()
.
then
(
function
(
self
)
{
self
.
test
.
comment
(
'navigating history backward'
);
self
.
test
.
assertMatch
(
self
.
getCurrentUrl
(),
/tests
\/
site
\/
page2
\.
html$/
,
'Casper.back() can go back an history step'
);
})
.
forward
()
.
then
(
function
(
self
)
{
self
.
test
.
comment
(
'navigating history forward'
);
self
.
test
.
assertMatch
(
self
.
getCurrentUrl
(),
/tests
\/
site
\/
page3
\.
html$/
,
'Casper.forward() can go forward an history step'
);
})
;
// run suite
casper
.
run
(
function
(
self
)
{
casper
.
test
.
comment
(
'history'
);
casper
.
test
.
assert
(
self
.
history
.
length
>
0
,
'Casper.history contains urls'
);
casper
.
test
.
assertMatch
(
self
.
history
[
0
],
/tests
\/
site
\/
index
\.
html$/
,
'Casper.history has the correct first url'
);
self
.
test
.
comment
(
'logging, again'
);
self
.
test
.
assertEquals
(
self
.
result
.
log
.
length
,
3
,
'log() logged messages'
);
self
.
test
.
comment
(
'history'
);
self
.
test
.
assert
(
self
.
history
.
length
>
0
,
'Casper.history contains urls'
);
self
.
test
.
assertMatch
(
self
.
history
[
0
],
/tests
\/
site
\/
index
\.
html$/
,
'Casper.history has the correct first url'
);
self
.
test
.
renderResults
(
true
,
0
,
save
);
});
...
...
Please
register
or
sign in
to post a comment