Commit 521ddb10 521ddb104d3a3b9f011ff8385dcf3bc61b217c2d by Nicolas Perriault

updated docs for resourceExists and waitForResource

1 parent 06646b11
......@@ -1382,9 +1382,9 @@ Repeats a navigation step a given number of times::
``resourceExists()``
-------------------------------------------------------------------------------
**Signature:** ``resourceExists(Mixed test)``
**Signature:** ``resourceExists(String|Function|RegExp test)``
Checks if a resource has been loaded. You can pass either a function or a string to perform the test::
Checks if a resource has been loaded. You can pass either a function, a string or a ``RegExp`` instance to perform the test::
casper.start('http://www.google.com/', function() {
if (this.resourceExists('logo3w.png')) {
......@@ -2016,17 +2016,29 @@ The currently loaded popups are available in the ``Casper.popups`` array-like pr
``waitForResource()``
-------------------------------------------------------------------------------
**Signature:** ``waitForResource(Function testFx[, Function then, Function onTimeout, Number timeout])``
**Signature:** ``waitForResource(String|Function|RegExp testFx[, Function then, Function onTimeout, Number timeout])``
Wait until a resource that matches the given ``testFx`` is loaded to process a next step. Uses `waitFor()`_::
Wait until a resource that matches a resource matching constraints defined by ``testFx`` are satisfief to process a next step.
casper.start('http://foo.bar/');
The ``testFx`` argument can be either a string, a function or a ``RegExp`` instance::
casper.waitForResource("foobar.png", function() {
this.echo('foobar.png has been loaded.');
});
casper.run();
Using a regexp::
casper.waitForResource(/foo(bar|baz)\.png$/, function() {
this.echo('foobar.png or foobaz.png has been loaded.');
});
Using a function::
casper.waitForResource(function testResource(resource) {
return resource.url.indexOf("https") === 0;
}, function onReceived() {
this.echo('a secure resource has been loaded.');
});
.. _casper_waitforurl:
......
......@@ -2084,11 +2084,11 @@ Casper.prototype.waitForPopup = function waitForPopup(urlPattern, then, onTimeou
/**
* Waits until a given resource is loaded
*
* @param String/Function test A function to test if the resource exists.
* A string will be matched against the resources url.
* @param Function then The next step to perform (optional)
* @param Function onTimeout A callback function to call on timeout (optional)
* @param Number timeout The max amount of time to wait, in milliseconds (optional)
* @param String/Function/RegExp test A function to test if the resource exists.
* A string will be matched against the resources url.
* @param Function then The next step to perform (optional)
* @param Function onTimeout A callback function to call on timeout (optional)
* @param Number timeout The max amount of time to wait, in milliseconds (optional)
* @return Casper
*/
Casper.prototype.waitForResource = function waitForResource(test, then, onTimeout, timeout) {
......