From c740cad71c3638b2966e8435e8beb57ca7bc88dc Mon Sep 17 00:00:00 2001 From: Zhang Yi Jiang Date: Thu, 27 May 2021 15:46:23 -0700 Subject: [PATCH] [selenium-webdriver] Allow Condition.fn to return Promise and null (#53444) --- types/selenium-webdriver/index.d.ts | 6 ++++-- types/selenium-webdriver/test/index.ts | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/types/selenium-webdriver/index.d.ts b/types/selenium-webdriver/index.d.ts index 06eba6afa33ad9..7dc46c5ee563da 100644 --- a/types/selenium-webdriver/index.d.ts +++ b/types/selenium-webdriver/index.d.ts @@ -308,6 +308,8 @@ export namespace error { function encodeError(err: any): {error: string, message: string}; } +type ConditionFn = (webdriver: WebDriver) => T | null | Promise; + /** * Defines a condition for use with WebDriver's WebDriver#wait wait command. */ @@ -319,13 +321,13 @@ export class Condition { * evaluate on each iteration of the wait loop. * @constructor */ - constructor(message: string, fn: (webdriver: WebDriver) => T); + constructor(message: string, fn: ConditionFn); /** @return {string} A description of this condition. */ description(): string; /** @type {function(!WebDriver): OUT} */ - fn(webdriver: WebDriver): T; + fn(webdriver: WebDriver): ConditionFn; } /** diff --git a/types/selenium-webdriver/test/index.ts b/types/selenium-webdriver/test/index.ts index f92bfb7b64dd6a..cc5222121e1600 100644 --- a/types/selenium-webdriver/test/index.ts +++ b/types/selenium-webdriver/test/index.ts @@ -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('message', () => Math.random() > 0.5 ? 'foo' : null); + const conditionStringPromise = new webdriver.Condition('message', async () => Math.random() > 0.5 ? 'foo' : null); +} + declare let stringPromise: Promise; function TestUntilModule() {