Skip to content

Commit d751b8c

Browse files
fix: update android app determination (#604)
1 parent a34dd5d commit d751b8c

File tree

3 files changed

+48
-11
lines changed

3 files changed

+48
-11
lines changed

.changeset/late-hounds-rush.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@wdio/visual-service": patch
3+
---
4+
5+
fix android app determination

packages/visual-service/src/utils.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,22 @@ export function determineNativeContext(
270270

271271
// If not check if it's a mobile
272272
if (driver.isMobile) {
273-
return !!(driver.requestedCapabilities as WebdriverIO.Capabilities)?.browserName === false
274-
&& (
275-
(driver.requestedCapabilities as AppiumCapabilities)?.['appium:app'] !== undefined
276-
|| (driver.requestedCapabilities as { 'appium:bundleId'?: string })?.['appium:bundleId'] !== undefined
277-
|| (driver.requestedCapabilities as { 'appium:appPackage'?: string })?.['appium:appPackage'] !== undefined
278-
)
279-
&& (driver.requestedCapabilities as AppiumCapabilities)?.['appium:autoWebview'] !== true
273+
const isAppiumAppCapPresent = (capabilities: AppiumCapabilities) => {
274+
const appiumKeys = [
275+
'appium:app',
276+
'appium:bundleId',
277+
'appium:appPackage',
278+
'appium:appActivity',
279+
'appium:appWaitActivity',
280+
'appium:appWaitPackage',
281+
]
282+
return appiumKeys.some(key => capabilities[key as keyof AppiumCapabilities] !== undefined)
283+
}
284+
const capabilities = driver.requestedCapabilities as WebdriverIO.Capabilities & AppiumCapabilities
285+
const isBrowserNameFalse = !!capabilities.browserName === false
286+
const isAutoWebviewFalse = capabilities['appium:autoWebview'] !== true
287+
288+
return isBrowserNameFalse && isAppiumAppCapPresent(capabilities) && isAutoWebviewFalse
280289
}
281290

282291
// If not, it's webcontext

packages/visual-service/tests/utils.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,19 +434,42 @@ describe('utils', () => {
434434
expect(await determineNativeContext(driver)).toBeFalsy()
435435
})
436436

437+
// For iOS
438+
it('should return true for when appium:bundleId is provided and autoWebview is true', async() => {
439+
(driver.capabilities as WebdriverIO.Capabilities).browserName = '';
440+
(driver.requestedCapabilities as AppiumCapabilities)['appium:bundleId'] = 'string';
441+
(driver.requestedCapabilities as AppiumCapabilities)['appium:autoWebview'] = true
442+
443+
expect(await determineNativeContext(driver)).toBeFalsy()
444+
})
445+
446+
// For Android
437447
it('should return true for when appium:appPackage is provided', async() => {
438448
(driver.capabilities as WebdriverIO.Capabilities).browserName = '';
439449
(driver.requestedCapabilities as AppiumCapabilities)['appium:appPackage'] = 'string'
440450

441451
expect(await determineNativeContext(driver)).toBeTruthy()
442452
})
443453

444-
it('should return true for when appium:bundleId is provided and autoWebview is true', async() => {
454+
it('should return true for when appium:appActivity is provided', async() => {
445455
(driver.capabilities as WebdriverIO.Capabilities).browserName = '';
446-
(driver.requestedCapabilities as AppiumCapabilities)['appium:bundleId'] = 'string';
447-
(driver.requestedCapabilities as AppiumCapabilities)['appium:autoWebview'] = true
456+
(driver.requestedCapabilities as AppiumCapabilities)['appium:appActivity'] = 'appActivity'
448457

449-
expect(await determineNativeContext(driver)).toBeFalsy()
458+
expect(await determineNativeContext(driver)).toBeTruthy()
459+
})
460+
461+
it('should return true for when appium:appWaitActivity is provided', async() => {
462+
(driver.capabilities as WebdriverIO.Capabilities).browserName = '';
463+
(driver.requestedCapabilities as AppiumCapabilities)['appium:appWaitActivity'] = 'appWaitActivity'
464+
465+
expect(await determineNativeContext(driver)).toBeTruthy()
466+
})
467+
468+
it('should return true for when appium:appWaitPackage is provided', async() => {
469+
(driver.capabilities as WebdriverIO.Capabilities).browserName = '';
470+
(driver.requestedCapabilities as AppiumCapabilities)['appium:appWaitPackage'] = 'appWaitPackage'
471+
472+
expect(await determineNativeContext(driver)).toBeTruthy()
450473
})
451474
})
452475
})

0 commit comments

Comments
 (0)