Skip to content

Commit

Permalink
[selenium-webdriver] Allow Condition.fn to return Promise<T> and null (
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangYiJiang authored May 27, 2021
1 parent c51eb58 commit c740cad
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions types/selenium-webdriver/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ export namespace error {
function encodeError(err: any): {error: string, message: string};
}

type ConditionFn<T> = (webdriver: WebDriver) => T | null | Promise<T | null>;

/**
* Defines a condition for use with WebDriver's WebDriver#wait wait command.
*/
Expand All @@ -319,13 +321,13 @@ export class Condition<T> {
* evaluate on each iteration of the wait loop.
* @constructor
*/
constructor(message: string, fn: (webdriver: WebDriver) => T);
constructor(message: string, fn: ConditionFn<T>);

/** @return {string} A description of this condition. */
description(): string;

/** @type {function(!WebDriver): OUT} */
fn(webdriver: WebDriver): T;
fn(webdriver: WebDriver): ConditionFn<T>;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions types/selenium-webdriver/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,11 @@ function TestWebElementPromise() {
elementPromise.then((element: webdriver.WebElement) => 'foo', (error: any) => 'bar').then((result: string) => {});
}

function testCondition() {
const conditionString = new webdriver.Condition<string>('message', () => Math.random() > 0.5 ? 'foo' : null);
const conditionStringPromise = new webdriver.Condition<string>('message', async () => Math.random() > 0.5 ? 'foo' : null);
}

declare let stringPromise: Promise<string>;

function TestUntilModule() {
Expand Down

0 comments on commit c740cad

Please sign in to comment.