Skip to content

Commit

Permalink
fix: fix autostart + attachToSession use case (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps authored Aug 17, 2023
1 parent a6ad90a commit 16bd5a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
21 changes: 17 additions & 4 deletions app/renderer/actions/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,24 @@ export function newSession (caps, attachSessId = null) {
let driver = null;
try {
if (attachSessId) {
// When attaching to a session id, webdriver does not fully populate
// client information, so we should supplement by attaching session
// capabilities that we are attaching to.
const attachedSessionCaps = session.runningAppiumSessions.find((session) => session.id === attachSessId).capabilities;
// When attaching to a session id, webdriver does not fully populate client information, so
// we should supplement by attaching session capabilities that we are attaching to, if they
// exist in our cache of running appium sessions. Otherwise (in the case where we are
// autostarting and attaching to a new session, retrieve session details via a server call)
serverOpts.isMobile = true;
const attachedSession = session.runningAppiumSessions.find((session) => session.id === attachSessId);
let attachedSessionCaps = {};
if (attachedSession) {
attachedSessionCaps = attachedSession.capabilities;
} else {
const {protocol, hostname, port, path} = serverOpts;
try {
const detailsUrl = `${protocol}://${hostname}:${port}${path.replace(/\/$/, '')}/session/${attachSessId}`;
attachedSessionCaps = (await ky(detailsUrl).json()).value;
} catch (err) {
showError(new Error(i18n.t('attachSessionNotRunning', {attachSessId})));
}
}
serverOpts.isIOS = Boolean(attachedSessionCaps.platformName.match(/iOS/i));
serverOpts.isAndroid = Boolean(attachedSessionCaps.platformName.match(/Android/i));
driver = await Web2Driver.attachToSession(attachSessId, serverOpts, attachedSessionCaps);
Expand Down
3 changes: 2 additions & 1 deletion assets/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -339,5 +339,6 @@
"Advanced Settings": "Advanced Settings",
"Native App Mode": "Native App Mode",
"Web/Hybrid App Mode": "Web/Hybrid App Mode",
"autoAddPrefixes": "Automatically add necessary Appium vendor prefixes on start"
"autoAddPrefixes": "Automatically add necessary Appium vendor prefixes on start",
"attachSessionNotRunning": "Could not confirm that session {{attachSessId}} is running on the provided server. Please check details before trying to attach to the session again."
}

0 comments on commit 16bd5a7

Please sign in to comment.