Commit d49e786c d49e786cc0b869525ddb503da3ac5bb3039d11a1 by Nicolas Perriault

Casper.resourceExists() now checks for non 404 HTTP status

1 parent d3a6d79d
......@@ -6,14 +6,15 @@ XXXX-XX-XX, v1.0.0
This version is yet to be released.
- [Casper.resourceExists()](http://casperjs.org/api.html#casper.resourceExists) and related functions now checks for non HTTP-404 received responses.
- closes [#230](https://github.com/n1k0/casperjs/issues/230) - added [`ClientUtils.getElementsBound()`](http://casperjs.org/api.html#clientutils.getElementsBounds) and [`Casper.getElementsBound()`](http://casperjs.org/api.html#casper.getElementsBounds)
- fixes [#254](https://github.com/n1k0/casperjs/issues/254) - fix up one use of qsa, hit when filling forms with missing elements
2012-10-01, v1.0.0-RC2
----------------------
### Important Changes & Caveats
- fixes [#254](https://github.com/n1k0/casperjs/issues/254) - fix up one use of qsa, hit when filling forms with missing elements
- **PhantomJS 1.6 is now the minimal requirement**, PhantomJS 1.7 is supported.
- CasperJS continues to ship with its own implementation of CommonJS' module pattern, due to the way it has to work to offer its own executable. While the implementations are nearly the same, **100% compatibility is not guaranteed**.
......
......@@ -1054,12 +1054,12 @@ Casper.prototype.resourceExists = function resourceExists(test) {
switch (utils.betterTypeOf(test)) {
case "string":
testFn = function _testResourceExists_String(res) {
return res.url.search(test) !== -1;
return res.url.search(test) !== -1 && res.status !== 404;
};
break;
case "regexp":
testFn = function _testResourceExists_Regexp(res) {
return test.test(res.url);
return test.test(res.url) && res.status !== 404;
};
break;
case "function":
......
......@@ -3,14 +3,13 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test resource</title>
</head>
<body>
<script id="loader"></script>
<script>
setTimeout(function () {
var path = "images/phantom.png?" + new Date();
document.querySelector("img").setAttribute("src", path);
document.querySelector("#loader").setAttribute("src", "dummy.js");
}, 1000);
</script>
</head>
<body>
<img width="55" height="55" border="1">
</body>
</html>
......
......@@ -7,18 +7,18 @@ casper.start "tests/site/resources.html", ->
"two resources found"
)
@test.assertResourceExists(
/phantom\.png/i
/dummy\.js/i
"phantom image found via test RegExp"
)
@test.assertResourceExists(
(res) -> res.url.match "phantom.png"
(res) -> res.url.match "dummy.js"
"phantom image found via test Function"
)
@test.assertResourceExists(
"phantom.png"
"dummy.js"
"phantom image found via test String"
)
onTimeout = -> @test.fail "waitForResource timeout occured"
@waitForResource "phantom.png", onTime, onTimeout
@waitForResource "dummy.js", onTime, onTimeout
casper.run(-> @test.done())
......