Skip to content

Commit 75caa0e

Browse files
committed
feat: adding more tests
- fix the LT capability support
1 parent 4798faa commit 75caa0e

File tree

60 files changed

+533
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+533
-183
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"test.saucelabs.sims.web": "SAUCE_ENV=sims wdio ./tests/configs/wdio.saucelabs.web.conf.ts",
4242
"test.lambdatest.desktop": "LT_ENV=desktop wdio ./tests/configs/wdio.lambdatest.web.conf.ts",
4343
"test.lambdatest.web": "wdio ./tests/configs/wdio.lambdatest.web.conf.ts",
44+
"test.lambdatest.emu.web": "LT_ENV=emu wdio ./tests/configs/wdio.lambdatest.web.conf.ts",
4445
"pnpm.install.workaround": "pnpm install --shamefully-hoist",
4546
"update.packages": "node ./scripts/update.packages.mjs",
4647
"prepare": "husky",
@@ -71,6 +72,7 @@
7172
"@wdio/appium-service": "^9.4.2",
7273
"@wdio/cli": "^9.4.2",
7374
"@wdio/globals": "^9.4.2",
75+
"wdio-lambdatest-service": "^3.0.3",
7476
"@wdio/local-runner": "^9.4.2",
7577
"@wdio/mocha-framework": "^9.4.2",
7678
"@wdio/sauce-service": "^9.4.2",

packages/visual-service/src/utils.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ async function getMobileInstanceData({
151151
}
152152
}
153153

154+
/**
155+
* Get the LambdaTest options, these can be case insensitive
156+
*/
157+
export function getLtOptions(capabilities: WebdriverIO.Capabilities): any | undefined {
158+
const key = Object.keys(capabilities).find(
159+
(k) => k.toLowerCase() === 'lt:options'
160+
)
161+
162+
return key ? (capabilities as Record<string, any>)[key] : undefined
163+
}
164+
154165
/**
155166
* Get the device name
156167
*/
@@ -167,11 +178,18 @@ function getDeviceName(currentBrowser: WebdriverIO.Browser): string {
167178
// - return the "requested" deviceName in the session capabilities
168179
// - don't use the `appium:deviceName` capability
169180
const isBrowserStack = 'bstack:options' in requestedCapabilities
170-
const bsOptions = (requestedCapabilities as WebdriverIO.Capabilities)['bstack:options']
181+
const bsOptions = requestedCapabilities['bstack:options']
171182
const capName = 'deviceName'
172183
if (isBrowserStack && bsOptions && capName in bsOptions){
173184
deviceName = bsOptions[capName as keyof typeof bsOptions] as string
174185
}
186+
// Same for LabdaTest
187+
const isLambdaTest = 'lt:options' in requestedCapabilities
188+
const ltOptions = getLtOptions(requestedCapabilities)
189+
if (isLambdaTest && ltOptions && capName in ltOptions){
190+
deviceName = ltOptions[capName as keyof typeof ltOptions] as string
191+
}
192+
175193
const { 'appium:deviceName': requestedDeviceName } = requestedCapabilities as AppiumCapabilities
176194

177195
return (deviceName !== NOT_KNOWN ? deviceName : requestedDeviceName || returnedDeviceName || NOT_KNOWN).toLowerCase()
@@ -217,7 +235,10 @@ export async function getInstanceData(currentBrowser: WebdriverIO.Browser): Prom
217235
? rawApp.replace(/\\/g, '/').split('/').pop().replace(/[^a-zA-Z0-9.]/g, '_')
218236
: NOT_KNOWN
219237
const deviceName = getDeviceName(currentBrowser)
220-
const nativeWebScreenshot = !!((requestedCapabilities as Capabilities.AppiumAndroidCapabilities)['appium:nativeWebScreenshot'])
238+
const ltOptions = getLtOptions(requestedCapabilities)
239+
// @TODO: Figure this one out in the future when we know more about the Appium capabilities from LT
240+
// 20241216: LT doesn't have the option to take a ChromeDriver screenshot, so if it's Android it's always native
241+
const nativeWebScreenshot = isAndroid && ltOptions || !!((requestedCapabilities as Capabilities.AppiumAndroidCapabilities)['appium:nativeWebScreenshot'])
221242
const platformVersion = (rawPlatformVersion === undefined || rawPlatformVersion === '') ? NOT_KNOWN : rawPlatformVersion.toLowerCase()
222243

223244
const { devicePixelRatio: mobileDevicePixelRatio, devicePlatformRect, deviceScreenSize, } = await getMobileInstanceData({ currentBrowser, isAndroid, isMobile })
@@ -269,6 +290,7 @@ export function determineNativeContext(
269290
}
270291

271292
// If not check if it's a mobile
293+
// @TODO: Also check for LT
272294
if (driver.isMobile) {
273295
const isAppiumAppCapPresent = (capabilities: AppiumCapabilities) => {
274296
const appiumKeys = [

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,45 @@ exports[`utils > getInstanceData > should return instance data when the browsers
268268
}
269269
`;
270270

271+
exports[`utils > getInstanceData > should return instance data when the lambdatest capabilities are provided 1`] = `
272+
{
273+
"appName": "not-known",
274+
"browserName": "chrome",
275+
"browserVersion": "75.123",
276+
"deviceName": "samsung galaxy s22 lt",
277+
"devicePixelRatio": 1,
278+
"devicePlatformRect": {
279+
"homeBar": {
280+
"height": 0,
281+
"width": 0,
282+
"x": 0,
283+
"y": 0,
284+
},
285+
"statusBar": {
286+
"height": 0,
287+
"width": 0,
288+
"x": 0,
289+
"y": 0,
290+
},
291+
},
292+
"deviceScreenSize": {
293+
"height": 200,
294+
"width": 100,
295+
},
296+
"isAndroid": true,
297+
"isIOS": false,
298+
"isMobile": true,
299+
"logName": "",
300+
"name": "",
301+
"nativeWebScreenshot": {
302+
"deviceName": "Samsung Galaxy S22 LT",
303+
"platformVersion": "11",
304+
},
305+
"platformName": "osx",
306+
"platformVersion": "11",
307+
}
308+
`;
309+
271310
exports[`utils > getInstanceData > should return instance data when the minimum of capabilities is provided 1`] = `
272311
{
273312
"appName": "not-known",

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,10 +338,33 @@ describe('utils', () => {
338338
})
339339
expect(await getInstanceData(driver)).toMatchSnapshot()
340340
})
341+
342+
it('should return instance data when the lambdatest capabilities are provided', async() => {
343+
const driver = createDriverMock({
344+
...DEFAULT_DESKTOP_BROWSER,
345+
requestedCapabilities:{
346+
...DEFAULT_DESKTOP_BROWSER.requestedCapabilities,
347+
'lt:options': {
348+
deviceName: 'Samsung Galaxy S22 LT',
349+
platformVersion: '11',
350+
},
351+
},
352+
capabilities: {
353+
...DEFAULT_DESKTOP_BROWSER.capabilities,
354+
// @ts-expect-error
355+
platformVersion: '11',
356+
},
357+
isAndroid: true,
358+
isMobile: true,
359+
getWindowSize: vi.fn().mockResolvedValueOnce({ width: 100, height: 200 }),
360+
})
361+
expect(await getInstanceData(driver)).toMatchSnapshot()
362+
})
341363
})
342364

343365
describe('getBrowserObject', () => {
344366
function createElementMock(parent: WebdriverIO.Browser): WebdriverIO.Element {
367+
// @ts-expect-error
345368
return {
346369
isMultiremote: false,
347370
sessionId: 'mock-session-id',

0 commit comments

Comments
 (0)