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

Commit

Permalink
feat(expectedConditions): adding urlIs and urlContains (#3237)
Browse files Browse the repository at this point in the history
* adding urlIs and urlContains
* tests for UrlIs and UrlContains
  • Loading branch information
manoj9788 authored and cnishina committed Jun 3, 2016
1 parent 094ffa0 commit 8316917
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
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

0 comments on commit 8316917

Please sign in to comment.