Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

[feature] Adding urlIs and urlContains to expectedConditions class #3237

Merged
merged 3 commits into from
Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions lib/expectedConditions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,49 @@ export class ExpectedConditions {
};
}

/**
* An expectation for checking that the URL contains a case-sensitive
* substring.
*
* @example
* var EC = protractor.ExpectedConditions;
* // Waits for the URL to contain 'foo'.
* browser.wait(EC.urlContains('foo'), 5000);
*
* @param {!string} url The fragment of URL expected
*
* @return {!function} An expected condition that returns a promise
* representing whether the URL contains the string.
*/
urlContains(url: string): Function {
return () => {
return protractor.browser.driver.getCurrentUrl().then(
(actualUrl: string): boolean => {
return actualUrl.indexOf(url) > -1;
});
};
}

/**
* An expectation for checking the URL of a page.
*
* @example
* var EC = protractor.ExpectedConditions;
* // Waits for the URL to be 'foo'.
* browser.wait(EC.urlIs('foo'), 5000);
*
* @param {!string} url The expected URL, which must be an exact match.
*
* @return {!function} An expected condition that returns a promise
* representing whether the url equals the string.
*/
urlIs(url: string): Function {
return () => {
return protractor.browser.driver.getCurrentUrl().then(
(actualUrl: string): boolean => { return actualUrl === url; });
};
}

/**
* An expectation for checking that an element is present on the DOM
* of a page. This does not necessarily mean that the element is visible.
Expand Down
13 changes: 13 additions & 0 deletions spec/basic/expected_conditions_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var EC = protractor.ExpectedConditions;
var env = require('../environment');

describe('expected conditions', function() {
beforeEach(function() {
Expand Down Expand Up @@ -66,6 +67,18 @@ describe('expected conditions', function() {
expect(EC.titleIs('My AngularJS App').call()).toBe(true);
});

it('should have urlContains', function() {
var baseUrlFromSpec = browser.baseUrl;
expect(EC.urlContains('/form').call()).toBe(true);
expect(EC.urlContains(baseUrlFromSpec+ 'index.html#/form').call()).toBe(true);
});

it('should have urlIs', function() {
var baseUrlFromSpec = browser.baseUrl;
expect(EC.urlIs(env.baseUrl).call()).toBe(false);
expect(EC.urlIs(baseUrlFromSpec+'index.html#/form').call()).toBe(true);
});

it('should have elementToBeClickable', function() {
var invalidIsClickable = EC.elementToBeClickable($('#INVALID'));
var buttonIsClickable = EC.elementToBeClickable($('#disabledButton'));
Expand Down