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
6bf71011
...
6bf710114963065b367276ae5f1259a76522195c
authored
2011-12-02 10:24:29 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
better error handling for Casper.getGlobal()
1 parent
11a936d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
8 deletions
casper.js
tests/run.js
tests/site/global.html
casper.js
View file @
6bf7101
...
...
@@ -515,9 +515,21 @@
* @return mixed
*/
getGlobal
:
function
(
name
)
{
return
this
.
evaluate
(
function
()
{
return
window
[
window
.
__casper_params__
.
name
];
var
result
=
this
.
evaluate
(
function
()
{
var
name
=
window
.
__casper_params__
.
name
;
var
result
=
{};
try
{
result
.
value
=
JSON
.
stringify
(
window
[
name
]);
}
catch
(
e
)
{
result
.
error
=
'Unable to JSON encode window.'
+
name
+
': '
+
e
;
}
return
result
;
},
{
'name'
:
name
});
if
(
result
.
error
)
{
throw
result
.
error
;
}
else
{
return
JSON
.
parse
(
result
.
value
);
}
},
/**
...
...
tests/run.js
View file @
6bf7101
...
...
@@ -134,9 +134,9 @@ casper.then(function(self) {
return
document
.
querySelector
(
'input[name="file"]'
).
files
.
length
===
1
;
},
true
,
'Casper.fill() can select a file to upload'
);
self
.
test
.
assertEvalEquals
(
function
()
{
return
document
.
querySelector
(
'input[name="checklist[]"][value="1"]'
).
checked
&&
!
document
.
querySelector
(
'input[name="checklist[]"][value="2"]'
).
checked
&&
document
.
querySelector
(
'input[name="checklist[]"][value="3"]'
).
checked
return
(
document
.
querySelector
(
'input[name="checklist[]"][value="1"]'
).
checked
&&
!
document
.
querySelector
(
'input[name="checklist[]"][value="2"]'
).
checked
&&
document
.
querySelector
(
'input[name="checklist[]"][value="3"]'
).
checked
);
},
true
,
'Casper.fill() can fill a list of checkboxes'
);
self
.
click
(
'input[type="submit"]'
);
});
...
...
@@ -216,7 +216,8 @@ casper.then(function() {
// Casper.getGlobal()
casper
.
thenOpen
(
'tests/site/global.html'
,
function
(
self
)
{
self
.
test
.
comment
(
'Casper.getGlobal()'
);
self
.
test
.
assertEquals
(
self
.
getGlobal
(
'myGlobal'
),
'awesome string'
,
'Casper.getGlobal() can retrieve a remote global variable'
)
self
.
test
.
assertEquals
(
self
.
getGlobal
(
'myGlobal'
),
'awesome string'
,
'Casper.getGlobal() can retrieve a remote global variable'
);
self
.
test
.
assertRaises
(
self
.
getGlobal
,
[
'myUnencodableGlobal'
],
'Casper.getGlobal() does not fail trying to encode an unencodable global'
);
});
// Casper.options.onStepComplete
...
...
@@ -234,13 +235,13 @@ casper.then(function(self) {
self
.
options
.
onResourceReceived
=
function
(
self
,
resource
)
{
self
.
test
.
comment
(
'Casper.options.onResourceReceived()'
);
self
.
test
.
assertType
(
resource
,
'object'
,
'Casper.options.onResourceReceived() retrieve a resource object'
);
self
.
test
.
assert
(
'status'
in
resource
,
'Casper.options.onResourceReceived() retrieve a valid resource object'
)
self
.
test
.
assert
(
'status'
in
resource
,
'Casper.options.onResourceReceived() retrieve a valid resource object'
)
;
self
.
options
.
onResourceReceived
=
null
;
};
self
.
options
.
onResourceRequested
=
function
(
self
,
request
)
{
self
.
test
.
comment
(
'Casper.options.onResourceRequested()'
);
self
.
test
.
assertType
(
request
,
'object'
,
'Casper.options.onResourceRequested() retrieve a request object'
);
self
.
test
.
assert
(
'method'
in
request
,
'Casper.options.onResourceRequested() retrieve a valid request object'
)
self
.
test
.
assert
(
'method'
in
request
,
'Casper.options.onResourceRequested() retrieve a valid request object'
)
;
self
.
options
.
onResourceRequested
=
null
;
};
self
.
thenOpen
(
'tests/site/page1.html'
);
...
...
tests/site/global.html
View file @
6bf7101
...
...
@@ -3,6 +3,7 @@
<body>
<script
type=
"text/javascript"
>
var
myGlobal
=
'awesome string'
;
var
myUnencodableGlobal
=
document
;
</script>
</body>
</html>
\ No newline at end of file
...
...
Please
register
or
sign in
to post a comment