1- // Configuration utilities for BrowserStack App SDK
21import {
32 APP_DEVICE_CONFIGS ,
43 AppSDKSupportedTestingFrameworkEnum ,
@@ -8,39 +7,33 @@ import {
87import { ValidatedEnvironment } from "../../sdk-utils/common/device-validator.js" ;
98
109export function generateAppBrowserStackYMLInstructions (
11- platforms : string [ ] ,
10+ config : {
11+ validatedEnvironments ?: ValidatedEnvironment [ ] ;
12+ platforms ?: string [ ] ;
13+ testingFramework ?: string ;
14+ projectName ?: string ;
15+ } ,
1216 username : string ,
1317 accessKey : string ,
1418 appPath : string = DEFAULT_APP_PATH ,
15- testingFramework : string ,
1619) : string {
1720 if (
18- testingFramework === AppSDKSupportedTestingFrameworkEnum . nightwatch ||
19- testingFramework === AppSDKSupportedTestingFrameworkEnum . webdriverio ||
20- testingFramework === AppSDKSupportedTestingFrameworkEnum . cucumberRuby
21+ config . testingFramework ===
22+ AppSDKSupportedTestingFrameworkEnum . nightwatch ||
23+ config . testingFramework ===
24+ AppSDKSupportedTestingFrameworkEnum . webdriverio ||
25+ config . testingFramework === AppSDKSupportedTestingFrameworkEnum . cucumberRuby
2126 ) {
2227 return "" ;
2328 }
2429
25- // Generate platform and device configurations
26- const platformConfigs = platforms
27- . map ( ( platform ) => {
28- const devices =
29- APP_DEVICE_CONFIGS [ platform as keyof typeof APP_DEVICE_CONFIGS ] ;
30- if ( ! devices ) return "" ;
30+ const platformConfigs = generatePlatformConfigs ( config ) ;
3131
32- return devices
33- . map (
34- ( device ) => ` - platformName: ${ platform }
35- deviceName: ${ device . deviceName }
36- platformVersion: "${ device . platformVersion } "` ,
37- )
38- . join ( "\n" ) ;
39- } )
40- . filter ( Boolean )
41- . join ( "\n" ) ;
32+ const projectName = config . projectName || "BrowserStack Sample" ;
33+ const buildName = config . projectName
34+ ? `${ config . projectName } -AppAutomate-Build`
35+ : "bstack-demo" ;
4236
43- // Construct YAML content
4437 const configContent = `\`\`\`yaml
4538userName: ${ username }
4639accessKey: ${ accessKey }
@@ -49,8 +42,8 @@ platforms:
4942${ platformConfigs }
5043parallelsPerPlatform: 1
5144browserstackLocal: true
52- buildName: bstack-demo
53- projectName: BrowserStack Sample
45+ buildName: ${ buildName }
46+ projectName: ${ projectName }
5447debug: true
5548networkLogs: true
5649percy: false
@@ -64,64 +57,46 @@ accessibility: false
6457- Set \`browserstackLocal: true\` if you need to test with local/staging servers
6558- Adjust \`parallelsPerPlatform\` based on your subscription limits` ;
6659
67- // Return formatted step for instructions
68- return createStep (
69- "Update browserstack.yml file with App Automate configuration:" ,
70- `Create or update the browserstack.yml file in your project root with the following content:
60+ const stepTitle =
61+ "Update browserstack.yml file with App Automate configuration:" ;
7162
72- ${ configContent } `,
73- ) ;
63+ const stepDescription = `Create or update the browserstack.yml file in your project root with the following content:
64+ ${ configContent } ` ;
65+
66+ return createStep ( stepTitle , stepDescription ) ;
7467}
7568
76- /**
77- * Generate App Automate browserstack.yml from validated device configurations
78- */
79- export function generateAppAutomateYML (
80- validatedEnvironments : ValidatedEnvironment [ ] ,
81- username : string ,
82- accessKey : string ,
83- appPath : string = DEFAULT_APP_PATH ,
84- projectName : string ,
85- ) : string {
86- // Generate platform configurations from validated environments
87- const platformConfigs = validatedEnvironments
88- . filter ( ( env ) => env . platform === "android" || env . platform === "ios" )
89- . map ( ( env ) => {
90- return ` - platformName: ${ env . platform }
69+ function generatePlatformConfigs ( config : {
70+ validatedEnvironments ?: ValidatedEnvironment [ ] ;
71+ platforms ?: string [ ] ;
72+ } ) : string {
73+ if ( config . validatedEnvironments && config . validatedEnvironments . length > 0 ) {
74+ return config . validatedEnvironments
75+ . filter ( ( env ) => env . platform === "android" || env . platform === "ios" )
76+ . map ( ( env ) => {
77+ return ` - platformName: ${ env . platform }
9178 deviceName: "${ env . deviceName } "
9279 platformVersion: "${ env . osVersion } "` ;
93- } )
94- . join ( "\n" ) ;
80+ } )
81+ . join ( "\n" ) ;
82+ } else if ( config . platforms && config . platforms . length > 0 ) {
83+ return config . platforms
84+ . map ( ( platform ) => {
85+ const devices =
86+ APP_DEVICE_CONFIGS [ platform as keyof typeof APP_DEVICE_CONFIGS ] ;
87+ if ( ! devices ) return "" ;
9588
96- // Construct YAML content with validated data
97- const configContent = `\`\`\`yaml
98- userName: ${ username }
99- accessKey: ${ accessKey }
100- app: ${ appPath }
101- platforms:
102- ${ platformConfigs }
103- parallelsPerPlatform: 1
104- browserstackLocal: true
105- buildName: ${ projectName } -AppAutomate-Build
106- projectName: ${ projectName }
107- debug: true
108- networkLogs: true
109- percy: false
110- percyCaptureMode: auto
111- accessibility: false
112- \`\`\`
113-
114- **Important notes:**
115- - Replace \`app: ${ appPath } \` with the path to your actual app file (e.g., \`./SampleApp.apk\` for Android or \`./SampleApp.ipa\` for iOS)
116- - You can upload your app using BrowserStack's App Upload API or manually through the dashboard
117- - Set \`browserstackLocal: true\` if you need to test with local/staging servers
118- - Adjust \`parallelsPerPlatform\` based on your subscription limits` ;
119-
120- // Return formatted step for instructions
121- return createStep (
122- "Update browserstack.yml file with validated App Automate configuration:" ,
123- `Create or update the browserstack.yml file in your project root with your validated device configurations:
89+ return devices
90+ . map (
91+ ( device ) => ` - platformName: ${ platform }
92+ deviceName: ${ device . deviceName }
93+ platformVersion: "${ device . platformVersion } "` ,
94+ )
95+ . join ( "\n" ) ;
96+ } )
97+ . filter ( Boolean )
98+ . join ( "\n" ) ;
99+ }
124100
125- ${ configContent } `,
126- ) ;
101+ return "" ;
127102}
0 commit comments