-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (115 loc) · 4.23 KB
/
test-browserstack.yml
File metadata and controls
131 lines (115 loc) · 4.23 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
# BrowserStack App Automate - E2E Tests
# Uses existing Appium/WebdriverIO tests from e2e/
# Setup: Add GitHub Secrets:
# - BROWSERSTACK_USERNAME
# - BROWSERSTACK_ACCESS_KEY
name: BrowserStack
on:
workflow_dispatch:
inputs:
apk_url:
description: 'APK URL (skips build). E.g. GitHub Release or raw file.'
required: false
type: string
jobs:
browserstack-e2e:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
# ==========================================
# VERIFY BROWSERSTACK (fail fast before build)
# ==========================================
- name: Verify BrowserStack credentials
run: |
HTTP=$(curl -s -o /dev/null -w "%{http_code}" -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
"https://api-cloud.browserstack.com/app-automate/recent_apps?limit=1")
if [ "$HTTP" != "200" ]; then
echo "BrowserStack verification failed (HTTP $HTTP). Check BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY."
exit 1
fi
echo "BrowserStack credentials verified (HTTP 200)"
# ==========================================
# BUILD OR DOWNLOAD APK
# ==========================================
- name: Download pre-built APK
if: inputs.apk_url != ''
run: |
mkdir -p build/app/outputs/flutter-apk
curl -fsSL -o build/app/outputs/flutter-apk/app-debug.apk "${{ inputs.apk_url }}"
- name: Setup Java
if: inputs.apk_url == ''
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Setup Flutter
if: inputs.apk_url == ''
uses: subosito/flutter-action@v2
with:
flutter-version: '3.35.4'
channel: 'stable'
cache: true
- name: Build APK
if: inputs.apk_url == ''
run: |
flutter pub get
flutter build apk --debug
- name: Ensure APK exists
run: |
mkdir -p build/app/outputs/flutter-apk
ls -la build/app/outputs/flutter-apk/app-debug.apk
# ==========================================
# UPLOAD TO BROWSERSTACK
# ==========================================
- name: Upload APK to BrowserStack
id: upload
run: |
RESPONSE=$(curl -s -u "${{ secrets.BROWSERSTACK_USERNAME }}:${{ secrets.BROWSERSTACK_ACCESS_KEY }}" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@build/app/outputs/flutter-apk/app-debug.apk")
APP_ID=$(echo "$RESPONSE" | jq -r '.app_url')
if [ -z "$APP_ID" ] || [ "$APP_ID" = "null" ]; then
echo "Upload failed: $RESPONSE"
exit 1
fi
echo "app_id=$APP_ID" >> $GITHUB_OUTPUT
echo "Uploaded: $APP_ID"
# ==========================================
# RUN E2E TESTS
# ==========================================
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install E2E dependencies
working-directory: e2e
run: npm install
- name: Run E2E tests on BrowserStack
working-directory: e2e
env:
BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }}
BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }}
BROWSERSTACK_APP_ID: ${{ steps.upload.outputs.app_id }}
PLATFORM: android
BSTACK_BUILD: "Build ${{ github.run_id }}"
run: npx mocha 'test/**/*.js' --timeout 180000 --reporter spec
# ==========================================
# ARTIFACTS
# ==========================================
- name: Upload Screenshots
if: always()
uses: actions/upload-artifact@v4
with:
name: browserstack-screenshots
path: e2e/screenshots/
retention-days: 30
- name: Upload Reports
if: always()
uses: actions/upload-artifact@v4
with:
name: browserstack-reports
path: |
e2e/reports/
e2e/mochawesome-report/
retention-days: 30