diff --git a/lib/browser.ts b/lib/browser.ts index 92dd1ab0c..95096c48c 100644 --- a/lib/browser.ts +++ b/lib/browser.ts @@ -747,8 +747,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * the wrapped webdriver directly. * * @example - * browser.get('https://angularjs.org/'); - * expect(browser.getCurrentUrl()).toBe('https://angularjs.org/'); + * await browser.get('https://angularjs.org/'); + * expect(await browser.getCurrentUrl()).toBe('https://angularjs.org/'); * * @param {string} destination Destination URL. * @param {number=} opt_timeout Number of milliseconds to wait for Angular to @@ -894,9 +894,9 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * Browse to another page using in-page navigation. * * @example - * browser.get('http://angular.github.io/protractor/#/tutorial'); - * browser.setLocation('api'); - * expect(browser.getCurrentUrl()) + * await browser.get('http://angular.github.io/protractor/#/tutorial'); + * await browser.setLocation('api'); + * expect(await browser.getCurrentUrl()) * .toBe('http://angular.github.io/protractor/#/api'); * * @param {string} url In page URL using the same syntax as $location.url() @@ -922,8 +922,8 @@ export class ProtractorBrowser extends AbstractExtendedWebDriver { * * @deprecated Please use `browser.getCurrentUrl()` * @example - * browser.get('http://angular.github.io/protractor/#/api'); - * expect(browser.getLocationAbsUrl()) + * await browser.get('http://angular.github.io/protractor/#/api'); + * expect(await browser.getLocationAbsUrl()) * .toBe('http://angular.github.io/protractor/#/api'); * @returns {Promise} The current absolute url from * AngularJS. diff --git a/lib/element.ts b/lib/element.ts index 675b170ae..936ef8d04 100644 --- a/lib/element.ts +++ b/lib/element.ts @@ -55,23 +55,21 @@ let WEB_ELEMENT_FUNCTIONS = [ * * * @example - * element.all(by.css('.items li')).then(function(items) { - * expect(items.length).toBe(3); - * expect(items[0].getText()).toBe('First'); - * }); + * const items = await element.all(by.css('.items li')); + * expect(items.length).toBe(3); + * expect(await items[0].getText()).toBe('First'); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * - * $$('.items li').then(function(items) { - * expect(items.length).toBe(3); - * expect(items[0].getText()).toBe('First'); - * }); + * const items = await $$('.items li'); + * expect(items.length).toBe(3); + * expect(await items[0].getText()).toBe('First'); * * @constructor * @param {ProtractorBrowser} browser A browser instance. * @param {function(): Array.} getWebElements A function * that returns a list of the underlying Web Elements. - * @param {webdriver.Locator} locator The most relevant locator. It is only + * @param {Locator} locator The most relevant locator. It is only * used for error reporting and ElementArrayFinder.locator. * @param {Array} opt_actionResults An array * of promises which will be retrieved with then. Resolves to the latest @@ -132,23 +130,23 @@ export class ElementArrayFinder extends WebdriverWebElement { * * @example * let foo = element.all(by.css('.parent')).all(by.css('.foo')); - * expect(foo.getText()).toEqual(['1a', '2a']); + * expect(await foo.getText()).toEqual(['1a', '2a']); * let baz = element.all(by.css('.parent')).all(by.css('.baz')); - * expect(baz.getText()).toEqual(['1b']); + * expect(await baz.getText()).toEqual(['1b']); * let nonexistent = element.all(by.css('.parent')) * .all(by.css('.NONEXISTENT')); - * expect(nonexistent.getText()).toEqual(['']); + * expect(await nonexistent.getText()).toEqual(['']); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * * let foo = $$('.parent').$$('.foo'); - * expect(foo.getText()).toEqual(['1a', '2a']); + * expect(await foo.getText()).toEqual(['1a', '2a']); * let baz = $$('.parent').$$('.baz'); - * expect(baz.getText()).toEqual(['1b']); + * expect(await baz.getText()).toEqual(['1b']); * let nonexistent = $$('.parent').$$('.NONEXISTENT'); - * expect(nonexistent.getText()).toEqual(['']); + * expect(await nonexistent.getText()).toEqual(['']); * - * @param {webdriver.Locator} subLocator + * @param {Locator} locator * @returns {ElementArrayFinder} */ all(locator: Locator): ElementArrayFinder { @@ -200,22 +198,19 @@ export class ElementArrayFinder extends WebdriverWebElement { * * * @example - * element.all(by.css('.items li')).filter(function(elem, index) { - * return elem.getText().then(function(text) { - * return text === 'Third'; - * }); - * }).first().click(); + * await element.all(by.css('.items li')) + * .filter(async (elem, index) => await elem.getText() === 'Third') + * .first() + * .click(); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * - * $$('.items li').filter(function(elem, index) { - * return elem.getText().then(function(text) { - * return text === 'Third'; - * }); - * }).first().click(); + * await $$('.items li') + * .filter(async (elem, index) => await elem.getText() === 'Third') + * .first() + * .click(); * - * @param {function(ElementFinder, number): boolean|Promise} - * filterFn + * @param {function(ElementFinder, number): boolean|Promise} filterFn * Filter function that will test if an element should be returned. * filterFn can either return a boolean or a promise that resolves to a * boolean. @@ -255,16 +250,16 @@ export class ElementArrayFinder extends WebdriverWebElement { * * @example * let list = element.all(by.css('.items li')); - * expect(list.get(0).getText()).toBe('First'); - * expect(list.get(1).getText()).toBe('Second'); + * expect(await list.get(0).getText()).toBe('First'); + * expect(await list.get(1).getText()).toBe('Second'); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * * let list = $$('.items li'); - * expect(list.get(0).getText()).toBe('First'); - * expect(list.get(1).getText()).toBe('Second'); + * expect(await list.get(0).getText()).toBe('First'); + * expect(await list.get(1).getText()).toBe('Second'); * - * @param {number|Promise} index Element index. + * @param {number|Promise} indexPromise Element index. * @returns {ElementFinder} finder representing element at the given index. */ get(indexPromise: number|Promise): ElementFinder { @@ -299,12 +294,12 @@ export class ElementArrayFinder extends WebdriverWebElement { * * @example * let first = element.all(by.css('.items li')).first(); - * expect(first.getText()).toBe('First'); + * expect(await first.getText()).toBe('First'); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * * let first = $$('.items li').first(); - * expect(first.getText()).toBe('First'); + * expect(await first.getText()).toBe('First'); * * @returns {ElementFinder} finder representing the first matching element */ @@ -326,12 +321,12 @@ export class ElementArrayFinder extends WebdriverWebElement { * * @example * let last = element.all(by.css('.items li')).last(); - * expect(last.getText()).toBe('Third'); + * expect(await last.getText()).toBe('Third'); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * * let last = $$('.items li').last(); - * expect(last.getText()).toBe('Third'); + * expect(await last.getText()).toBe('Third'); * * @returns {ElementFinder} finder representing the last matching element */ @@ -353,16 +348,16 @@ export class ElementArrayFinder extends WebdriverWebElement { * @example * // The following two blocks of code are equivalent. * let list = element.all(by.css('.count span')); - * expect(list.count()).toBe(2); - * expect(list.get(0).getText()).toBe('First'); - * expect(list.get(1).getText()).toBe('Second'); + * expect(await list.count()).toBe(2); + * expect(await list.get(0).getText()).toBe('First'); + * expect(await list.get(1).getText()).toBe('Second'); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * * let list = $$('.count span'); - * expect(list.count()).toBe(2); - * expect(list.get(0).getText()).toBe('First'); - * expect(list.get(1).getText()).toBe('Second'); + * expect(await list.count()).toBe(2); + * expect(await list.get(0).getText()).toBe('First'); + * expect(await list.get(1).getText()).toBe('Second'); * * @param {string} selector a css selector * @returns {ElementArrayFinder} which identifies the @@ -397,12 +392,12 @@ export class ElementArrayFinder extends WebdriverWebElement { * * @example * let list = element.all(by.css('.items li')); - * expect(list.count()).toBe(3); + * expect(await list.count()).toBe(3); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * * let list = $$('.items li'); - * expect(list.count()).toBe(3); + * expect(await list.count()).toBe(3); * * @returns {!Promise} A promise which resolves to the * number of elements matching the locator. @@ -426,7 +421,7 @@ export class ElementArrayFinder extends WebdriverWebElement { * @alias element.all(locator).isPresent() * * @example - * expect($('.item').isPresent()).toBeTruthy(); + * expect(await $('.item').isPresent()).toBeTruthy(); * * @returns {Promise} */ @@ -448,7 +443,7 @@ export class ElementArrayFinder extends WebdriverWebElement { * // returns by.css('#ID1') * $$('#ID1').filter(filterFn).get(0).click().locator(); * - * @returns {webdriver.Locator} + * @returns {Locator} */ locator(): Locator { return this.locator_; @@ -523,15 +518,13 @@ export class ElementArrayFinder extends WebdriverWebElement { * * * @example - * element.all(by.css('.items li')).then(function(arr) { - * expect(arr.length).toEqual(3); - * }); + * const arr = await element.all(by.css('.items li')); + * expect(arr.length).toEqual(3); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * - * $$('.items li').then(function(arr) { - * expect(arr.length).toEqual(3); - * }); + * const arr = $$('.items li'); + * expect(arr.length).toEqual(3); * * @param {function(Array.)} fn * @param {function(Error)} errorFn @@ -561,20 +554,16 @@ export class ElementArrayFinder extends WebdriverWebElement { * * * @example - * element.all(by.css('.items li')).each(function(element, index) { + * await element.all(by.css('.items li')).each(async (element, index) => { * // Will print 0 First, 1 Second, 2 Third. - * element.getText().then(function (text) { - * console.log(index, text); - * }); + * console.log(index, await element.getText()); * }); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * - * $$('.items li').each(function(element, index) { + * $$('.items li').each(async (element, index) => { * // Will print 0 First, 1 Second, 2 Third. - * element.getText().then(function (text) { - * console.log(index, text); - * }); + * console.log(index, await element.getText()); * }); * * @param {function(ElementFinder)} fn Input function @@ -601,13 +590,14 @@ export class ElementArrayFinder extends WebdriverWebElement { * * * @example - * let items = element.all(by.css('.items li')).map(function(elm, index) { - * return { - * index: index, - * text: elm.getText(), - * class: elm.getAttribute('class') - * }; - * }); + * let items = await element.all(by.css('.items li')) + * .map(async (elm, index) => { + * return { + * index: index, + * text: await elm.getText(), + * class: await elm.getAttribute('class') + * }; + * }); * expect(items).toEqual([ * {index: 0, text: 'First', class: 'one'}, * {index: 1, text: 'Second', class: 'two'}, @@ -616,11 +606,11 @@ export class ElementArrayFinder extends WebdriverWebElement { * * // Or using the shortcut $$() notation instead of element.all(by.css()): * - * let items = $$('.items li').map(function(elm, index) { + * let items = await $$('.items li').map(async (elm, index) => { * return { * index: index, - * text: elm.getText(), - * class: elm.getAttribute('class') + * text: await elm.getText(), + * class: await elm.getAttribute('class') * }; * }); * expect(items).toEqual([ @@ -662,21 +652,15 @@ export class ElementArrayFinder extends WebdriverWebElement { * * * @example - * let value = element.all(by.css('.items li')).reduce(function(acc, elem) { - * return elem.getText().then(function(text) { - * return acc + text + ' '; - * }); - * }, ''); + * let value = await element.all(by.css('.items li')) + * .reduce(async (acc, elem) => acc + (await elem.getText()) + ' ', ''); * * expect(value).toEqual('First Second Third '); * * // Or using the shortcut $$() notation instead of element.all(by.css()): * - * let value = $$('.items li').reduce(function(acc, elem) { - * return elem.getText().then(function(text) { - * return acc + text + ' '; - * }); - * }, ''); + * let value = await $$('.items li') + * .reduce(async (acc, elem) => acc + (await elem.getText()) + ' ', ''); * * expect(value).toEqual('First Second Third '); * @@ -774,17 +758,17 @@ export class ElementArrayFinder extends WebdriverWebElement { * * @example * // Find element with {{scopelet}} syntax. - * element(by.binding('person.name')).getText().then(function(name) { - * expect(name).toBe('Foo'); - * }); + * const name = await element(by.binding('person.name')).getText(); + * expect(name).toBe('Foo'); * * // Find element with ng-bind="scopelet" syntax. - * expect(element(by.binding('person.email')).getText()).toBe('foo@bar.com'); + * const email = await element(by.binding('person.email')).getText(); + * expect(email).toBe('foo@bar.com'); * * // Find by model. * let input = element(by.model('person.name')); - * input.sendKeys('123'); - * expect(input.getAttribute('value')).toBe('Foo123'); + * await input.sendKeys('123'); + * expect(await input.getAttribute('value')).toBe('Foo123'); * * @constructor * @extends {webdriver.WebElement} @@ -876,7 +860,7 @@ export class ElementFinder extends WebdriverWebElement { /** * @see ElementArrayFinder.prototype.locator * - * @returns {webdriver.Locator} + * @returns {Locator} */ locator(): any { return this.elementArrayFinder_.locator(); @@ -929,7 +913,7 @@ export class ElementFinder extends WebdriverWebElement { * * let items = $('.parent').all(by.tagName('li')); * - * @param {webdriver.Locator} subLocator + * @param {Locator} subLocator * @returns {ElementArrayFinder} */ all(subLocator: Locator): ElementArrayFinder { @@ -952,26 +936,26 @@ export class ElementFinder extends WebdriverWebElement { * // Chain 2 element calls. * let child = element(by.css('.parent')). * element(by.css('.child')); - * expect(child.getText()).toBe('Child text\n555-123-4567'); + * expect(await child.getText()).toBe('Child text\n555-123-4567'); * * // Chain 3 element calls. * let triple = element(by.css('.parent')). * element(by.css('.child')). * element(by.binding('person.phone')); - * expect(triple.getText()).toBe('555-123-4567'); + * expect(await triple.getText()).toBe('555-123-4567'); * * // Or using the shortcut $() notation instead of element(by.css()): * * // Chain 2 element calls. * let child = $('.parent').$('.child'); - * expect(child.getText()).toBe('Child text\n555-123-4567'); + * expect(await child.getText()).toBe('Child text\n555-123-4567'); * * // Chain 3 element calls. * let triple = $('.parent').$('.child'). * element(by.binding('person.phone')); - * expect(triple.getText()).toBe('555-123-4567'); + * expect(await triple.getText()).toBe('555-123-4567'); * - * @param {webdriver.Locator} subLocator + * @param {Locator} subLocator * @returns {ElementFinder} */ element(subLocator: Locator): ElementFinder { @@ -1022,24 +1006,24 @@ export class ElementFinder extends WebdriverWebElement { * // Chain 2 element calls. * let child = element(by.css('.parent')). * $('.child'); - * expect(child.getText()).toBe('Child text\n555-123-4567'); + * expect(await child.getText()).toBe('Child text\n555-123-4567'); * * // Chain 3 element calls. * let triple = element(by.css('.parent')). * $('.child'). * element(by.binding('person.phone')); - * expect(triple.getText()).toBe('555-123-4567'); + * expect(await triple.getText()).toBe('555-123-4567'); * * // Or using the shortcut $() notation instead of element(by.css()): * * // Chain 2 element calls. * let child = $('.parent').$('.child'); - * expect(child.getText()).toBe('Child text\n555-123-4567'); + * expect(await child.getText()).toBe('Child text\n555-123-4567'); * * // Chain 3 element calls. * let triple = $('.parent').$('.child'). * element(by.binding('person.phone')); - * expect(triple.getText()).toBe('555-123-4567'); + * expect(await triple.getText()).toBe('555-123-4567'); * * @param {string} selector A css selector * @returns {ElementFinder} @@ -1056,10 +1040,10 @@ export class ElementFinder extends WebdriverWebElement { * * @example * // Element exists. - * expect(element(by.binding('person.name')).isPresent()).toBe(true); + * expect(await element(by.binding('person.name')).isPresent()).toBe(true); * * // Element not present. - * expect(element(by.binding('notPresent')).isPresent()).toBe(false); + * expect(await element(by.binding('notPresent')).isPresent()).toBe(false); * * @returns {Promise} which resolves to whether * the element is present on the page. @@ -1090,7 +1074,7 @@ export class ElementFinder extends WebdriverWebElement { * * @see ElementFinder.isPresent * - * @param {webdriver.Locator} subLocator Locator for element to look for. + * @param {Locator} subLocator Locator for element to look for. * @returns {Promise} which resolves to whether * the subelement is present on the page. */ @@ -1135,7 +1119,7 @@ export class ElementFinder extends WebdriverWebElement { /** * Compares an element to this one for equality. * - * @param {!ElementFinder|!webdriver.WebElement} The element to compare to. + * @param {!ElementFinder|!webdriver.WebElement} element The element to compare to. * * @returns {!Promise} A promise that will be * resolved to whether the two WebElements are equal. @@ -1161,7 +1145,7 @@ export class ElementFinder extends WebdriverWebElement { * * @example * let item = $('.count .two'); - * expect(item.getText()).toBe('Second'); + * expect(await item.getText()).toBe('Second'); * * @param {string} selector A css selector * @returns {ElementFinder} which identifies the located @@ -1187,12 +1171,12 @@ export const build$ = (element: ElementHelper, by: typeof By) => { * @example * // The following protractor expressions are equivalent. * let list = element.all(by.css('.count span')); - * expect(list.count()).toBe(2); + * expect(await list.count()).toBe(2); * * list = $$('.count span'); - * expect(list.count()).toBe(2); - * expect(list.get(0).getText()).toBe('First'); - * expect(list.get(1).getText()).toBe('Second'); + * expect(await list.count()).toBe(2); + * expect(await list.get(0).getText()).toBe('First'); + * expect(await list.get(1).getText()).toBe('Second'); * * @param {string} selector a css selector * @returns {ElementArrayFinder} which identifies the diff --git a/lib/expectedConditions.ts b/lib/expectedConditions.ts index 209713608..3bb078554 100644 --- a/lib/expectedConditions.ts +++ b/lib/expectedConditions.ts @@ -16,30 +16,28 @@ import {falseIfMissing, passBoolean} from './util'; * * * @example - * var EC = protractor.ExpectedConditions; - * var button = $('#xyz'); - * var isClickable = EC.elementToBeClickable(button); + * const EC = protractor.ExpectedConditions; + * const button = $('#xyz'); + * const isClickable = EC.elementToBeClickable(button); * - * browser.get(URL); - * browser.wait(isClickable, 5000); //wait for an element to become clickable - * button.click(); + * await browser.get(URL); + * await browser.wait(isClickable, 5000); //wait for an element to become clickable + * await button.click(); * * // You can define your own expected condition, which is a function that * // takes no parameter and evaluates to a promise of a boolean. - * var urlChanged = function() { - * return browser.getCurrentUrl().then(function(url) { - * return url === 'http://www.angularjs.org'; - * }); - * }; + * const urlChanged = async () => { + * return await browser.getCurrentUrl() === 'http://www.angularjs.org'; + * } * * // You can customize the conditions with EC.and, EC.or, and EC.not. * // Here's a condition to wait for url to change, $('abc') element to contain * // text 'bar', and button becomes clickable. - * var condition = EC.and(urlChanged, EC.textToBePresentInElement($('abc'), + * const condition = EC.and(urlChanged, EC.textToBePresentInElement($('abc'), * 'bar'), isClickable); - * browser.get(URL); - * browser.wait(condition, 5000); //wait for condition to be true. - * button.click(); + * await browser.get(URL); + * await browser.wait(condition, 5000); //wait for condition to be true. + * await button.click(); * * @alias ExpectedConditions * @constructor @@ -51,10 +49,10 @@ export class ProtractorExpectedConditions { * Negates the result of a promise. * * @example - * var EC = protractor.ExpectedConditions; - * var titleIsNotFoo = EC.not(EC.titleIs('Foo')); + * const EC = protractor.ExpectedConditions; + * const titleIsNotFoo = EC.not(EC.titleIs('Foo')); * // Waits for title to become something besides 'foo'. - * browser.wait(titleIsNotFoo, 5000); + * await browser.wait(titleIsNotFoo, 5000); * * @alias ExpectedConditions.not * @param {!function} expectedCondition @@ -102,14 +100,14 @@ export class ProtractorExpectedConditions { * at the first expected condition that evaluates to false. * * @example - * var EC = protractor.ExpectedConditions; - * var titleContainsFoo = EC.titleContains('Foo'); - * var titleIsNotFooBar = EC.not(EC.titleIs('FooBar')); + * const EC = protractor.ExpectedConditions; + * const titleContainsFoo = EC.titleContains('Foo'); + * const titleIsNotFooBar = EC.not(EC.titleIs('FooBar')); * // Waits for title to contain 'Foo', but is not 'FooBar' - * browser.wait(EC.and(titleContainsFoo, titleIsNotFooBar), 5000); + * await browser.wait(EC.and(titleContainsFoo, titleIsNotFooBar), 5000); * * @alias ExpectedConditions.and - * @param {Array.} fns An array of expected conditions to 'and' + * @param {Array.} args An array of expected conditions to 'and' * together. * * @returns {!function} An expected condition that returns a promise which @@ -125,13 +123,13 @@ export class ProtractorExpectedConditions { * * @alias ExpectedConditions.or * @example - * var EC = protractor.ExpectedConditions; - * var titleContainsFoo = EC.titleContains('Foo'); - * var titleContainsBar = EC.titleContains('Bar'); + * const EC = protractor.ExpectedConditions; + * const titleContainsFoo = EC.titleContains('Foo'); + * const titleContainsBar = EC.titleContains('Bar'); * // Waits for title to contain either 'Foo' or 'Bar' - * browser.wait(EC.or(titleContainsFoo, titleContainsBar), 5000); + * await browser.wait(EC.or(titleContainsFoo, titleContainsBar), 5000); * - * @param {Array.} fns An array of expected conditions to 'or' + * @param {Array.} args An array of expected conditions to 'or' * together. * * @returns {!function} An expected condition that returns a promise which @@ -145,9 +143,9 @@ export class ProtractorExpectedConditions { * Expect an alert to be present. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for an alert pops up. - * browser.wait(EC.alertIsPresent(), 5000); + * await browser.wait(EC.alertIsPresent(), 5000); * * @alias ExpectedConditions.alertIsPresent * @returns {!function} An expected condition that returns a promise @@ -175,9 +173,9 @@ export class ProtractorExpectedConditions { * can click it. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'abc' to be clickable. - * browser.wait(EC.elementToBeClickable($('#abc')), 5000); + * await browser.wait(EC.elementToBeClickable($('#abc')), 5000); * * @alias ExpectedConditions.elementToBeClickable * @param {!ElementFinder} elementFinder The element to check @@ -196,9 +194,9 @@ export class ProtractorExpectedConditions { * element. Returns false if the elementFinder does not find an element. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'abc' to contain the text 'foo'. - * browser.wait(EC.textToBePresentInElement($('#abc'), 'foo'), 5000); + * await browser.wait(EC.textToBePresentInElement($('#abc'), 'foo'), 5000); * * @alias ExpectedConditions.textToBePresentInElement * @param {!ElementFinder} elementFinder The element to check @@ -223,9 +221,9 @@ export class ProtractorExpectedConditions { * value. Returns false if the elementFinder does not find an element. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'myInput' to contain the input 'foo'. - * browser.wait(EC.textToBePresentInElementValue($('#myInput'), 'foo'), 5000); + * await browser.wait(EC.textToBePresentInElementValue($('#myInput'), 'foo'), 5000); * * @alias ExpectedConditions.textToBePresentInElementValue * @param {!ElementFinder} elementFinder The element to check @@ -248,9 +246,9 @@ export class ProtractorExpectedConditions { * substring. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the title to contain 'foo'. - * browser.wait(EC.titleContains('foo'), 5000); + * await browser.wait(EC.titleContains('foo'), 5000); * * @alias ExpectedConditions.titleContains * @param {!string} title The fragment of title expected @@ -270,9 +268,9 @@ export class ProtractorExpectedConditions { * An expectation for checking the title of a page. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the title to be 'foo'. - * browser.wait(EC.titleIs('foo'), 5000); + * await browser.wait(EC.titleIs('foo'), 5000); * * @alias ExpectedConditions.titleIs * @param {!string} title The expected title, which must be an exact match. @@ -293,9 +291,9 @@ export class ProtractorExpectedConditions { * substring. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the URL to contain 'foo'. - * browser.wait(EC.urlContains('foo'), 5000); + * await browser.wait(EC.urlContains('foo'), 5000); * * @alias ExpectedConditions.urlContains * @param {!string} url The fragment of URL expected @@ -315,9 +313,9 @@ export class ProtractorExpectedConditions { * An expectation for checking the URL of a page. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the URL to be 'foo'. - * browser.wait(EC.urlIs('foo'), 5000); + * await browser.wait(EC.urlIs('foo'), 5000); * * @alias ExpectedConditions.urlIs * @param {!string} url The expected URL, which must be an exact match. @@ -339,9 +337,9 @@ export class ProtractorExpectedConditions { * This is the opposite of 'stalenessOf'. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'abc' to be present on the dom. - * browser.wait(EC.presenceOf($('#abc')), 5000); + * await browser.wait(EC.presenceOf($('#abc')), 5000); * * @alias ExpectedConditions.presenceOf * @param {!ElementFinder} elementFinder The element to check @@ -358,9 +356,9 @@ export class ProtractorExpectedConditions { * of a page. This is the opposite of 'presenceOf'. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'abc' to be no longer present on the dom. - * browser.wait(EC.stalenessOf($('#abc')), 5000); + * await browser.wait(EC.stalenessOf($('#abc')), 5000); * * @alias ExpectedConditions.stalenessOf * @param {!ElementFinder} elementFinder The element to check @@ -380,9 +378,9 @@ export class ProtractorExpectedConditions { * of 'invisibilityOf'. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'abc' to be visible on the dom. - * browser.wait(EC.visibilityOf($('#abc')), 5000); + * await browser.wait(EC.visibilityOf($('#abc')), 5000); * * @alias ExpectedConditions.visibilityOf * @param {!ElementFinder} elementFinder The element to check @@ -401,9 +399,9 @@ export class ProtractorExpectedConditions { * present on the DOM. This is the opposite of 'visibilityOf'. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'abc' to be no longer visible on the dom. - * browser.wait(EC.invisibilityOf($('#abc')), 5000); + * await browser.wait(EC.invisibilityOf($('#abc')), 5000); * * @alias ExpectedConditions.invisibilityOf * @param {!ElementFinder} elementFinder The element to check @@ -419,9 +417,9 @@ export class ProtractorExpectedConditions { * An expectation for checking the selection is selected. * * @example - * var EC = protractor.ExpectedConditions; + * const EC = protractor.ExpectedConditions; * // Waits for the element with id 'myCheckbox' to be selected. - * browser.wait(EC.elementToBeSelected($('#myCheckbox')), 5000); + * await browser.wait(EC.elementToBeSelected($('#myCheckbox')), 5000); * * @alias ExpectedConditions.elementToBeSelected * @param {!ElementFinder} elementFinder The element to check diff --git a/lib/locators.ts b/lib/locators.ts index 8d942cc0a..6471ae850 100644 --- a/lib/locators.ts +++ b/lib/locators.ts @@ -66,7 +66,7 @@ export class ProtractorBy extends WebdriverBy { * }); * * // Use the custom locator. - * element(by.buttonTextSimple('Go!')).click(); + * await element(by.buttonTextSimple('Go!')).click(); * * @alias by.addLocator(locatorName, functionOrScript) * @param {string} name The name of the new locator. @@ -115,14 +115,14 @@ export class ProtractorBy extends WebdriverBy { * * @example * var span1 = element(by.binding('person.name')); - * expect(span1.getText()).toBe('Foo'); + * expect(await span1.getText()).toBe('Foo'); * * var span2 = element(by.binding('person.email')); - * expect(span2.getText()).toBe('foo@bar.com'); + * expect(await span2.getText()).toBe('foo@bar.com'); * * // You can also use a substring for a partial match * var span1alt = element(by.binding('name')); - * expect(span1alt.getText()).toBe('Foo'); + * expect(await span1alt.getText()).toBe('Foo'); * * // This works for sites using Angular 1.2 but NOT 1.3 * var deprecatedSyntax = element(by.binding('{{person.name}}')); @@ -154,12 +154,12 @@ export class ProtractorBy extends WebdriverBy { * {{person_phone|uppercase}} * * @example - * expect(element(by.exactBinding('person.name')).isPresent()).toBe(true); - * expect(element(by.exactBinding('person-email')).isPresent()).toBe(true); - * expect(element(by.exactBinding('person')).isPresent()).toBe(false); - * expect(element(by.exactBinding('person_phone')).isPresent()).toBe(true); - * expect(element(by.exactBinding('person_phone|uppercase')).isPresent()).toBe(true); - * expect(element(by.exactBinding('phone')).isPresent()).toBe(false); + * expect(await element(by.exactBinding('person.name')).isPresent()).toBe(true); + * expect(await element(by.exactBinding('person-email')).isPresent()).toBe(true); + * expect(await element(by.exactBinding('person')).isPresent()).toBe(false); + * expect(await element(by.exactBinding('person_phone')).isPresent()).toBe(true); + * expect(await element(by.exactBinding('person_phone|uppercase')).isPresent()).toBe(true); + * expect(await element(by.exactBinding('phone')).isPresent()).toBe(false); * * @param {string} bindingDescriptor * @returns {ProtractorLocator} location strategy @@ -188,8 +188,8 @@ export class ProtractorBy extends WebdriverBy { * * @example * var input = element(by.model('person.name')); - * input.sendKeys('123'); - * expect(input.getAttribute('value')).toBe('Foo123'); + * await input.sendKeys('123'); + * expect(await input.getAttribute('value')).toBe('Foo123'); * * @param {string} model ng-model expression. * @returns {ProtractorLocator} location strategy @@ -356,37 +356,36 @@ export class ProtractorBy extends WebdriverBy { * * @example * // Returns the DIV for the second cat. - * var secondCat = element(by.repeater('cat in pets').row(1)); + * let secondCat = element(by.repeater('cat in pets').row(1)); * * // Returns the SPAN for the first cat's name. - * var firstCatName = element(by.repeater('cat in pets'). + * let firstCatName = element(by.repeater('cat in pets'). * row(0).column('cat.name')); * * // Returns a promise that resolves to an array of WebElements from a column - * var ages = element.all( - * by.repeater('cat in pets').column('cat.age')); + * let ages = element.all(by.repeater('cat in pets').column('cat.age')); * * // Returns a promise that resolves to an array of WebElements containing * // all top level elements repeated by the repeater. For 2 pets rows * // resolves to an array of 2 elements. - * var rows = element.all(by.repeater('cat in pets')); + * let rows = element.all(by.repeater('cat in pets')); * * // Returns a promise that resolves to an array of WebElements containing * // all the elements with a binding to the book's name. - * var divs = element.all(by.repeater('book in library').column('book.name')); + * let divs = element.all(by.repeater('book in library').column('book.name')); * * // Returns a promise that resolves to an array of WebElements containing * // the DIVs for the second book. - * var bookInfo = element.all(by.repeater('book in library').row(1)); + * let bookInfo = element.all(by.repeater('book in library').row(1)); * * // Returns the H4 for the first book's name. - * var firstBookName = element(by.repeater('book in library'). + * let firstBookName = element(by.repeater('book in library'). * row(0).column('book.name')); * * // Returns a promise that resolves to an array of WebElements containing * // all top level elements repeated by the repeater. For 2 books divs * // resolves to an array of 4 elements. - * var divs = element.all(by.repeater('book in library')); + * let divs = element.all(by.repeater('book in library')); * * @param {string} repeatDescriptor * @returns {ProtractorLocator} location strategy @@ -403,12 +402,9 @@ export class ProtractorBy extends WebdriverBy { *
  • * * @example - * expect(element(by.exactRepeater('person in - * peopleWithRedHair')).isPresent()) - * .toBe(true); - * expect(element(by.exactRepeater('person in - * people')).isPresent()).toBe(false); - * expect(element(by.exactRepeater('car in cars')).isPresent()).toBe(true); + * expect(await element(by.exactRepeater('person in peopleWithRedHair')).isPresent()).toBe(true); + * expect(await element(by.exactRepeater('person in people')).isPresent()).toBe(false); + * expect(await element(by.exactRepeater('car in cars')).isPresent()).toBe(true); * * @param {string} repeatDescriptor * @returns {ProtractorLocator} location strategy @@ -431,7 +427,7 @@ export class ProtractorBy extends WebdriverBy { * var dog = element(by.cssContainingText('.pet', 'Dog')); * * @param {string} cssSelector css selector - * @param {string|RegExp} searchString text search + * @param {string|RegExp} searchText text search * @returns {ProtractorLocator} location strategy */ cssContainingText(cssSelector: string, searchText: string|RegExp): ProtractorLocator { @@ -462,9 +458,9 @@ export class ProtractorBy extends WebdriverBy { * * @example * var allOptions = element.all(by.options('c for c in colors')); - * expect(allOptions.count()).toEqual(2); + * expect(await allOptions.count()).toEqual(2); * var firstOption = allOptions.first(); - * expect(firstOption.getText()).toEqual('red'); + * expect(await firstOption.getText()).toEqual('red'); * * @param {string} optionsDescriptor ng-options expression. * @returns {ProtractorLocator} location strategy @@ -500,7 +496,7 @@ export class ProtractorBy extends WebdriverBy { * * @example * var spans = element.all(by.deepCss('span')); - * expect(spans.count()).toEqual(3); + * expect(await spans.count()).toEqual(3); * * @param {string} selector a css selector within the Shadow DOM. * @returns {Locator} location strategy