-
Notifications
You must be signed in to change notification settings - Fork 29
refactor: update device handling in Automate tools #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
10ace7e
ff9a638
da2cb9f
ada7046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,7 +9,10 @@ import { maybeCompressBase64 } from "../lib/utils.js"; | |||||||||||||
| import { remote } from "webdriverio"; | ||||||||||||||
| import { AppTestPlatform } from "./appautomate-utils/native-execution/types.js"; | ||||||||||||||
| import { setupAppAutomateHandler } from "./appautomate-utils/appium-sdk/handler.js"; | ||||||||||||||
| import { validateAppAutomateDevices } from "./sdk-utils/common/device-validator.js"; | ||||||||||||||
| import { | ||||||||||||||
| validateAppAutomateDevices, | ||||||||||||||
| convertMobileDevicesToTuples, | ||||||||||||||
| } from "./sdk-utils/common/device-validator.js"; | ||||||||||||||
|
|
||||||||||||||
| import { | ||||||||||||||
| SETUP_APP_AUTOMATE_DESCRIPTION, | ||||||||||||||
|
|
@@ -378,7 +381,15 @@ export default function addAppAutomationTools( | |||||||||||||
| undefined, | ||||||||||||||
| config, | ||||||||||||||
| ); | ||||||||||||||
| return await runAppTestsOnBrowserStack(args, config); | ||||||||||||||
| // Convert device objects to tuples for the handler | ||||||||||||||
| const devices: Array<Array<string>> = | ||||||||||||||
| (args.devices || []).length === 0 | ||||||||||||||
| ? [["android", "Samsung Galaxy S24", "latest"]] | ||||||||||||||
| : convertMobileDevicesToTuples(args.devices || []); | ||||||||||||||
|
||||||||||||||
| (args.devices || []).length === 0 | |
| ? [["android", "Samsung Galaxy S24", "latest"]] | |
| : convertMobileDevicesToTuples(args.devices || []); | |
| args.devices.length === 0 | |
| ? [["android", "Samsung Galaxy S24", "latest"]] | |
| : convertMobileDevicesToTuples(args.devices); |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -48,67 +48,80 @@ export const SetUpPercyParamsShape = { | |||
| ), | ||||
| }; | ||||
|
|
||||
| // Shared mobile device schema for App Automate (no browser field) | ||||
| export const MobileDeviceSchema = z.discriminatedUnion("platform", [ | ||||
| z.object({ | ||||
| platform: z.literal("android"), | ||||
| deviceName: z.string().describe("Device name, e.g. 'Samsung Galaxy S24', 'Google Pixel 8'"), | ||||
| osVersion: z.string().describe("Android version, e.g. '14', '16', 'latest'"), | ||||
| }), | ||||
| z.object({ | ||||
| platform: z.literal("ios"), | ||||
| deviceName: z.string().describe("Device name, e.g. 'iPhone 15', 'iPhone 14 Pro'"), | ||||
| osVersion: z.string().describe("iOS version, e.g. '17', '16', 'latest'"), | ||||
| }), | ||||
| ]); | ||||
|
|
||||
| const DeviceSchema = z.discriminatedUnion("platform", [ | ||||
| z.object({ | ||||
| platform: z.literal("windows"), | ||||
| osVersion: z.string().describe("Windows version, e.g. '10', '11'"), | ||||
| browser: z.string().describe("Browser name, e.g. 'chrome', 'firefox', 'edge'"), | ||||
| browserVersion: z | ||||
| .string() | ||||
| .optional() | ||||
| .describe("Browser version, e.g. '132', 'latest', 'oldest'"), | ||||
| }), | ||||
| z.object({ | ||||
| platform: z.literal("android"), | ||||
| deviceName: z | ||||
| .string() | ||||
| .describe("Device name, e.g. 'Samsung Galaxy S24', 'Google Pixel 8'"), | ||||
| osVersion: z.string().describe("Android version, e.g. '14', '16', 'latest'"), | ||||
| browser: z | ||||
| .string() | ||||
| .optional() | ||||
| .describe("Browser name, e.g. 'chrome', 'samsung browser'"), | ||||
| }), | ||||
| z.object({ | ||||
| platform: z.literal("ios"), | ||||
| deviceName: z | ||||
| .string() | ||||
| .describe("Device name, e.g. 'iPhone 15', 'iPhone 14 Pro'"), | ||||
| osVersion: z.string().describe("iOS version, e.g. '17', 'latest'"), | ||||
| browser: z | ||||
| .string() | ||||
| .optional() | ||||
| .describe("Browser name, typically 'safari'"), | ||||
| }), | ||||
| z.object({ | ||||
| platform: z.literal("macos"), | ||||
| osVersion: z.string().describe("macOS version name, e.g. 'Sequoia', 'Ventura'"), | ||||
| browser: z.string().describe("Browser name, e.g. 'safari', 'chrome'"), | ||||
| browserVersion: z | ||||
| .string() | ||||
| .optional() | ||||
| .describe("Browser version, e.g. 'latest'"), | ||||
| }), | ||||
| ]); | ||||
|
|
||||
| export const RunTestsOnBrowserStackParamsShape = { | ||||
| projectName: z | ||||
| .string() | ||||
| .describe("A single name for your project to organize all your tests."), | ||||
| detectedLanguage: z.nativeEnum(SDKSupportedLanguageEnum), | ||||
| detectedBrowserAutomationFramework: z.nativeEnum( | ||||
| SDKSupportedBrowserAutomationFrameworkEnum, | ||||
| ), | ||||
| detectedBrowserAutomationFramework: z.nativeEnum(SDKSupportedBrowserAutomationFrameworkEnum), | ||||
| detectedTestingFramework: z.nativeEnum(SDKSupportedTestingFrameworkEnum), | ||||
| devices: z | ||||
| .array( | ||||
| z.union([ | ||||
| // Windows: [windows, osVersion, browser, browserVersion] | ||||
| z.tuple([ | ||||
| z | ||||
| .nativeEnum(WindowsPlatformEnum) | ||||
| .describe("Platform identifier: 'windows'"), | ||||
| z.string().describe("Windows version, e.g. '10', '11'"), | ||||
| z.string().describe("Browser name, e.g. 'chrome', 'firefox', 'edge'"), | ||||
| z | ||||
| .string() | ||||
| .describe("Browser version, e.g. '132', 'latest', 'oldest'"), | ||||
| ]), | ||||
| // Android: [android, name, model, osVersion, browser] | ||||
| z.tuple([ | ||||
| z | ||||
| .literal(PlatformEnum.ANDROID) | ||||
| .describe("Platform identifier: 'android'"), | ||||
| z | ||||
| .string() | ||||
| .describe( | ||||
| "Device name, e.g. 'Samsung Galaxy S24', 'Google Pixel 8'", | ||||
| ), | ||||
| z.string().describe("Android version, e.g. '14', '16', 'latest'"), | ||||
| z.string().describe("Browser name, e.g. 'chrome', 'samsung browser'"), | ||||
| ]), | ||||
| // iOS: [ios, name, model, osVersion, browser] | ||||
| z.tuple([ | ||||
| z.literal(PlatformEnum.IOS).describe("Platform identifier: 'ios'"), | ||||
| z.string().describe("Device name, e.g. 'iPhone 12 Pro'"), | ||||
| z.string().describe("iOS version, e.g. '17', 'latest'"), | ||||
| z.string().describe("Browser name, typically 'safari'"), | ||||
| ]), | ||||
| // macOS: [mac|macos, name, model, browser, browserVersion] | ||||
| z.tuple([ | ||||
| z | ||||
| .nativeEnum(MacOSPlatformEnum) | ||||
| .describe("Platform identifier: 'mac' or 'macos'"), | ||||
| z.string().describe("macOS version name, e.g. 'Sequoia', 'Ventura'"), | ||||
| z.string().describe("Browser name, e.g. 'safari', 'chrome'"), | ||||
| z.string().describe("Browser version, e.g. 'latest'"), | ||||
| ]), | ||||
| ]), | ||||
| ) | ||||
| .array(DeviceSchema) | ||||
| .max(3) | ||||
| .default([]) | ||||
| .describe( | ||||
| "Preferred tuples of target devices.Add device only when user asks explicitly for it. Defaults to [] . Example: [['windows', '11', 'chrome', 'latest']]", | ||||
| "Device objects array. Use the object format directly - no transformation needed. Add only when user explicitly requests devices. Examples: [{ platform: 'windows', osVersion: '11', browser: 'chrome', browserVersion: 'latest' }] or [{ platform: 'android', deviceName: 'Samsung Galaxy S24', osVersion: '14', browser: 'chrome' }].", | ||||
| ), | ||||
| }; | ||||
|
|
||||
|
|
||||
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default device
[['android', 'Samsung Galaxy S24', 'latest']]is duplicated in bothappautomate.ts(line 387) andappium-sdk/handler.ts(line 54). Consider defining this as a constant (e.g.,DEFAULT_MOBILE_DEVICE) in a shared location to ensure consistency and ease maintenance.