Skip to content

Commit 744cd02

Browse files
committed
test(appium): fix login logic for BrowserStack
1 parent dd43d6d commit 744cd02

2 files changed

Lines changed: 15 additions & 10 deletions

File tree

appium/tests/helpers/app.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,22 @@ export async function waitForAppReady(opts: { skipLogin?: boolean } = {}) {
179179

180180
if (skipLogin) return;
181181

182-
// want to login user so we can't clean up/delete user data for the next rerun
182+
// Want to login the user so we can clean up/delete its data on the next rerun.
183+
// The sharedStore cache is a local-only optimization: locally we reuse the same
184+
// emulator/simulator across specs, so once we've logged in we can skip the
185+
// text-check on subsequent specs. On BrowserStack each parallel session lands
186+
// on a fresh device, so the flag would lie about another session's state.
183187
const testUserId = getTestExternalId();
184-
const loggedIn = await browser.sharedStore.get('loggedIn');
185-
if (!loggedIn) {
186-
const userIdEl = await scrollToEl('user_external_id_value', { direction: 'up' });
187-
const sessionUserId = await userIdEl.getText();
188-
if (sessionUserId !== testUserId) {
189-
await loginUser(testUserId);
190-
}
191-
await browser.sharedStore.set('loggedIn', true);
188+
const isLocal = !process.env.BROWSERSTACK_USERNAME;
189+
190+
if (isLocal && (await browser.sharedStore.get('loggedIn'))) return;
191+
192+
const userIdEl = await scrollToEl('user_external_id_value', { direction: 'up' });
193+
const sessionUserId = await userIdEl.getText();
194+
if (sessionUserId !== testUserId) {
195+
await loginUser(testUserId);
192196
}
197+
if (isLocal) await browser.sharedStore.set('loggedIn', true);
193198
}
194199

195200
/**

appium/wdio.shared.conf.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const bstackOptions = {
2727
export const sharedConfig: WebdriverIO.Config = {
2828
...(isLocal ? localConnection : browserstackConnection),
2929

30-
maxInstances: 1,
30+
maxInstances: isLocal ? 1 : undefined,
3131
logLevel: 'warn',
3232

3333
specs: ['./tests/specs/**/*.spec.ts'],

0 commit comments

Comments
 (0)