( elementLocator: By, attribute: string, timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM )
| 314 | } |
| 315 | |
| 316 | async waitAndGetElementAttribute( |
| 317 | elementLocator: By, |
| 318 | attribute: string, |
| 319 | timeout: number = TIMEOUT_CONSTANTS.TS_SELENIUM_CLICK_ON_VISIBLE_ITEM |
| 320 | ): Promise<string> { |
| 321 | const polling: number = TIMEOUT_CONSTANTS.TS_SELENIUM_DEFAULT_POLLING; |
| 322 | const attempts: number = Math.ceil(timeout / polling); |
| 323 | Logger.trace(`${elementLocator} attribute: '${attribute}'`); |
| 324 | |
| 325 | for (let i: number = 0; i < attempts; i++) { |
| 326 | let element: WebElement; |
| 327 | try { |
| 328 | element = await this.waitVisibility(elementLocator, polling); |
| 329 | } catch (err) { |
| 330 | if (i >= attempts - 1) { |
| 331 | Logger.error(`failed with exception, out of attempts - ${err}`); |
| 332 | throw err; |
| 333 | } |
| 334 | |
| 335 | if (err instanceof error.TimeoutError) { |
| 336 | Logger.trace(`polling timed out attempt #${i + 1}, retrying with ${polling}ms timeout`); |
| 337 | continue; |
| 338 | } |
| 339 | |
| 340 | Logger.error(`failed with an unexpected exception - ${err}`); |
| 341 | throw err; |
| 342 | } |
| 343 | |
| 344 | try { |
| 345 | return await element.getAttribute(attribute); |
| 346 | } catch (err) { |
| 347 | if (err instanceof error.StaleElementReferenceError) { |
| 348 | await this.wait(polling); |
| 349 | continue; |
| 350 | } |
| 351 | |
| 352 | Logger.error(`failed with an unexpected exception - ${err}`); |
| 353 | throw err; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | throw new error.TimeoutError( |
| 358 | `Exceeded maximum gettin of the '${attribute}' attribute attempts, from the '${elementLocator}' element` |
| 359 | ); |
| 360 | } |
| 361 | |
| 362 | async waitAndGetCssValue( |
| 363 | elementLocator: By, |
no test coverage detected