Skip to content

Commit

Permalink
fix: reduce getSession endpoint calls in hybrid mode (#1330)
Browse files Browse the repository at this point in the history
* fix: move getSession command to avoid error in newer chrome

* parse platform

* fix lint
  • Loading branch information
KazuCocoa authored Feb 8, 2024
1 parent 8a3325a commit 10b3eda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions app/renderer/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,10 @@ export function newSession(caps, attachSessId = null) {
throw new Error(i18n.t('attachSessionNotRunning', {attachSessId}));
}
}
serverOpts.isIOS = Boolean(attachedSessionCaps.platformName.match(/iOS/i));
serverOpts.isAndroid = Boolean(attachedSessionCaps.platformName.match(/Android/i));
// Chrome MJSONWP mode returns "platform" instead of "platformName"
const platformName = attachedSessionCaps.platformName || attachedSessionCaps.platform;
serverOpts.isIOS = Boolean(platformName.match(/iOS/i));
serverOpts.isAndroid = Boolean(platformName.match(/Android/i));
driver = await Web2Driver.attachToSession(attachSessId, serverOpts, attachedSessionCaps);
driver._isAttachedSession = true;
} else {
Expand Down
16 changes: 11 additions & 5 deletions app/renderer/lib/appium-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ export default class AppiumClient {
await this.driver.switchContext(NATIVE_APP);
}

const sessionDetails = await this.driver.getSession();
const isAndroid = this.driver.client.isAndroid;

// Get all available contexts (or the error, if one appears)
Expand Down Expand Up @@ -307,8 +306,12 @@ export default class AppiumClient {
const systemBars = await this.driver.executeScript('mobile:getSystemBars', []);
webviewTopOffset = systemBars.statusBar.height;
} catch (e) {
// in case driver does not support mobile:getSystemBars
webviewTopOffset = sessionDetails.viewportRect.top;
try {
// to minimize the endpoint call which gets error in newer chromedriver.
const sessionDetails = await this.driver.getSession();
// in case driver does not support mobile:getSystemBars
webviewTopOffset = sessionDetails.viewportRect.top;
} catch (ign) {}
}
}
} else if (this.driver.client.isIOS) {
Expand All @@ -327,8 +330,11 @@ export default class AppiumClient {
const deviceScreenInfo = await this.driver.executeScript('mobile:deviceScreenInfo', []);
webviewLeftOffset = deviceScreenInfo.statusBarSize.height;
} catch (e) {
// in case driver does not support mobile:deviceScreenInfo
webviewLeftOffset = sessionDetails.statBarHeight;
try {
const sessionDetails = await this.driver.getSession();
// in case driver does not support mobile:deviceScreenInfo
webviewLeftOffset = sessionDetails.statBarHeight;
} catch (ign) {}
}
}
}
Expand Down

0 comments on commit 10b3eda

Please sign in to comment.