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
a50f6991
...
a50f6991811d52d44682bbb8b7d44bbe62d7f4c0
authored
2014-04-19 16:06:19 +0200
by
Mickaël Andrieu
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge pull request #892 from r8k/841
check javascriptEnabled status in the page
2 parents
06d6dc2f
a5c7d0d5
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
64 additions
and
3 deletions
modules/casper.js
tests/suites/casper/evaluate.js
tests/suites/casper/open.js
tests/suites/casper/urls.js
modules/casper.js
View file @
a50f699
...
...
@@ -690,6 +690,10 @@ Casper.prototype.echo = function echo(text, style, pad) {
Casper
.
prototype
.
evaluate
=
function
evaluate
(
fn
,
context
)
{
"use strict"
;
this
.
checkStarted
();
// check whether javascript is enabled !!
if
(
this
.
options
.
pageSettings
.
javascriptEnabled
===
false
)
{
throw
new
CasperError
(
"evaluate() requires javascript to be enabled"
);
}
// preliminary checks
if
(
!
utils
.
isFunction
(
fn
)
&&
!
utils
.
isString
(
fn
))
{
// phantomjs allows functions defs as string
throw
new
CasperError
(
"evaluate() only accepts functions or strings"
);
...
...
@@ -980,9 +984,13 @@ Casper.prototype.getCurrentUrl = function getCurrentUrl() {
"use strict"
;
this
.
checkStarted
();
try
{
return
utils
.
decodeUrl
(
this
.
evaluate
(
function
_evaluate
()
{
return
document
.
location
.
href
;
}));
if
(
this
.
options
.
pageSettings
.
javascriptEnabled
===
false
)
{
return
this
.
page
.
url
;
}
else
{
return
utils
.
decodeUrl
(
this
.
evaluate
(
function
_evaluate
()
{
return
document
.
location
.
href
;
}));
}
}
catch
(
e
)
{
// most likely the current page object has been "deleted" (think closed popup)
if
(
/deleted QObject/
.
test
(
e
.
message
))
...
...
tests/suites/casper/evaluate.js
View file @
a50f699
...
...
@@ -110,3 +110,22 @@ casper.test.begin("evaluate() returns a value which can be altered", 1, function
test
.
done
();
});
});
// https://github.com/n1k0/casperjs/issues/841
casper
.
test
.
begin
(
"evaluate() with js disabled, throws error"
,
1
,
function
(
test
)
{
casper
.
options
.
pageSettings
.
javascriptEnabled
=
false
;
casper
.
start
().
then
(
function
()
{
function
getListResult
()
{
return
this
.
evaluate
(
function
()
{
return
[{
a
:
1
},
{
b
:
2
}];
});
}
test
.
assertThrows
(
getListResult
,
undefined
,
"Casper.evaluate() raises an error if JavaScript is disabled in the page"
);
});
casper
.
run
(
function
()
{
test
.
done
();
casper
.
options
.
pageSettings
.
javascriptEnabled
=
true
;
});
});
\ No newline at end of file
...
...
tests/suites/casper/open.js
View file @
a50f699
...
...
@@ -51,6 +51,26 @@ casper.test.begin('open() GET casing tests', 2, {
}
});
casper
.
test
.
begin
(
'open() (JS disabled) tests'
,
3
,
{
setUp
:
setUp
,
tearDown
:
tearDown
,
test
:
function
(
test
)
{
casper
.
options
.
pageSettings
.
javascriptEnabled
=
false
;
casper
.
open
(
'tests/site/alert.html'
).
then
(
function
()
{
test
.
pass
(
"Casper.open() can open and load a location using GET, with JS disabled"
);
test
.
assertEquals
(
usedSettings
,
{
method
:
"get"
},
"Casper.open() used the expected GET settings"
);
test
.
assertHttpStatus
(
200
,
"Response Code is 200"
);
});
casper
.
run
(
function
()
{
test
.
done
();
casper
.
options
.
pageSettings
.
javascriptEnabled
=
true
;
});
}
});
casper
.
test
.
begin
(
'open() POST tests'
,
2
,
{
setUp
:
setUp
,
tearDown
:
tearDown
,
...
...
tests/suites/casper/urls.js
View file @
a50f699
...
...
@@ -23,3 +23,17 @@ casper.test.begin('urls tests', 6, function(test) {
test
.
done
();
});
});
// https://github.com/n1k0/casperjs/issues/841
casper
.
test
.
begin
(
'url tests with javascript disabled'
,
1
,
function
(
test
)
{
casper
.
options
.
pageSettings
.
javascriptEnabled
=
false
;
casper
.
start
(
'tests/site/urls.html'
);
casper
.
then
(
function
()
{
test
.
assertMatch
(
this
.
getCurrentUrl
(),
/urls
\.
html$/
,
'Casper.getCurrentUrl() can work, with javascript disabled'
);
});
casper
.
run
(
function
()
{
test
.
done
();
casper
.
options
.
pageSettings
.
javascriptEnabled
=
true
;
});
});
...
...
Please
register
or
sign in
to post a comment