(elementLocator: By, text: string, timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM)
| 438 | } |
| 439 | |
| 440 | async type(elementLocator: By, text: string, timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM): Promise<void> { |
| 441 | const polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING; |
| 442 | const attempts: number = Math.ceil(timeout / polling); |
| 443 | |
| 444 | if (elementLocator.toString().toLocaleLowerCase().includes('password')) { |
| 445 | Logger.trace(`${elementLocator} text: ***`); |
| 446 | } else { |
| 447 | Logger.trace(`${elementLocator} text: ${text}`); |
| 448 | } |
| 449 | |
| 450 | for (let i: number = 0; i < attempts; i++) { |
| 451 | let element: WebElement; |
| 452 | try { |
| 453 | element = await this.waitVisibility(elementLocator, polling); |
| 454 | } catch (err) { |
| 455 | if (i >= attempts - 1) { |
| 456 | Logger.error(`failed with exception, out of attempts - ${err}`); |
| 457 | throw err; |
| 458 | } |
| 459 | |
| 460 | if (err instanceof error.TimeoutError) { |
| 461 | Logger.trace(`polling timed out attempt #${i + 1}, retrying with ${polling}ms timeout`); |
| 462 | continue; |
| 463 | } |
| 464 | |
| 465 | Logger.error(`failed with an unexpected exception - ${err}`); |
| 466 | throw err; |
| 467 | } |
| 468 | |
| 469 | try { |
| 470 | await element.sendKeys(text); |
| 471 | return; |
| 472 | } catch (err) { |
| 473 | if (err instanceof error.StaleElementReferenceError) { |
| 474 | await this.wait(polling); |
| 475 | continue; |
| 476 | } |
| 477 | |
| 478 | Logger.error(`failed with an unexpected exception - ${err}`); |
| 479 | throw err; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | throw new error.TimeoutError(`Exceeded maximum typing attempts, to the '${elementLocator}' element`); |
| 484 | } |
| 485 | |
| 486 | async typeToInvisible( |
| 487 | elementLocator: By, |
no test coverage detected