This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
chore(test): clean up no control flow typescript tests #5023
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<void>(); | ||
let deferredA: Promise<void>; | ||
els = applyAction_.call(els, () => { | ||
return deferredA.promise.then(() => { | ||
deferredA = new Promise<void>(resolve => { | ||
order.push('a'); | ||
resolve(); | ||
}); | ||
}); | ||
let deferredB = q.defer<void>(); | ||
let deferredB: Promise<void>; | ||
els = applyAction_.call(els, () => { | ||
return deferredB.promise.then(() => { | ||
deferredB = new Promise<void>(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<void>), | ||
} as any as (() => Promise<boolean>), | ||
function() { | ||
return false; | ||
} as any as (() => ppromise.Promise<void>)); | ||
await expect(successful).toEqual(false); | ||
} as any as (() => Promise<boolean>)); | ||
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<void>)); | ||
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); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wat? Can't this at least be (usernameInput.clear() as ElementFinder)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. wat is right. I might need to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casting it just directly to
ElementFinder
does not work as shown above. Per the documentation, the return type iswebdriver.promise.Promise.<void>
so I'm not sure how this actually works. Shouldn't it return a promise for an ElementFinder? That would make more sense.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, yeah it should be
as Promise<ElementFinder>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a TODO to fix this and it is logged as an issue.