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
e468c0f8
...
e468c0f834d0c897d28e1f0285a765dd6e4d2b84
authored
2013-05-08 23:14:57 +0200
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
updated tests regarding phantomjs version used
1 parent
b44b82e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
94 deletions
tests/suites/casper/request.coffee
tests/suites/casper/request.coffee
View file @
e468c0f
...
...
@@ -2,97 +2,102 @@
#jshint strict:false
SERVER
=
'http://localhost:54321/'
ORIGINAL_URL
=
"tests/site/index.html"
CHANGED_URL
=
"tests/site/index.html?foo=bar"
setToTrueOnResourceRequested
=
false
setToTrueOnResourceReceived
=
false
requestURLRequested
=
''
requestURLReceived
=
''
onResourceRequested
=
(
casper
,
requestData
,
request
)
->
if
requestData
.
url
==
(
SERVER
+
ORIGINAL_URL
)
setToTrueOnResourceRequested
=
true
requestURLRequested
=
requestData
.
url
onResourceRequestedWithAbort
=
(
casper
,
requestData
,
request
)
->
if
requestData
.
url
==
(
SERVER
+
ORIGINAL_URL
)
request
.
abort
()
onResourceRequestedWithChangeURL
=
(
casper
,
requestData
,
request
)
->
if
requestData
.
url
==
(
SERVER
+
ORIGINAL_URL
)
request
.
changeUrl
(
SERVER
+
CHANGED_URL
)
onResourceReceived
=
(
casper
,
response
)
->
if
response
.
url
==
(
SERVER
+
ORIGINAL_URL
)
setToTrueOnResourceReceived
=
true
requestURLReceived
=
response
.
url
onResourceReceivedWithChangeURL
=
(
casper
,
response
)
->
if
response
.
url
==
(
SERVER
+
CHANGED_URL
)
requestURLReceived
=
response
.
url
setUp
=
(
test
)
->
casper
.
options
.
onResourceRequested
=
onResourceRequested
casper
.
options
.
onResourceReceived
=
onResourceReceived
casper
.
start
()
setUpWithAbort
=
(
test
)
->
casper
.
options
.
onResourceRequested
=
onResourceRequestedWithAbort
casper
.
options
.
onResourceReceived
=
onResourceReceived
casper
.
start
()
setUpWithChangeURL
=
(
test
)
->
casper
.
options
.
onResourceRequested
=
onResourceRequestedWithChangeURL
casper
.
options
.
onResourceReceived
=
onResourceReceivedWithChangeURL
casper
.
start
()
tearDown
=
(
test
)
->
setToTrueOnResourceRequested
=
false
setToTrueOnResourceReceived
=
false
casper
.
options
.
onResourceRequested
=
null
casper
.
options
.
onResourceReceived
=
null
casper
.
test
.
begin
"onResourceRequested tests without abort/override"
,
4
,
setUp
:
setUp
tearDown
:
tearDown
test
:
(
test
)
->
casper
.
open
(
ORIGINAL_URL
).
then
->
casper
.
wait
3000
,
->
test
.
assertEquals
setToTrueOnResourceRequested
,
true
,
"Casper.options.onResourceRequested called successfully"
test
.
assertEquals
requestURLRequested
,
SERVER
+
ORIGINAL_URL
,
"request url successfully recorded"
test
.
assertEquals
setToTrueOnResourceReceived
,
true
,
"Casper.options.onResourceReceived called successfully"
test
.
assertEquals
requestURLReceived
,
SERVER
+
ORIGINAL_URL
,
"response url successfully recorded"
casper
.
run
->
test
.
done
()
casper
.
test
.
begin
"onResourceRequested tests with request.abort()"
,
1
,
setUp
:
setUpWithAbort
tearDown
:
tearDown
test
:
(
test
)
->
casper
.
open
(
ORIGINAL_URL
).
then
->
casper
.
wait
3000
,
->
test
.
assertNotEquals
setToTrueOnResourceReceived
,
true
,
"Casper.options.onResourceReceived correctly never called"
casper
.
run
->
test
.
done
()
casper
.
test
.
begin
"onResourceRequested tests with request.changeUrl()"
,
1
,
setUp
:
setUpWithChangeURL
tearDown
:
tearDown
test
:
(
test
)
->
casper
.
open
(
ORIGINAL_URL
).
then
->
casper
.
wait
3000
,
->
test
.
assertEquals
requestURLReceived
,
SERVER
+
CHANGED_URL
,
"response url successfully changed"
casper
.
run
->
test
.
done
()
utils
=
require
"utils"
if
utils
.
ltVersion
(
phantom
.
version
,
'1.9.0'
)
casper
.
test
.
skip
(
6
,
'PhantomJS version <1.9.0 does not implement request.abort()'
)
casper
.
test
.
done
()
else
SERVER
=
'http://localhost:54321/'
ORIGINAL_URL
=
"tests/site/index.html"
CHANGED_URL
=
"tests/site/index.html?foo=bar"
setToTrueOnResourceRequested
=
false
setToTrueOnResourceReceived
=
false
requestURLRequested
=
''
requestURLReceived
=
''
onResourceRequested
=
(
casper
,
requestData
,
request
)
->
if
requestData
.
url
==
(
SERVER
+
ORIGINAL_URL
)
setToTrueOnResourceRequested
=
true
requestURLRequested
=
requestData
.
url
onResourceRequestedWithAbort
=
(
casper
,
requestData
,
request
)
->
if
requestData
.
url
==
(
SERVER
+
ORIGINAL_URL
)
request
.
abort
()
onResourceRequestedWithChangeURL
=
(
casper
,
requestData
,
request
)
->
if
requestData
.
url
==
(
SERVER
+
ORIGINAL_URL
)
request
.
changeUrl
(
SERVER
+
CHANGED_URL
)
onResourceReceived
=
(
casper
,
response
)
->
if
response
.
url
==
(
SERVER
+
ORIGINAL_URL
)
setToTrueOnResourceReceived
=
true
requestURLReceived
=
response
.
url
onResourceReceivedWithChangeURL
=
(
casper
,
response
)
->
if
response
.
url
==
(
SERVER
+
CHANGED_URL
)
requestURLReceived
=
response
.
url
setUp
=
(
test
)
->
casper
.
options
.
onResourceRequested
=
onResourceRequested
casper
.
options
.
onResourceReceived
=
onResourceReceived
casper
.
start
()
setUpWithAbort
=
(
test
)
->
casper
.
options
.
onResourceRequested
=
onResourceRequestedWithAbort
casper
.
options
.
onResourceReceived
=
onResourceReceived
casper
.
start
()
setUpWithChangeURL
=
(
test
)
->
casper
.
options
.
onResourceRequested
=
onResourceRequestedWithChangeURL
casper
.
options
.
onResourceReceived
=
onResourceReceivedWithChangeURL
casper
.
start
()
tearDown
=
(
test
)
->
setToTrueOnResourceRequested
=
false
setToTrueOnResourceReceived
=
false
casper
.
options
.
onResourceRequested
=
null
casper
.
options
.
onResourceReceived
=
null
casper
.
test
.
begin
"onResourceRequested tests without abort/override"
,
4
,
setUp
:
setUp
tearDown
:
tearDown
test
:
(
test
)
->
casper
.
open
(
ORIGINAL_URL
).
then
->
casper
.
wait
200
,
->
test
.
assertEquals
setToTrueOnResourceRequested
,
true
,
"Casper.options.onResourceRequested called successfully"
test
.
assertEquals
requestURLRequested
,
SERVER
+
ORIGINAL_URL
,
"request url successfully recorded"
test
.
assertEquals
setToTrueOnResourceReceived
,
true
,
"Casper.options.onResourceReceived called successfully"
test
.
assertEquals
requestURLReceived
,
SERVER
+
ORIGINAL_URL
,
"response url successfully recorded"
casper
.
run
->
test
.
done
()
casper
.
test
.
begin
"onResourceRequested tests with request.abort()"
,
1
,
setUp
:
setUpWithAbort
tearDown
:
tearDown
test
:
(
test
)
->
casper
.
open
(
ORIGINAL_URL
).
then
->
casper
.
wait
200
,
->
test
.
assertNotEquals
setToTrueOnResourceReceived
,
true
,
"Casper.options.onResourceReceived correctly never called"
casper
.
run
->
test
.
done
()
casper
.
test
.
begin
"onResourceRequested tests with request.changeUrl()"
,
1
,
setUp
:
setUpWithChangeURL
tearDown
:
tearDown
test
:
(
test
)
->
casper
.
open
(
ORIGINAL_URL
).
then
->
casper
.
wait
200
,
->
test
.
assertEquals
requestURLReceived
,
SERVER
+
CHANGED_URL
,
"response url successfully changed"
casper
.
run
->
test
.
done
()
...
...
Please
register
or
sign in
to post a comment