|
1 | 1 | import type { Capabilities } from '@wdio/types' |
2 | | -import type { AppiumCapabilities } from 'node_modules/@wdio/types/build/Capabilities.js' |
3 | 2 | import { getMobileScreenSize, getMobileViewPortPosition, IOS_OFFSETS, NOT_KNOWN } from '@wdio/image-comparison-core' |
4 | 3 | import type { Folders, InstanceData, TestContext } from '@wdio/image-comparison-core' |
5 | 4 | import type { |
@@ -151,6 +150,15 @@ export function getLtOptions(capabilities: WebdriverIO.Capabilities): any | unde |
151 | 150 | return key ? (capabilities as Record<string, any>)[key] : undefined |
152 | 151 | } |
153 | 152 |
|
| 153 | +/** |
| 154 | + * Get a requested Appium capability value by checking both the `appium:`-prefixed |
| 155 | + * top-level format and the nested `appium:options` format. |
| 156 | + */ |
| 157 | +function getRequestedAppiumCapability(requestedCapabilities: WebdriverIO.Capabilities, capName: string): unknown { |
| 158 | + return (requestedCapabilities as Record<string, unknown>)[`appium:${capName}`] |
| 159 | + ?? (requestedCapabilities as WebdriverIO.Capabilities)['appium:options']?.[capName as keyof typeof requestedCapabilities['appium:options']] |
| 160 | +} |
| 161 | + |
154 | 162 | /** |
155 | 163 | * Get the device name |
156 | 164 | */ |
@@ -179,7 +187,10 @@ function getDeviceName(browserInstance: WebdriverIO.Browser): string { |
179 | 187 | deviceName = ltOptions[capName as keyof typeof ltOptions] as string |
180 | 188 | } |
181 | 189 |
|
182 | | - const { 'appium:deviceName': requestedDeviceName } = requestedCapabilities as AppiumCapabilities |
| 190 | + const requestedDeviceName = ( |
| 191 | + getRequestedAppiumCapability(requestedCapabilities, 'deviceName') |
| 192 | + || getRequestedAppiumCapability(requestedCapabilities, 'avd') |
| 193 | + ) as string | undefined |
183 | 194 |
|
184 | 195 | return (deviceName !== NOT_KNOWN ? deviceName : requestedDeviceName || returnedDeviceName || NOT_KNOWN).toLowerCase() |
185 | 196 | } |
@@ -233,7 +244,7 @@ export async function getInstanceData({ |
233 | 244 | const ltOptions = getLtOptions(requestedCapabilities) |
234 | 245 | // @TODO: Figure this one out in the future when we know more about the Appium capabilities from LT |
235 | 246 | // 20241216: LT doesn't have the option to take a ChromeDriver screenshot, so if it's Android it's always native |
236 | | - const nativeWebScreenshot = isAndroid && ltOptions || !!((requestedCapabilities as Capabilities.AppiumAndroidCapabilities)['appium:nativeWebScreenshot']) |
| 247 | + const nativeWebScreenshot = isAndroid && ltOptions || !!getRequestedAppiumCapability(requestedCapabilities, 'nativeWebScreenshot') |
237 | 248 | const platformVersion = (rawPlatformVersion === undefined || rawPlatformVersion === '') ? NOT_KNOWN : rawPlatformVersion.toLowerCase() |
238 | 249 | const { |
239 | 250 | devicePixelRatio: mobileDevicePixelRatio, |
|
0 commit comments