Skip to content

Commit

Permalink
Adding new functions to until class (#2139)
Browse files Browse the repository at this point in the history
  • Loading branch information
manoj9788 authored and jleyba committed May 21, 2016
1 parent a1b0fbd commit 8981d76
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
51 changes: 51 additions & 0 deletions javascript/node/selenium-webdriver/lib/until.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,57 @@ exports.titleMatches = function titleMatches(regex) {
};


/**
* Creates a condition that will wait for the current page's url to match the
* given value.
*
* @param {string} url The expected page url.
* @return {!Condition<boolean>} The new condition.
*/
exports.urlIs = function urlIs(url){
return new Condition(
'for url to be ' + JSON.stringify(url),
function(driver) {
return driver.getCurrentUrl().then(function(u) {
return u === url;
});
});
};

/**
* Creates a condition that will wait for the current page's url to contain
* the given substring.
*
* @param {string} substrUrl The substring that should be present in the page
* title.
* @return {!Condition<boolean>} The new condition.
*/
exports.urlContains = function urlContains(substrUrl) {
return new Condition(
'for url to contain ' + JSON.stringify(substrUrl),
function(driver) {
return driver.getCurrentUrl().then(function(url) {
return url.indexOf(substrUrl) !== -1;
});
});
};

/**
* Creates a condition that will wait for the current page's url to match the
* given regular expression.
*
* @param {!RegExp} regex The regular expression to test against.
* @return {!Condition<boolean>} The new condition.
*/
exports.urlMatches = function urlMatches(regex) {
return new Condition('for url to match ' + regex, function(driver) {
return driver.getCurrentUrl().then(function(url) {
return regex.test(url);
});
});
};


/**
* Creates a condition that will loop until an element is
* {@link ./webdriver.WebDriver#findElement found} with the given locator.
Expand Down
28 changes: 28 additions & 0 deletions javascript/node/selenium-webdriver/test/lib/until_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,34 @@ describe('until', function() {
assert.deepStrictEqual(titles, ['google']);
});
});

it('testUntilUrlIs', function() {
var urls = ['http://www.foo.com', 'https://boo.com', 'http://docs.yes.com'];
executor.on(CommandName.GET_CURRENT_URL, () => urls.shift());

return driver.wait(until.urlIs('https://boo.com'), 3000).then(function() {
assert.deepStrictEqual(urls, ['http://docs.yes.com']);
});
});

it('testUntilUrlContains', function() {
var urls = ['http://foo.com', 'https://groups.froogle.com', 'http://google.com'];
executor.on(CommandName.GET_CURRENT_URL, () => urls.shift());

return driver.wait(until.urlContains('oogle.com'), 3000).then(function() {
assert.deepStrictEqual(urls, ['http://google.com']);
});
});

it('testUntilUrlMatches', function() {
var urls = ['foo', 'froogle', 'aaaabc', 'aabbbc', 'google'];
executor.on(CommandName.GET_CURRENT_URL, () => urls.shift());

return driver.wait(until.urlMatches(/^a{2,3}b+c$/), 3000)
.then(function() {
assert.deepStrictEqual(urls, ['google']);
});
});

it('testUntilElementLocated', function() {
var responses = [
Expand Down

0 comments on commit 8981d76

Please sign in to comment.