Commit e9218ef9 e9218ef9b835ada5e786ff48bba2a14213b46b57 by Nicolas Perriault

refs #435 - added Casper#waitForUrl

1 parent 25aa9da9
......@@ -129,6 +129,7 @@ casper.on('page.resource.requested', function(requestData, request) {
- fixed [#452](https://github.com/n1k0/casperjs/pull/452) - allow uppercase http methods in `Casper#open()`
- Added [`Casper#fillSelectors()`](http://docs.casperjs.org/en/latest/modules/casper.html#fillselectors) and [`Casper#fillXPath()`](http://docs.casperjs.org/en/latest/modules/casper.html#fillxpath)
- Added [`Casper#getElementsAttribute()`](http://docs.casperjs.org/en/latest/modules/casper.html#getelementsattribute) and [`Casper#getElementsInfo()`](http://docs.casperjs.org/en/latest/modules/casper.html#getelementsinfo)
- Added [`Casper#waitForUrl()`](http://docs.casperjs.org/en/latest/modules/casper.html#waitforurl)
- Added support for key modifiers to `Casper#sendKeys()`
- `cli`: Now dropping an arg or an option will be reflected in their *raw* equivalent
- `cli.get()` now supports fallback values
......
......@@ -1984,6 +1984,25 @@ Wait until a resource that matches the given ``testFx`` is loaded to process a n
casper.run();
.. _casper_waitforurl:
.. index:: URL
``waitForUrl()``
-------------------------------------------------------------------------------
**Signature:** ``waitForUrl(String|RegExp url[, Function then, Function onTimeout, Number timeout])``
.. versionadded:: 1.1
Waits for the current pahe url to match the provided argument (``String`` or ``RegExp``)::
casper.start('http://foo/').waitForUrl(/login\.html$/, function() {
this.echo('redirected to login.html');
});
casper.run();
.. index:: selector
``waitForSelector()``
......
......@@ -2067,6 +2067,28 @@ Casper.prototype.waitForResource = function waitForResource(test, then, onTimeou
};
/**
* Waits for a given url to be loaded.
*
* @param String|RegExp url The url to wait for
* @param Function then The next step to perform (optional)
* @param Function onTimeout A callback function to call on timeout (optional)
* @return Casper
*/
Casper.prototype.waitForUrl = function waitForUrl(url, then, onTimeout, timeout) {
"use strict";
this.checkStarted();
timeout = timeout ? timeout : this.options.waitTimeout;
return this.waitFor(function _check() {
if (utils.isString(url)) {
return this.getCurrentUrl().indexOf(url) !== -1;
} else if (utils.isRegExp(url)) {
return url.test(this.getCurrentUrl());
}
throw new CasperError('invalid url argument');
}, then, onTimeout, timeout);
};
/**
* Waits until an element matching the provided DOM CSS3/XPath selector exists in
* remote DOM to process a next step.
*
......
......@@ -136,3 +136,35 @@ casper.test.begin('waitUntilVisible() tests', 2, function(test) {
test.done();
});
});
casper.test.begin('waitForUrl() regexp tests', 1, function(test) {
casper.start().thenEvaluate(function() {
setTimeout(function() {
document.location = './form.html';
}, 100);
});
casper.waitForUrl(/form\.html$/, function() {
test.pass('Casper.waitForUrl() waits for a given regexp url');
});
casper.run(function() {
test.done();
});
});
casper.test.begin('waitForUrl() string tests', 1, function(test) {
casper.start().thenEvaluate(function() {
setTimeout(function() {
document.location = './form.html';
}, 100);
});
casper.waitForUrl('form.html', function() {
test.pass('Casper.waitForUrl() waits for a given string url');
});
casper.run(function() {
test.done();
});
});
......