From 666023639490752ba1efaec3ff22205556b17379 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Sun, 22 May 2016 21:39:31 +1000 Subject: [PATCH 1/3] [feature] adding urlIs and urlContains --- lib/expectedConditions.ts | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/lib/expectedConditions.ts b/lib/expectedConditions.ts index c9a85c361..734195eb5 100644 --- a/lib/expectedConditions.ts +++ b/lib/expectedConditions.ts @@ -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. From 69b3c513d66b7f7f19d26b027860a4f6fde6744d Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Sun, 22 May 2016 21:54:38 +1000 Subject: [PATCH 2/3] tests for UrlIs and UrlContains declared as a var baseUrlFromSpec - to prevent tests failure, just incase if anyone builds and runs protractor test app with different port number --- spec/basic/expected_conditions_spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/basic/expected_conditions_spec.js b/spec/basic/expected_conditions_spec.js index 6f4d57015..0e8b056df 100644 --- a/spec/basic/expected_conditions_spec.js +++ b/spec/basic/expected_conditions_spec.js @@ -66,6 +66,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('http://localhost:8081').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')); From 560308a8a1325a1ba510d228a575c9b9bcc57271 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Fri, 3 Jun 2016 23:18:57 +1000 Subject: [PATCH 3/3] incorporated review comments from craig --- spec/basic/expected_conditions_spec.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/basic/expected_conditions_spec.js b/spec/basic/expected_conditions_spec.js index 0e8b056df..798ce1940 100644 --- a/spec/basic/expected_conditions_spec.js +++ b/spec/basic/expected_conditions_spec.js @@ -1,4 +1,5 @@ var EC = protractor.ExpectedConditions; +var env = require('../environment'); describe('expected conditions', function() { beforeEach(function() { @@ -74,7 +75,7 @@ describe('expected conditions', function() { it('should have urlIs', function() { var baseUrlFromSpec = browser.baseUrl; - expect(EC.urlIs('http://localhost:8081').call()).toBe(false); + expect(EC.urlIs(env.baseUrl).call()).toBe(false); expect(EC.urlIs(baseUrlFromSpec+'index.html#/form').call()).toBe(true); });