Skip to content

Commit acb3170

Browse files
update logs and readme
1 parent bd7d990 commit acb3170

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ driver.findElementByAccessibilityId("login").click();
4949
driver.findElementByAccessibilityId("slider1").click();
5050
driver.findElementByAccessibilityId("login").sendKeys('Hello');
5151
```
52+
53+
Server logs will be as below:
54+
55+
```
56+
[Appium] Plugin element-wait (sessionless) is now handling cmd 'findElement'
57+
[Plugin [element-wait (sessionless)]] Retrying to find element with accessibility id strategy for login selector
58+
[Plugin [element-wait (sessionless)]] Retrying to find element with accessibility id strategy for login selector
59+
[Plugin [element-wait (sessionless)]] Retrying to find element with accessibility id strategy for login selector
60+
[Plugin [element-wait (sessionless)]] Element with accessibility id strategy for login selector found.
61+
[Plugin [element-wait (sessionless)]] Checking if login element is displayed
62+
[Plugin [element-wait (sessionless)]] login element is displayed.
63+
```

src/plugin.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ import fetch from 'node-fetch';
44
let retryCount = 0;
55
export 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

Comments
 (0)