(elementLocator: By, timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM)
| 635 | } |
| 636 | |
| 637 | async waitAndGetText(elementLocator: By, timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM): Promise<string> { |
| 638 | const polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING; |
| 639 | const attempts: number = Math.ceil(timeout / polling); |
| 640 | Logger.trace(`${elementLocator}`); |
| 641 | |
| 642 | for (let i: number = 0; i < attempts; i++) { |
| 643 | let element: WebElement; |
| 644 | try { |
| 645 | element = await this.waitVisibility(elementLocator, polling); |
| 646 | } catch (err) { |
| 647 | if (i >= attempts - 1) { |
| 648 | Logger.error(`failed with exception, out of attempts - ${err}`); |
| 649 | throw err; |
| 650 | } |
| 651 | |
| 652 | if (err instanceof error.TimeoutError) { |
| 653 | Logger.trace(`polling timed out attempt #${i + 1}, retrying with ${polling}ms timeout`); |
| 654 | continue; |
| 655 | } |
| 656 | |
| 657 | Logger.error(`failed with an unexpected exception - ${err}`); |
| 658 | throw err; |
| 659 | } |
| 660 | |
| 661 | try { |
| 662 | return await element.getText(); |
| 663 | } catch (err) { |
| 664 | if (err instanceof error.StaleElementReferenceError) { |
| 665 | await this.wait(polling); |
| 666 | continue; |
| 667 | } |
| 668 | |
| 669 | Logger.error(`failed with an unexpected exception - ${err}`); |
| 670 | throw err; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | throw new error.TimeoutError(`Exceeded maximum text obtaining attempts, from the '${elementLocator}' element`); |
| 675 | } |
| 676 | |
| 677 | async waitAndGetValue(elementLocator: By, timeout: number): Promise<string> { |
| 678 | Logger.trace(`${elementLocator}`); |
no test coverage detected