Skip to content

Commit

Permalink
fix: correctly account for position and scroll values of webviews
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Mar 4, 2024
1 parent 7600888 commit d129737
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
53 changes: 34 additions & 19 deletions app/renderer/lib/appium-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,26 +315,41 @@ export default class AppiumClient {
}
}
} else if (this.driver.client.isIOS) {
// on iOS, find the top status bar and address bar and use its Y endpoint
const topBar = await this.fetchElement({
strategy: '-ios class chain',
selector: IOS_TOP_CONTROLS_SELECTOR,
});
if (topBar.el) {
const {y, height} = await topBar.el.getRect();
webviewTopOffset = y + height;
}
// in landscape mode, there is empty space on both sides (at default zoom level), so add offset for that too
if (windowSize.height < windowSize.width) {
try {
const deviceScreenInfo = await this.driver.executeScript('mobile:deviceScreenInfo', []);
webviewLeftOffset = deviceScreenInfo.statusBarSize.height;
} catch (e) {
const isSafari = this.driver.client?.capabilities?.browserName?.toLowerCase() === 'safari';
if (isSafari) {
// on iOS, if we're in Safari simply find the top status bar and address bar and use its Y endpoint
const topBar = await this.fetchElement({
strategy: '-ios class chain',
selector: IOS_TOP_CONTROLS_SELECTOR,
});
if (topBar.el) {
const {y, height} = await topBar.el.getRect();
webviewTopOffset = y + height;
}
// in landscape mode, there is empty space on both sides (at default zoom level), so add offset for that too
if (windowSize.height < windowSize.width) {
try {
const sessionDetails = await this.driver.getSession();
// in case driver does not support mobile:deviceScreenInfo
webviewLeftOffset = sessionDetails.statBarHeight;
} catch (ign) {}
const deviceScreenInfo = await this.driver.executeScript('mobile:deviceScreenInfo', []);
webviewLeftOffset = deviceScreenInfo.statusBarSize.height;
} catch (e) {
try {
const sessionDetails = await this.driver.getSession();
// in case driver does not support mobile:deviceScreenInfo
webviewLeftOffset = sessionDetails.statBarHeight;
} catch (ign) {}
}
}
} else {
// if we have a hybrid view, just find the first WebView element and use its position as
// the offset. Unfortunately this strategy doesn't work for Safari
const wv = await this.fetchElement({
strategy: 'class name',
selector: 'XCUIElementTypeWebView',
});
if (wv.el) {
const {x, y} = await wv.el.getRect();
webviewTopOffset = y;
webviewLeftOffset = x;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/renderer/lib/webview-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export function setHtmlElementAttributes(obj) {

el.setAttribute('data-appium-inspector-width', Math.round(rect.width * dpr));
el.setAttribute('data-appium-inspector-height', Math.round(rect.height * dpr));
el.setAttribute('data-appium-inspector-x', Math.round(webviewLeftOffset + rect.left * dpr));
el.setAttribute('data-appium-inspector-y', Math.round(webviewTopOffset + rect.top * dpr));
el.setAttribute('data-appium-inspector-x', Math.round(webviewLeftOffset + ((rect.left - window.scrollX) * dpr)));
el.setAttribute('data-appium-inspector-y', Math.round(webviewTopOffset + ((rect.top - window.scrollY) * dpr)));
});
}

Expand Down

0 comments on commit d129737

Please sign in to comment.