diff --git a/scripts/test.js b/scripts/test.js index 64665d2fb..db542db32 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -39,9 +39,9 @@ var passingTests = [ // 'node built/cli.js spec/noGlobalsConf.js', // 'node built/cli.js spec/angular2Conf.js', // 'node built/cli.js spec/hybridConf.js', - // 'node built/cli.js spec/built/noCFBasicConf.js', - // 'node built/cli.js spec/built/noCFBasicConf.js --useBlockingProxy', - // 'node built/cli.js spec/built/noCFPluginConf.js', + 'node built/cli.js spec/built/noCFBasicConf.js', + 'node built/cli.js spec/built/noCFBasicConf.js --useBlockingProxy', + 'node built/cli.js spec/built/noCFPluginConf.js', // //'node scripts/driverProviderAttachSession.js', // 'node built/cli.js spec/driverProviderUseExistingWebDriver.js', // 'node built/cli.js spec/driverProviderUseExistingWebDriver.js --useBlockingProxy', diff --git a/spec/ts/basic/element_spec.ts b/spec/ts/basic/element_spec.ts index 18ca6a7da..faabd61a5 100644 --- a/spec/ts/basic/element_spec.ts +++ b/spec/ts/basic/element_spec.ts @@ -1,186 +1,191 @@ // Based off of spec/basic/elements_spec.js import * as q from 'q'; -import {$, $$, browser, by, By, element, ElementArrayFinder, ElementFinder, ExpectedConditions, promise as ppromise, WebElement} from '../../..'; +import {$, browser, by, element, ElementArrayFinder, ElementFinder, promise as ppromise, WebElement} from '../../..'; -describe('ElementFinder', function() { - it('should return the same result as browser.findElement', async function() { +describe('ElementFinder', () => { + it('should return the same result as browser.findElement', async() => { await browser.get('index.html#/form'); const nameByElement = element(by.binding('username')); - await expect(nameByElement.getText()) - .toEqual(browser.findElement(by.binding('username')).getText()); + expect(await nameByElement.getText()) + .toEqual(await browser.findElement(by.binding('username')).getText()); }); - it('should wait to grab the WebElement until a method is called', async function() { + it('should wait to grab the WebElement until a method is called', async() => { // These should throw no error before a page is loaded. const usernameInput = element(by.model('username')); const name = element(by.binding('username')); await browser.get('index.html#/form'); - await expect(name.getText()).toEqual('Anon'); + expect(await name.getText()).toEqual('Anon'); await usernameInput.clear(); await usernameInput.sendKeys('Jane'); - await expect(name.getText()).toEqual('Jane'); + expect(await name.getText()).toEqual('Jane'); }); - it('should chain element actions', async function() { + it('should chain element actions', async() => { await browser.get('index.html#/form'); const usernameInput = element(by.model('username')); const name = element(by.binding('username')); - await expect(name.getText()).toEqual('Anon'); + expect(await name.getText()).toEqual('Anon'); await((usernameInput.clear() as any) as ElementFinder).sendKeys('Jane'); - await expect(name.getText()).toEqual('Jane'); + expect(await name.getText()).toEqual('Jane'); }); - it('should run chained element actions in sequence', function(done: any) { + it('should run chained element actions in sequence', async(done: any) => { // Testing private methods is bad :( let els = new ElementArrayFinder(browser, () => { - return ppromise.when([null as WebElement]); + return Promise.resolve([null as WebElement]); }); let applyAction_: (actionFn: (value: WebElement, index: number, array: WebElement[]) => any) => ElementArrayFinder = (ElementArrayFinder as any).prototype.applyAction_; let order: string[] = []; - let deferredA = q.defer(); + let deferredA: Promise; els = applyAction_.call(els, () => { - return deferredA.promise.then(() => { + deferredA = new Promise(resolve => { order.push('a'); + resolve(); }); }); - let deferredB = q.defer(); + let deferredB: Promise; els = applyAction_.call(els, () => { - return deferredB.promise.then(() => { + deferredB = new Promise(resolve => { order.push('b'); + resolve(); }); }); - deferredB.resolve(); + await deferredB; setTimeout(async function() { - deferredA.resolve(); + await deferredA; await els; expect(order).toEqual(['a', 'b']); done(); }, 100); }); - it('chained call should wait to grab the WebElement until a method is called', async function() { + it('chained call should wait to grab the WebElement until a method is called', + async() => { // These should throw no error before a page is loaded. - const reused = element(by.id('baz')).element(by.binding('item.reusedBinding')); + const reused = element(by.id('baz')) + .element(by.binding('item.reusedBinding')); await browser.get('index.html#/conflict'); - await expect(reused.getText()).toEqual('Inner: inner'); - await expect(reused.isPresent()).toBe(true); + expect(await reused.getText()).toEqual('Inner: inner'); + expect(await reused.isPresent()).toBe(true); }); - it('should differentiate elements with the same binding by chaining', async function() { + it('should differentiate elements with the same binding by chaining', + async() => { await browser.get('index.html#/conflict'); const outerReused = element(by.binding('item.reusedBinding')); const innerReused = element(by.id('baz')).element(by.binding('item.reusedBinding')); - await expect(outerReused.getText()).toEqual('Outer: outer'); - await expect(innerReused.getText()).toEqual('Inner: inner'); + expect(await outerReused.getText()).toEqual('Outer: outer'); + expect(await innerReused.getText()).toEqual('Inner: inner'); }); - it('should chain deeper than 2', async function() { + it('should chain deeper than 2', async() => { // These should throw no error before a page is loaded. - const reused = - element(by.css('body')).element(by.id('baz')).element(by.binding('item.reusedBinding')); + const reused = element(by.css('body')).element(by.id('baz')) + .element(by.binding('item.reusedBinding')); await browser.get('index.html#/conflict'); - await expect(reused.getText()).toEqual('Inner: inner'); + expect(await reused.getText()).toEqual('Inner: inner'); }); - it('should allow handling errors', async function() { + it('should allow handling errors', async() => { await browser.get('index.html#/form'); try { await $('.nopenopenope').getText(); // The above line should have throw an error. Fail. - await expect(true).toEqual(false); + expect(true).toEqual(false); } catch (e) { - await expect(true).toEqual(true); + expect(true).toEqual(true); } }); - it('should allow handling chained errors', async function() { + it('should allow handling chained errors', async() => { await browser.get('index.html#/form'); try { await $('.nopenopenope').$('furthernope').getText(); // The above line should have throw an error. Fail. - await expect(true).toEqual(false); + expect(true).toEqual(false); } catch (e) { - await expect(true).toEqual(true); + expect(true).toEqual(true); } }); - it('should keep a reference to the original locator', async function() { + it('should keep a reference to the original locator', async() => { await browser.get('index.html#/form'); const byCss = by.css('body'); const byBinding = by.binding('greet'); - await expect(element(byCss).locator()).toEqual(byCss); - await expect(element(byBinding).locator()).toEqual(byBinding); + expect(await element(byCss).locator()).toEqual(byCss); + expect(await element(byBinding).locator()).toEqual(byBinding); }); - it('should propagate exceptions', async function() { + it('should propagate exceptions', async() => { await browser.get('index.html#/form'); const invalidElement = element(by.binding('INVALID')); const successful = invalidElement.getText().then( function() { return true; - } as any as (() => ppromise.Promise), + } as any as (() => Promise), function() { return false; - } as any as (() => ppromise.Promise)); - await expect(successful).toEqual(false); + } as any as (() => Promise)); + expect(await successful).toEqual(false); }); - it('should be returned from a helper without infinite loops', async function() { + it('should be returned from a helper without infinite loops', async() => { await browser.get('index.html#/form'); - const helperPromise = ppromise.when(true).then(function() { + const helperPromise = Promise.resolve(true).then(() => { return element(by.binding('greeting')); }); - await helperPromise.then(async function(finalResult: ElementFinder) { - await expect(finalResult.getText()).toEqual('Hiya'); - } as any as (() => ppromise.Promise)); + await helperPromise.then(async(finalResult: ElementFinder) => { + expect(await finalResult.getText()).toEqual('Hiya'); + }); }); - it('should be usable in WebDriver functions', async function() { + it('should be usable in WebDriver functions', async() => { await browser.get('index.html#/form'); const greeting = element(by.binding('greeting')); await browser.executeScript('arguments[0].scrollIntoView', greeting); }); - it('should allow null as success handler', async function() { + it('should allow null as success handler', async() => { await browser.get('index.html#/form'); const name = element(by.binding('username')); - await expect(name.getText()).toEqual('Anon'); - await expect(name.getText().then(null, function() {})).toEqual('Anon'); + expect(await name.getText()).toEqual('Anon'); + expect(await name.getText().then(null, function() {})).toEqual('Anon'); }); - it('should check equality correctly', async function() { + it('should check equality correctly', async() => { await browser.get('index.html#/form'); const usernameInput = element(by.model('username')); const name = element(by.binding('username')); - await expect(usernameInput.equals(usernameInput)).toEqual(true); - await expect(usernameInput.equals(name)).toEqual(false); + expect(await usernameInput.equals(usernameInput)).toEqual(true); + expect(await usernameInput.equals(name)).toEqual(false); }); }); diff --git a/spec/ts/basic/is_disabled_spec.ts b/spec/ts/basic/is_disabled_spec.ts index 0ccc20ff8..7b906aae3 100644 --- a/spec/ts/basic/is_disabled_spec.ts +++ b/spec/ts/basic/is_disabled_spec.ts @@ -1,11 +1,11 @@ import {browser, promise as ppromise} from '../../..'; -describe('verify control flow is off', function() { +describe('verify control flow is off', () => { it('should have set webdriver.promise.USE_PROMISE_MANAGER', () => { expect((ppromise as any).USE_PROMISE_MANAGER).toBe(false); }); - it('should not wait on one command before starting another', async function() { + it('should not wait on one command before starting another', async() => { // Wait forever browser.controlFlow().wait( (browser.controlFlow() as any).promise((): void => undefined) as ppromise.Promise); diff --git a/spec/ts/noCFPluginConf.ts b/spec/ts/noCFPluginConf.ts index fac32bf7a..3f62f7319 100644 --- a/spec/ts/noCFPluginConf.ts +++ b/spec/ts/noCFPluginConf.ts @@ -1,6 +1,4 @@ -import * as q from 'q'; import {Config, protractor} from '../..'; -import {promise as wdpromise} from 'selenium-webdriver'; const env = require('../environment.js'); export let config: Config = { @@ -20,11 +18,11 @@ export let config: Config = { plugins: [{ inline: { - onPageLoad: function() { - //TODO: remove cast when @types/selenium-webdriver understands disabling the control flow - return (q.delay(100) as any as wdpromise.Promise).then(function() { - (protractor as any).ON_PAGE_LOAD = true; + onPageLoad: async function() { + await new Promise(resolve => { + setTimeout(resolve, 100); }); + (protractor as any).ON_PAGE_LOAD = true; } } }] diff --git a/spec/ts/plugin/plugin_spec.ts b/spec/ts/plugin/plugin_spec.ts index 2ee4cc2b5..bcbfdc84b 100644 --- a/spec/ts/plugin/plugin_spec.ts +++ b/spec/ts/plugin/plugin_spec.ts @@ -1,8 +1,8 @@ import {browser, protractor} from '../../..'; -describe('plugins', function() { - it('should have run the onPageLoad hook', async function() { +describe('plugins', () => { + it('should have run the onPageLoad hook', async() => { await browser.get('index.html'); - await expect((protractor as any).ON_PAGE_LOAD).toBe(true); + expect((protractor as any).ON_PAGE_LOAD).toBe(true); }); });