-
Notifications
You must be signed in to change notification settings - Fork 1
314 lines (285 loc) · 11.4 KB
/
browserstack-sdk.yml
File metadata and controls
314 lines (285 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
name: BrowserStack SDK Tests
# ============================================================================
# WORKFLOW TRIGGERS
# ============================================================================
# This workflow is triggered by:
# 1. Push events to main/develop/appiumMobile branches
# 2. Pull requests to main/develop
# 3. Manual dispatch (workflow_dispatch) with custom platform/tag selections
on:
push:
branches:
- main
- develop
- appiumMobile
pull_request:
branches:
- main
- develop
# schedule:
# Runs daily at 3:00 AM UTC
# Use https://crontab.guru to adjust timing
# 0 3 * * * = Every day at 3:00 AM
# - cron: '0 3 * * *'
workflow_dispatch:
# Allows manual triggering from GitHub UI with custom inputs
# Usage: Actions tab → Run Workflow → Select platform and tags
inputs:
platform:
description: 'Platform to test'
required: true
default: 'android'
type: choice
options:
- android
- ios
- both
tags:
description: 'Cucumber tags filter'
required: false
default: 'platform-default'
type: choice
options:
- platform-default
- '@androidOnly'
- '@iosOnly'
- '@smoke'
- '@regression'
- 'custom'
env:
# Global environment variables for all jobs
JAVA_VERSION: '21' # Java version for compilation and test execution
MAVEN_OPTS: '-Xmx1024m' # Maven heap memory (for iOS stability)
jobs:
# ============================================================================
# Build & Validate
# ============================================================================
# Purpose: Compile and validate the project before running tests
# This job runs first and other jobs depend on it (needs: build)
build:
name: Build & Validate
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: maven
- name: Validate & Compile
run: mvn clean compile test-compile --no-transfer-progress
- name: Cache Maven packages
uses: actions/cache@v4
with:
# Caches ~/.m2/repository to speed up subsequent builds
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
# ============================================================================
# Android SDK Tests
# ============================================================================
# Purpose: Run Android tests on BrowserStack cloud
# Trigger Condition: Runs if platform is 'android' or 'both'
# Dependency: Waits for 'build' job to complete (needs: build)
test-android-sdk:
name: Android SDK Tests (BrowserStack)
runs-on: ubuntu-latest
needs: build
if: |
github.event.inputs.platform == 'android' ||
github.event.inputs.platform == 'both' ||
github.event.inputs.platform == '' ||
github.event_name != 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: maven
- name: Verify BrowserStack credentials
run: |
if [ -z "${{ secrets.BROWSERSTACK_USERNAME }}" ] || [ -z "${{ secrets.BROWSERSTACK_ACCESS_KEY }}" ]; then
echo "::error::BrowserStack credentials not configured. Add BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY to repository secrets."
exit 1
fi
- name: Determine Cucumber tags
id: tags
run: |
TAG_INPUT="${{ github.event.inputs.tags }}"
if [ "$TAG_INPUT" = "platform-default" ] || [ -z "$TAG_INPUT" ]; then
echo "filter=@androidOnly" >> $GITHUB_OUTPUT
elif [ "$TAG_INPUT" = "custom" ]; then
echo "filter=" >> $GITHUB_OUTPUT
else
echo "filter=$TAG_INPUT" >> $GITHUB_OUTPUT
fi
- name: Run Android SDK Tests
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
run: |
# Maven command structure:
# -DsuiteXmlFile: TestNG suite file
# -Dbrowserstack.config: YAML config file with app ID and device list
# -Dplatform=android: Sets platform for DriverFactory
# -Dcucumber.filter.tags: Applies tag filters (@androidOnly, @smoke, etc.)
mvn clean test \
-DsuiteXmlFile=testngSuite.xml \
-Dbrowserstack.config=browserstack-android-ci.yml \
-Dplatform=android \
-Dcucumber.filter.tags="${{ steps.tags.outputs.filter }}" \
--no-transfer-progress \
-q
- name: Upload Test Reports
# Uploads test artifacts (Extent Reports, SureFire reports, Cucumber HTML)
# Runs even if tests fail (if: always())
# Retention: 30 days
if: always()
uses: actions/upload-artifact@v4
with:
name: android-sdk-reports
path: |
target/extent-reports/
target/surefire-reports/
target/reports/cucumber-report/
retention-days: 30
- name: Upload Logs
if: failure()
uses: actions/upload-artifact@v4
with:
name: android-sdk-logs
path: target/logs/
retention-days: 7
- name: Publish Test Results
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: target/surefire-reports/TEST-*.xml
check_name: Android SDK Test Results
# ============================================================================
# iOS SDK Tests
# ============================================================================
# Purpose: Run iOS tests on BrowserStack cloud
# Trigger Condition: Runs if platform is 'ios' or 'both' OR automatic push triggers
# Dependency: Waits for 'build' job to complete (needs: build)
# Note: if condition includes automatic triggers for push events
test-ios-sdk:
name: iOS SDK Tests (BrowserStack)
runs-on: ubuntu-latest
needs: build
if: |
github.event.inputs.platform == 'ios' ||
github.event.inputs.platform == 'both' ||
github.event_name != 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Java ${{ env.JAVA_VERSION }}
uses: actions/setup-java@v4
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: 'temurin'
cache: maven
- name: Verify BrowserStack credentials
run: |
if [ -z "${{ secrets.BROWSERSTACK_USERNAME }}" ] || [ -z "${{ secrets.BROWSERSTACK_ACCESS_KEY }}" ]; then
echo "::error::BrowserStack credentials not configured. Add BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY to repository secrets."
exit 1
fi
- name: Determine Cucumber tags
id: tags
run: |
TAG_INPUT="${{ github.event.inputs.tags }}"
if [ "$TAG_INPUT" = "platform-default" ] || [ -z "$TAG_INPUT" ]; then
echo "filter=@iosOnly" >> $GITHUB_OUTPUT
elif [ "$TAG_INPUT" = "custom" ]; then
echo "filter=" >> $GITHUB_OUTPUT
else
echo "filter=$TAG_INPUT" >> $GITHUB_OUTPUT
fi
- name: Run iOS SDK Tests
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
run: |
# Same Maven structure as Android, but with iOS-specific config
# browserstack-ios-ci.yml contains: iOS devices, automationName: XCUITest, app ID
mvn clean test \
-DsuiteXmlFile=testngSuite.xml \
-Dbrowserstack.config=browserstack-ios-ci.yml \
-Dplatform=ios \
-Dcucumber.filter.tags="${{ steps.tags.outputs.filter }}" \
--no-transfer-progress \
-q
- name: Upload Test Reports
# Same as Android: uploads all test artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: ios-sdk-reports
path: |
target/extent-reports/
target/surefire-reports/
target/reports/cucumber-report/
retention-days: 30
- name: Upload Logs
# Uploads logs only if tests failed (if: failure())
if: failure()
uses: actions/upload-artifact@v4
with:
name: ios-sdk-logs
path: target/logs/
retention-days: 7
- name: Publish Test Results
# Parses TestNG XML reports and publishes results to GitHub
# Creates a check run in the workflow summary
if: always()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: target/surefire-reports/TEST-*.xml
check_name: iOS SDK Test Results
# ============================================================================
# Summary Report
# ============================================================================
# Purpose: Display final test summary in workflow UI
# Runs after all test jobs (both Android and iOS) complete
summary:
name: Test Summary
runs-on: ubuntu-latest
needs: [test-android-sdk, test-ios-sdk]
if: always() # Runs regardless of test results to always show summary
steps:
- name: Download all artifacts
# Collects all uploaded artifacts (reports, logs) from previous jobs
uses: actions/download-artifact@v4
with:
path: reports
- name: Generate Summary
# Creates a summary markdown output visible in workflow UI
# Shows test results, branch info, and links to artifacts
run: |
echo "## 📊 Test Execution Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Workflow:** ${{ github.workflow }}" >> $GITHUB_STEP_SUMMARY
echo "**Trigger:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Test Results" >> $GITHUB_STEP_SUMMARY
echo "- 🤖 Android SDK: ${{ needs.test-android-sdk.result }}" >> $GITHUB_STEP_SUMMARY
echo "- 🍎 iOS SDK: ${{ needs.test-ios-sdk.result }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "View detailed reports in artifacts section." >> $GITHUB_STEP_SUMMARY
- name: Check overall status
# Fails the workflow if any test job failed
run: |
if [ "${{ needs.test-android-sdk.result }}" == "failure" ] || [ "${{ needs.test-ios-sdk.result }}" == "failure" ]; then
echo "::error::One or more test jobs failed"
exit 1
fi