updated docs for resourceExists and waitForResource
Showing
2 changed files
with
23 additions
and
11 deletions
... | @@ -1382,9 +1382,9 @@ Repeats a navigation step a given number of times:: | ... | @@ -1382,9 +1382,9 @@ Repeats a navigation step a given number of times:: |
1382 | ``resourceExists()`` | 1382 | ``resourceExists()`` |
1383 | ------------------------------------------------------------------------------- | 1383 | ------------------------------------------------------------------------------- |
1384 | 1384 | ||
1385 | **Signature:** ``resourceExists(Mixed test)`` | 1385 | **Signature:** ``resourceExists(String|Function|RegExp test)`` |
1386 | 1386 | ||
1387 | Checks if a resource has been loaded. You can pass either a function or a string to perform the test:: | 1387 | Checks if a resource has been loaded. You can pass either a function, a string or a ``RegExp`` instance to perform the test:: |
1388 | 1388 | ||
1389 | casper.start('http://www.google.com/', function() { | 1389 | casper.start('http://www.google.com/', function() { |
1390 | if (this.resourceExists('logo3w.png')) { | 1390 | if (this.resourceExists('logo3w.png')) { |
... | @@ -2016,17 +2016,29 @@ The currently loaded popups are available in the ``Casper.popups`` array-like pr | ... | @@ -2016,17 +2016,29 @@ The currently loaded popups are available in the ``Casper.popups`` array-like pr |
2016 | ``waitForResource()`` | 2016 | ``waitForResource()`` |
2017 | ------------------------------------------------------------------------------- | 2017 | ------------------------------------------------------------------------------- |
2018 | 2018 | ||
2019 | **Signature:** ``waitForResource(Function testFx[, Function then, Function onTimeout, Number timeout])`` | 2019 | **Signature:** ``waitForResource(String|Function|RegExp testFx[, Function then, Function onTimeout, Number timeout])`` |
2020 | 2020 | ||
2021 | Wait until a resource that matches the given ``testFx`` is loaded to process a next step. Uses `waitFor()`_:: | 2021 | Wait until a resource that matches a resource matching constraints defined by ``testFx`` are satisfief to process a next step. |
2022 | 2022 | ||
2023 | casper.start('http://foo.bar/'); | 2023 | The ``testFx`` argument can be either a string, a function or a ``RegExp`` instance:: |
2024 | 2024 | ||
2025 | casper.waitForResource("foobar.png", function() { | 2025 | casper.waitForResource("foobar.png", function() { |
2026 | this.echo('foobar.png has been loaded.'); | 2026 | this.echo('foobar.png has been loaded.'); |
2027 | }); | 2027 | }); |
2028 | 2028 | ||
2029 | casper.run(); | 2029 | Using a regexp:: |
2030 | |||
2031 | casper.waitForResource(/foo(bar|baz)\.png$/, function() { | ||
2032 | this.echo('foobar.png or foobaz.png has been loaded.'); | ||
2033 | }); | ||
2034 | |||
2035 | Using a function:: | ||
2036 | |||
2037 | casper.waitForResource(function testResource(resource) { | ||
2038 | return resource.url.indexOf("https") === 0; | ||
2039 | }, function onReceived() { | ||
2040 | this.echo('a secure resource has been loaded.'); | ||
2041 | }); | ||
2030 | 2042 | ||
2031 | .. _casper_waitforurl: | 2043 | .. _casper_waitforurl: |
2032 | 2044 | ... | ... |
... | @@ -2084,11 +2084,11 @@ Casper.prototype.waitForPopup = function waitForPopup(urlPattern, then, onTimeou | ... | @@ -2084,11 +2084,11 @@ Casper.prototype.waitForPopup = function waitForPopup(urlPattern, then, onTimeou |
2084 | /** | 2084 | /** |
2085 | * Waits until a given resource is loaded | 2085 | * Waits until a given resource is loaded |
2086 | * | 2086 | * |
2087 | * @param String/Function test A function to test if the resource exists. | 2087 | * @param String/Function/RegExp test A function to test if the resource exists. |
2088 | * A string will be matched against the resources url. | 2088 | * A string will be matched against the resources url. |
2089 | * @param Function then The next step to perform (optional) | 2089 | * @param Function then The next step to perform (optional) |
2090 | * @param Function onTimeout A callback function to call on timeout (optional) | 2090 | * @param Function onTimeout A callback function to call on timeout (optional) |
2091 | * @param Number timeout The max amount of time to wait, in milliseconds (optional) | 2091 | * @param Number timeout The max amount of time to wait, in milliseconds (optional) |
2092 | * @return Casper | 2092 | * @return Casper |
2093 | */ | 2093 | */ |
2094 | Casper.prototype.waitForResource = function waitForResource(test, then, onTimeout, timeout) { | 2094 | Casper.prototype.waitForResource = function waitForResource(test, then, onTimeout, timeout) { | ... | ... |
-
Please register or sign in to post a comment