Skip to content

Commit e5e14e9

Browse files
committed
check if element is displayed after element is found
1 parent deaa9ed commit e5e14e9

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"build": "babel src -d lib",
9-
"prepublish": "babel src -d lib"
9+
"prepublish": "babel src -d lib",
10+
"prettier": "prettier --write --single-quote"
1011
},
1112
"repository": {
1213
"type": "git",
@@ -49,8 +50,8 @@
4950
"npm": ">=6"
5051
},
5152
"lint-staged": {
52-
"**/**/*.{js,jsx,ts,tsx,json,css,scss,md}": [
53-
"prettier --write --single-quote",
53+
"src/*.{js,jsx,ts,tsx,json,css,scss,md}": [
54+
"npm run prettier",
5455
"git add"
5556
]
5657
},

src/plugin.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default class WaitCommandPlugin extends BasePlugin {
77
const locatorArgs = JSON.parse(JSON.stringify(args));
88
let originalRes;
99
await this._find(driver, locatorArgs);
10+
await this._elementDisplayed(driver);
1011
originalRes = await next();
1112
retryCount = 0;
1213
return originalRes;
@@ -39,6 +40,24 @@ export default class WaitCommandPlugin extends BasePlugin {
3940
await this._find(driver, locatorArgs);
4041
}
4142
}
43+
44+
if (json.sessionId) {
45+
this.element = json.value.ELEMENT;
46+
this.logger.info(
47+
`Element with ${strategy} strategy for ${selector} selector found.`
48+
);
49+
}
50+
}
51+
52+
async _elementDisplayed(driver) {
53+
this.logger.info('Checking if element is displayed');
54+
await fetch(
55+
`${baseUrl}wd/hub/session/${driver.sessionId}/element/${this.element}/attribute/displayed`,
56+
{
57+
method: 'GET',
58+
headers: { 'Content-Type': 'application/json' },
59+
}
60+
);
4261
}
4362

4463
_getAutomationName(driver) {
@@ -50,7 +69,7 @@ export default class WaitCommandPlugin extends BasePlugin {
5069
if (automationName === 'XCuiTest') {
5170
return `${driver.wda.wdaBaseUrl}:${driver.wda.wdaLocalPort}/`;
5271
} else {
53-
return `http://${driver[automationName].host}:${driver[automationName].systemPort}/`;
72+
return `http://${driver.uiautomator2.host}:${driver.uiautomator2.systemPort}/`;
5473
}
5574
}
5675
}

0 commit comments

Comments
 (0)