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

Commit 8316917

Browse files
manoj9788cnishina
authored andcommitted
feat(expectedConditions): adding urlIs and urlContains (#3237)
* adding urlIs and urlContains * tests for UrlIs and UrlContains
1 parent 094ffa0 commit 8316917

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

lib/expectedConditions.ts

+43
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,49 @@ export class ExpectedConditions {
265265
};
266266
}
267267

268+
/**
269+
* An expectation for checking that the URL contains a case-sensitive
270+
* substring.
271+
*
272+
* @example
273+
* var EC = protractor.ExpectedConditions;
274+
* // Waits for the URL to contain 'foo'.
275+
* browser.wait(EC.urlContains('foo'), 5000);
276+
*
277+
* @param {!string} url The fragment of URL expected
278+
*
279+
* @return {!function} An expected condition that returns a promise
280+
* representing whether the URL contains the string.
281+
*/
282+
urlContains(url: string): Function {
283+
return () => {
284+
return protractor.browser.driver.getCurrentUrl().then(
285+
(actualUrl: string): boolean => {
286+
return actualUrl.indexOf(url) > -1;
287+
});
288+
};
289+
}
290+
291+
/**
292+
* An expectation for checking the URL of a page.
293+
*
294+
* @example
295+
* var EC = protractor.ExpectedConditions;
296+
* // Waits for the URL to be 'foo'.
297+
* browser.wait(EC.urlIs('foo'), 5000);
298+
*
299+
* @param {!string} url The expected URL, which must be an exact match.
300+
*
301+
* @return {!function} An expected condition that returns a promise
302+
* representing whether the url equals the string.
303+
*/
304+
urlIs(url: string): Function {
305+
return () => {
306+
return protractor.browser.driver.getCurrentUrl().then(
307+
(actualUrl: string): boolean => { return actualUrl === url; });
308+
};
309+
}
310+
268311
/**
269312
* An expectation for checking that an element is present on the DOM
270313
* of a page. This does not necessarily mean that the element is visible.

spec/basic/expected_conditions_spec.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var EC = protractor.ExpectedConditions;
2+
var env = require('../environment');
23

34
describe('expected conditions', function() {
45
beforeEach(function() {
@@ -66,6 +67,18 @@ describe('expected conditions', function() {
6667
expect(EC.titleIs('My AngularJS App').call()).toBe(true);
6768
});
6869

70+
it('should have urlContains', function() {
71+
var baseUrlFromSpec = browser.baseUrl;
72+
expect(EC.urlContains('/form').call()).toBe(true);
73+
expect(EC.urlContains(baseUrlFromSpec+ 'index.html#/form').call()).toBe(true);
74+
});
75+
76+
it('should have urlIs', function() {
77+
var baseUrlFromSpec = browser.baseUrl;
78+
expect(EC.urlIs(env.baseUrl).call()).toBe(false);
79+
expect(EC.urlIs(baseUrlFromSpec+'index.html#/form').call()).toBe(true);
80+
});
81+
6982
it('should have elementToBeClickable', function() {
7083
var invalidIsClickable = EC.elementToBeClickable($('#INVALID'));
7184
var buttonIsClickable = EC.elementToBeClickable($('#disabledButton'));

0 commit comments

Comments
 (0)