1
- // Configuration utilities for BrowserStack App SDK
2
1
import {
3
2
APP_DEVICE_CONFIGS ,
4
3
AppSDKSupportedTestingFrameworkEnum ,
@@ -8,39 +7,33 @@ import {
8
7
import { ValidatedEnvironment } from "../../sdk-utils/common/device-validator.js" ;
9
8
10
9
export function generateAppBrowserStackYMLInstructions (
11
- platforms : string [ ] ,
10
+ config : {
11
+ validatedEnvironments ?: ValidatedEnvironment [ ] ;
12
+ platforms ?: string [ ] ;
13
+ testingFramework ?: string ;
14
+ projectName ?: string ;
15
+ } ,
12
16
username : string ,
13
17
accessKey : string ,
14
18
appPath : string = DEFAULT_APP_PATH ,
15
- testingFramework : string ,
16
19
) : string {
17
20
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
21
26
) {
22
27
return "" ;
23
28
}
24
29
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 ) ;
31
31
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" ;
42
36
43
- // Construct YAML content
44
37
const configContent = `\`\`\`yaml
45
38
userName: ${ username }
46
39
accessKey: ${ accessKey }
@@ -49,8 +42,8 @@ platforms:
49
42
${ platformConfigs }
50
43
parallelsPerPlatform: 1
51
44
browserstackLocal: true
52
- buildName: bstack-demo
53
- projectName: BrowserStack Sample
45
+ buildName: ${ buildName }
46
+ projectName: ${ projectName }
54
47
debug: true
55
48
networkLogs: true
56
49
percy: false
@@ -64,64 +57,46 @@ accessibility: false
64
57
- Set \`browserstackLocal: true\` if you need to test with local/staging servers
65
58
- Adjust \`parallelsPerPlatform\` based on your subscription limits` ;
66
59
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:" ;
71
62
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 ) ;
74
67
}
75
68
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 }
91
78
deviceName: "${ env . deviceName } "
92
79
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 "" ;
95
88
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
+ }
124
100
125
- ${ configContent } `,
126
- ) ;
101
+ return "" ;
127
102
}
0 commit comments