@@ -4,25 +4,25 @@ import fetch from 'node-fetch';
44let retryCount = 0 ;
55export default class WaitCommandPlugin extends BasePlugin {
66 async findElement ( next , driver , ...args ) {
7- const locatorArgs = JSON . parse ( JSON . stringify ( args ) ) ;
87 let originalRes ;
8+ const locatorArgs = JSON . parse ( JSON . stringify ( args ) ) ;
9+ this . strategy = locatorArgs [ 0 ] ;
10+ this . selector = locatorArgs [ 1 ] ;
911 await this . _find ( driver , locatorArgs ) ;
1012 await this . _elementDisplayed ( driver ) ;
1113 originalRes = await next ( ) ;
1214 retryCount = 0 ;
1315 return originalRes ;
1416 }
1517
16- async _find ( driver , locatorArgs ) {
17- const strategy = locatorArgs [ 0 ] ;
18- const selector = locatorArgs [ 1 ] ;
18+ async _find ( driver ) {
1919 const baseUrl = this . _constructSessionUrl ( driver ) ;
2020 const response = await fetch (
2121 `${ baseUrl } wd/hub/session/${ driver . sessionId } /element` ,
2222 {
2323 body : JSON . stringify ( {
24- strategy,
25- selector,
24+ strategy : this . strategy ,
25+ selector : this . selector ,
2626 context : '' ,
2727 multiple : false ,
2828 } ) ,
@@ -34,23 +34,24 @@ export default class WaitCommandPlugin extends BasePlugin {
3434 if ( json . value . error ) {
3535 if ( retryCount !== 25 ) {
3636 this . logger . info (
37- `Retrying to find element with ${ strategy } strategy for ${ selector } selector`
37+ `Retrying to find element with ${ this . strategy } strategy for ${ this . selector } selector`
3838 ) ;
3939 retryCount ++ ;
40- await this . _find ( driver , locatorArgs ) ;
40+ await this . _find ( driver ) ;
4141 }
4242 }
4343
4444 if ( json . sessionId && json . value . ELEMENT ) {
4545 this . element = json . value . ELEMENT ;
4646 this . logger . info (
47- `Element with ${ strategy } strategy for ${ selector } selector found.`
47+ `Element with ${ this . strategy } strategy for ${ this . selector } selector found.`
4848 ) ;
49+ retryCount = 0 ;
4950 }
5051 }
5152
5253 async _elementDisplayed ( driver ) {
53- this . logger . info ( ' Checking if element is displayed' ) ;
54+ this . logger . info ( ` Checking if ${ this . selector } element is displayed` ) ;
5455 const baseUrl = this . _constructSessionUrl ( driver ) ;
5556 const response = await fetch (
5657 `${ baseUrl } wd/hub/session/${ driver . sessionId } /element/${ this . element } /attribute/displayed` ,
@@ -63,14 +64,15 @@ export default class WaitCommandPlugin extends BasePlugin {
6364 if ( json . value . error ) {
6465 if ( retryCount !== 25 ) {
6566 this . logger . info (
66- `Retrying to check whether ${ this . element } element is displayed or not`
67+ `Retrying to check whether ${ this . selector } element is displayed or not`
6768 ) ;
6869 retryCount ++ ;
6970 await this . _elementDisplayed ( driver ) ;
7071 }
7172 }
7273 if ( json . sessionId && json . value === 'true' ) {
73- this . logger . info ( `Element with ${ this . element } id is displayed.` ) ;
74+ this . logger . info ( `${ this . selector } element is displayed.` ) ;
75+ retryCount = 0 ;
7476 }
7577 }
7678
0 commit comments