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
7c0343f0
...
7c0343f08ffb9f11c9309e73d19a01ff28ef3ce4
authored
2013-03-24 13:40:12 +0100
by
Nicolas Perriault
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
compat with phantomjs 1.9
1 parent
b87c8630
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
52 additions
and
28 deletions
modules/casper.js
modules/http.js
modules/tester.js
modules/utils.js
tests/suites/casper/headers.js
tests/suites/casper/history.js
tests/suites/casper/steps.js
tests/suites/http_status.js
modules/casper.js
View file @
7c0343f
...
...
@@ -133,7 +133,7 @@ var Casper = function Casper(options) {
this
.
popups
=
pagestack
.
create
();
// properties
this
.
checker
=
null
;
this
.
currentResponse
=
undefined
;
this
.
currentResponse
=
{}
;
this
.
currentUrl
=
'about:blank'
;
this
.
currentHTTPStatus
=
null
;
this
.
history
=
[];
...
...
@@ -1049,7 +1049,7 @@ Casper.prototype.handleReceivedResource = function(resource) {
return
;
}
this
.
currentHTTPStatus
=
null
;
this
.
currentResponse
=
undefined
;
this
.
currentResponse
=
{}
;
if
(
utils
.
isHTTPResource
(
resource
))
{
this
.
emit
(
'page.resource.received'
,
resource
);
this
.
currentResponse
=
resource
;
...
...
@@ -1503,6 +1503,7 @@ Casper.prototype.start = function start(location, then) {
this
.
emit
(
'starting'
);
this
.
log
(
'Starting...'
,
"info"
);
this
.
startTime
=
new
Date
().
getTime
();
this
.
currentResponse
=
{};
this
.
history
=
[];
this
.
popups
=
pagestack
.
create
();
this
.
steps
=
[];
...
...
modules/http.js
View file @
7c0343f
...
...
@@ -59,9 +59,10 @@ responseHeaders.prototype.get = function get(name){
};
/**
* Augment
the response with proper prototypes
* Augment
s the response with proper prototypes.
*
* @param mixed response Phantom response or undefined (generally with local files)
* @param Mixed response Phantom response or undefined (generally with local files)
* @return Object Augmented response
*/
exports
.
augmentResponse
=
function
(
response
)
{
"use strict"
;
...
...
@@ -70,4 +71,5 @@ exports.augmentResponse = function(response) {
return
;
}
response
.
headers
.
__proto__
=
responseHeaders
.
prototype
;
return
response
;
};
...
...
modules/tester.js
View file @
7c0343f
...
...
@@ -997,6 +997,7 @@ Tester.prototype.done = function done() {
this
.
executed
=
0
;
}
this
.
emit
(
'test.done'
);
this
.
casper
.
currentHTTPResponse
=
{};
this
.
running
=
this
.
started
=
false
;
var
nextTest
=
this
.
queue
.
shift
();
if
(
nextTest
)
{
...
...
modules/utils.js
View file @
7c0343f
...
...
@@ -114,7 +114,7 @@ function equals(v1, v2) {
return
v1
.
toString
()
===
v2
.
toString
();
}
if
(
v1
instanceof
Object
)
{
if
(
Object
.
keys
(
v1
).
length
!==
Object
.
keys
(
v2
).
length
)
{
if
(
!
(
v2
instanceof
Object
)
||
Object
.
keys
(
v1
).
length
!==
Object
.
keys
(
v2
).
length
)
{
return
false
;
}
for
(
var
k
in
v1
)
{
...
...
tests/suites/casper/headers.js
View file @
7c0343f
...
...
@@ -14,7 +14,7 @@ var service = server.listen(8090, function(request, response) {
casper
.
test
.
begin
(
'Casper.headers.get() using file protocol'
,
1
,
function
(
test
)
{
casper
.
start
(
'file://'
+
phantom
.
casperPath
+
'tests/site/index.html'
,
function
(
response
)
{
test
.
assertEquals
(
response
,
undefined
,
'No response availabl
e on local page'
);
test
.
assertEquals
(
response
,
{
data
:
null
},
'Empty http respons
e on local page'
);
}).
run
(
function
()
{
test
.
done
();
})
...
...
tests/suites/casper/history.js
View file @
7c0343f
...
...
@@ -6,17 +6,17 @@ casper.test.begin('handling navigation history', 4, function(test) {
casper
.
thenOpen
(
'tests/site/page3.html'
);
casper
.
back
();
casper
.
then
(
function
()
{
test
.
assertMatch
(
this
.
getCurrentUrl
(),
/
tests
\/
site
\/
page2
\.
html$/
,
test
.
assertMatch
(
this
.
getCurrentUrl
(),
/page2
\.
html$/
,
'Casper.back() can go back an history step'
);
});
casper
.
forward
();
casper
.
then
(
function
()
{
test
.
assertMatch
(
this
.
getCurrentUrl
(),
/
tests
\/
site
\/
page3
\.
html$/
,
test
.
assertMatch
(
this
.
getCurrentUrl
(),
/page3
\.
html$/
,
'Casper.forward() can go forward an history step'
);
});
casper
.
run
(
function
()
{
test
.
assert
(
this
.
history
.
length
>
0
,
'Casper.history contains urls'
);
test
.
assertMatch
(
this
.
history
[
0
],
/
tests
\/
site
\/
page1
\.
html$/
,
test
.
assertMatch
(
this
.
history
[
0
],
/page1
\.
html$/
,
'Casper.history has the correct first url'
);
test
.
done
();
});
...
...
tests/suites/casper/steps.js
View file @
7c0343f
...
...
@@ -40,10 +40,14 @@ casper.test.begin('eachThen() tests', 1, function(test) {
var
received
=
[];
casper
.
start
().
eachThen
([
1
,
2
,
3
],
function
(
response
)
{
if
(
!
response
)
{
test
.
fail
(
'No response received'
);
}
received
.
push
(
response
.
data
);
});
casper
.
run
(
function
()
{
console
.
log
(
'PLOP!!!'
);
test
.
assertEquals
(
received
,
[
1
,
2
,
3
],
'Casper.eachThen() passes item to step data'
);
test
.
done
();
...
...
tests/suites/http_status.js
View file @
7c0343f
...
...
@@ -6,15 +6,36 @@
*/
var
fs
=
require
(
'fs'
);
var
utils
=
require
(
'utils'
);
var
server
=
require
(
'webserver'
).
create
();
var
service
=
server
.
listen
(
8090
,
function
(
request
,
response
)
{
var
code
=
parseInt
(
/^
\/(\d
+
)
$/
.
exec
(
request
.
url
)[
1
],
10
);
response
.
statusCode
=
code
;
casper
.
test
.
begin
(
"HTTP status code handling"
,
163
,
{
setUp
:
function
(
test
)
{
this
.
server
=
require
(
'webserver'
).
create
();
this
.
server
.
listen
(
8090
,
function
(
request
,
response
)
{
response
.
statusCode
=
parseInt
(
/^
\/(\d
+
)
$/
.
exec
(
request
.
url
)[
1
],
10
);
response
.
write
(
""
);
response
.
close
();
});
});
this
.
testCodes
=
[
100
,
101
,
102
,
118
,
200
,
201
,
202
,
203
,
204
,
205
,
206
,
207
,
210
,
300
,
301
,
302
,
303
,
304
,
305
,
307
,
310
];
if
(
utils
.
ltVersion
(
phantom
.
version
,
'1.9.0'
))
{
// https://github.com/ariya/phantomjs/issues/11163
this
.
testCodes
=
this
.
testCodes
.
concat
([
400
,
401
,
402
,
403
,
404
,
405
,
406
,
407
,
408
,
409
,
410
,
411
,
412
,
413
,
414
,
415
,
416
,
417
,
418
,
422
,
423
,
424
,
425
,
426
,
449
,
450
,
500
,
501
,
502
,
503
,
504
,
505
,
507
,
509
]);
}
else
{
test
.
skip
(
102
);
}
},
casper
.
test
.
begin
(
"HTTP status code handling"
,
109
,
function
(
test
)
{
tearDown
:
function
()
{
this
.
server
.
close
();
},
test
:
function
(
test
)
{
casper
.
start
();
// file protocol
...
...
@@ -22,27 +43,22 @@ casper.test.begin("HTTP status code handling", 109, function(test) {
this
.
test
.
assertHttpStatus
(
null
,
'file:// protocol does not set a HTTP status'
);
});
// http protocol
var
codes
=
[
100
,
101
,
102
,
118
,
200
,
201
,
202
,
203
,
204
,
205
,
206
,
207
,
210
,
300
,
301
,
302
,
303
,
304
,
305
,
307
,
310
,
400
,
401
,
402
,
403
,
404
,
405
,
406
,
407
,
408
,
409
,
410
,
411
,
412
,
413
,
414
,
415
,
416
,
417
,
418
,
422
,
423
,
424
,
425
,
426
,
449
,
450
,
500
,
501
,
502
,
503
,
504
,
505
,
507
,
509
];
casper
.
each
(
codes
,
function
(
self
,
code
)
{
casper
.
each
(
this
.
testCodes
,
function
(
self
,
code
)
{
if
(
code
===
100
)
{
// HTTP 100 is CONTINUE, so don't expect a terminated response
return
;
}
this
.
thenOpen
(
'http://localhost:8090/'
+
code
,
function
()
{
this
.
test
.
assertEquals
(
this
.
currentHTTPStatus
,
code
,
utils
.
format
(
'Status is stored in casper.currentHTTPStatus'
,
code
));
this
.
test
.
assertHttpStatus
(
code
,
utils
.
format
(
'HTTP %d handled'
,
code
));
this
.
thenOpen
(
'http://localhost:8090/'
+
code
,
function
(
resource
)
{
test
.
assertEquals
(
resource
.
status
,
code
,
'Status is stored in resource.status'
);
test
.
assertEquals
(
this
.
currentHTTPStatus
,
code
,
'Status is stored in casper.currentHTTPStatus'
);
test
.
assertHttpStatus
(
code
,
utils
.
format
(
'HTTP %d handled'
,
code
));
});
});
casper
.
run
(
function
()
{
server
.
close
();
this
.
test
.
done
();
});
}
});
...
...
Please
register
or
sign in
to post a comment