Skip to content

Commit d220f85

Browse files
committed
added testing script and workflow changes
1 parent 11efd74 commit d220f85

File tree

4 files changed

+560
-47
lines changed

4 files changed

+560
-47
lines changed

.github/actions/ios-test/action.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,22 +165,45 @@ runs:
165165
echo "🚀 Booting simulator with fresh state..."
166166
xcrun simctl boot "${{ env.DEVICE_UDID }}"
167167
168-
# Wait for simulator to be fully ready (not just "Booted")
168+
# Wait for simulator to be fully ready - use multiple readiness indicators
169169
echo "⏳ Waiting for simulator to be fully operational..."
170170
WAIT_COUNT=0
171171
MAX_WAIT=30
172+
BOOT_READY=false
173+
172174
while [ $WAIT_COUNT -lt $MAX_WAIT ]; do
173-
if xcrun simctl bootstatus "${{ env.DEVICE_UDID }}" 2>/dev/null | grep -q "Boot status is ready"; then
174-
echo "✅ Simulator boot status is ready"
175-
break
175+
# Check if simulator is booted (primary indicator)
176+
SIMULATOR_STATUS=$(xcrun simctl list devices | grep "${{ env.DEVICE_UDID }}" | head -1 || echo "Not found")
177+
if echo "$SIMULATOR_STATUS" | grep -q "(Booted)"; then
178+
echo "✅ Simulator is booted"
179+
180+
# Try boot status check with timeout - if it hangs, skip it
181+
echo "🔍 Checking boot status readiness (with timeout)..."
182+
if timeout 5 xcrun simctl bootstatus "${{ env.DEVICE_UDID }}" 2>/dev/null | grep -q "Boot status is ready" 2>/dev/null; then
183+
echo "✅ Simulator boot status is ready"
184+
BOOT_READY=true
185+
break
186+
elif [ $? -eq 124 ]; then
187+
echo "⚠️ Boot status check timed out (5s), but simulator is booted - proceeding"
188+
BOOT_READY=true
189+
break
190+
else
191+
echo "📱 Simulator booted but boot status not ready yet, waiting..."
192+
fi
193+
else
194+
echo "⏳ Simulator not yet booted, waiting... (${WAIT_COUNT}/${MAX_WAIT})"
176195
fi
177-
echo "Waiting for boot status... ($((WAIT_COUNT + 1))/$MAX_WAIT)"
196+
178197
sleep 2
179198
WAIT_COUNT=$((WAIT_COUNT + 1))
180199
done
181200
182-
if [ $WAIT_COUNT -eq $MAX_WAIT ]; then
183-
echo "⚠️ WARNING: Boot status check timed out, proceeding anyway"
201+
if [ "$BOOT_READY" = false ]; then
202+
if [ $WAIT_COUNT -eq $MAX_WAIT ]; then
203+
echo "⚠️ WARNING: Simulator readiness check timed out, but proceeding anyway"
204+
else
205+
echo "⚠️ WARNING: Could not verify simulator readiness, but proceeding anyway"
206+
fi
184207
fi
185208
186209
# Additional delay for UI services to stabilize
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
name: iOS Expo Build and Test
2+
3+
permissions:
4+
contents: read
5+
actions: read
6+
7+
# Complete workflow using deploy-ios.sh to build fresh with Expo and run tests
8+
# This workflow demonstrates building from source using Expo, deploying to simulator, and testing
9+
10+
on:
11+
# Manual trigger with customization options
12+
workflow_dispatch:
13+
inputs:
14+
client_id:
15+
description: 'Auth0 Client ID for test environment'
16+
required: true
17+
type: string
18+
build_mode:
19+
description: 'Build configuration'
20+
required: false
21+
type: choice
22+
options:
23+
- debug
24+
- release
25+
default: 'debug'
26+
ios_version:
27+
description: 'iOS platform version for simulator'
28+
required: false
29+
type: string
30+
default: '26.0'
31+
device_name:
32+
description: 'iOS simulator device name'
33+
required: false
34+
type: string
35+
default: 'iPhone 16'
36+
run_tests:
37+
description: 'Run Appium tests after deployment'
38+
required: false
39+
type: boolean
40+
default: true
41+
show_logs:
42+
description: 'Show app logs during deployment'
43+
required: false
44+
type: boolean
45+
default: false
46+
47+
jobs:
48+
expo-build-and-test-ios:
49+
name: Expo Build and Test iOS App
50+
runs-on: macos-latest
51+
timeout-minutes: 90
52+
53+
steps:
54+
- name: Checkout code
55+
uses: actions/checkout@v4
56+
57+
- name: Setup Node.js
58+
uses: actions/setup-node@v4
59+
with:
60+
node-version: '20'
61+
cache: 'npm'
62+
cache-dependency-path: 'app/package-lock.json'
63+
64+
- name: Install Node.js dependencies
65+
working-directory: ./app
66+
run: npm ci
67+
68+
# Deploy fresh app using the deploy-ios.sh script
69+
- name: Expo Build and Deploy iOS App
70+
id: expo-deploy-ios
71+
run: |
72+
echo "🚀 Starting iOS Expo build and deployment using deploy-ios.sh..."
73+
74+
# Set deployment parameters
75+
DEPLOY_ARGS=""
76+
DEPLOY_ARGS="$DEPLOY_ARGS --client-id '${{ inputs.client_id }}'"
77+
DEPLOY_ARGS="$DEPLOY_ARGS --simulator '${{ inputs.device_name || 'iPhone 16' }}'"
78+
79+
if [ "${{ inputs.build_mode }}" = "release" ]; then
80+
DEPLOY_ARGS="$DEPLOY_ARGS --release"
81+
fi
82+
83+
if [ "${{ inputs.show_logs }}" = "true" ]; then
84+
DEPLOY_ARGS="$DEPLOY_ARGS --logs"
85+
fi
86+
87+
# Run deployment with verbose output for CI
88+
eval "./scripts/deploy-ios.sh $DEPLOY_ARGS --verbose"
89+
90+
echo "✅ iOS app built and deployed successfully with Expo"
91+
92+
# Get the deployed simulator details for testing
93+
SIMULATOR_ID=$(xcrun simctl list devices | grep "${{ inputs.device_name || 'iPhone 16' }}" | grep "Booted" | head -1 | grep -E -o '\([A-F0-9\-]+\)' | tr -d '()')
94+
echo "device_udid=$SIMULATOR_ID" >> $GITHUB_OUTPUT
95+
echo "bundle_id=com.softwareone.marketplaceMobile" >> $GITHUB_OUTPUT
96+
97+
echo "📱 Deployed to simulator: ${{ inputs.device_name || 'iPhone 16' }} ($SIMULATOR_ID)"
98+
99+
# Wait for app to be fully ready
100+
- name: Wait for App Startup
101+
run: |
102+
echo "⏳ Waiting for app to fully initialize..."
103+
sleep 10
104+
105+
# Verify app is installed and running
106+
SIMULATOR_ID="${{ steps.expo-deploy-ios.outputs.device_udid }}"
107+
BUNDLE_ID="${{ steps.expo-deploy-ios.outputs.bundle_id }}"
108+
109+
echo "🔍 Verifying app installation..."
110+
xcrun simctl listapps "$SIMULATOR_ID" | grep -q "$BUNDLE_ID" && echo "✅ App is installed" || echo "❌ App not found"
111+
112+
echo "🔍 Checking app state..."
113+
xcrun simctl spawn "$SIMULATOR_ID" launchctl list | grep -q "$BUNDLE_ID" && echo "✅ App is running" || echo "⚠️ App may not be running"
114+
115+
# Run tests using our existing ios-test action (optional)
116+
- name: Run Appium Tests
117+
if: ${{ inputs.run_tests == true }}
118+
uses: ./.github/actions/ios-test
119+
with:
120+
device_uuid: ${{ steps.expo-deploy-ios.outputs.device_udid }}
121+
ios_version: ${{ inputs.ios_version || '26.0' }}
122+
device_name: ${{ inputs.device_name || 'iPhone 16' }}
123+
node_version: '20'
124+
appium_version: '3.1.1'
125+
app_bundle_id: ${{ steps.expo-deploy-ios.outputs.bundle_id }}
126+
appium_host: 'localhost'
127+
appium_port: '4723'
128+
129+
# Alternative: Run specific test suite manually
130+
- name: Run Custom Test Suite
131+
if: ${{ inputs.run_tests == true }}
132+
working-directory: ./app
133+
env:
134+
DEVICE_UDID: ${{ steps.expo-deploy-ios.outputs.device_udid }}
135+
DEVICE_NAME: ${{ inputs.device_name || 'iPhone 16' }}
136+
PLATFORM_VERSION: ${{ inputs.ios_version || '26.0' }}
137+
APP_BUNDLE_ID: ${{ steps.expo-deploy-ios.outputs.bundle_id }}
138+
APPIUM_HOST: 'localhost'
139+
APPIUM_PORT: '4723'
140+
run: |
141+
echo "🧪 Running custom test suite with deployed app..."
142+
143+
# Start Appium server
144+
echo "🚀 Starting Appium server..."
145+
npx appium --log-level warn > /tmp/appium.log 2>&1 &
146+
APPIUM_PID=$!
147+
echo "Appium PID: $APPIUM_PID"
148+
149+
# Wait for Appium to start
150+
for i in {1..30}; do
151+
if curl -s http://localhost:4723/status > /dev/null 2>&1; then
152+
echo "✅ Appium server is ready!"
153+
break
154+
fi
155+
if [ $i -eq 30 ]; then
156+
echo "❌ Appium failed to start"
157+
cat /tmp/appium.log
158+
exit 1
159+
fi
160+
sleep 1
161+
done
162+
163+
# Run WebDriverIO tests
164+
echo "🧪 Running WebDriverIO test suite..."
165+
npx wdio run wdio.conf.js --suite welcome
166+
167+
# Cleanup
168+
echo "🛑 Stopping Appium server..."
169+
kill $APPIUM_PID 2>/dev/null || true
170+
171+
# Collect logs and artifacts
172+
- name: Collect App Logs
173+
if: always()
174+
run: |
175+
echo "📋 Collecting app logs and system information..."
176+
177+
SIMULATOR_ID="${{ steps.expo-deploy-ios.outputs.device_udid }}"
178+
179+
echo "=== iOS Simulator Information ===" >> deployment_logs.txt
180+
xcrun simctl list devices | grep -A 5 -B 5 "$SIMULATOR_ID" >> deployment_logs.txt
181+
182+
echo -e "\n=== App Installation Status ===" >> deployment_logs.txt
183+
xcrun simctl listapps "$SIMULATOR_ID" | grep -A 3 -B 3 "com.softwareone" >> deployment_logs.txt || echo "No app info found" >> deployment_logs.txt
184+
185+
echo -e "\n=== Recent App Logs ===" >> deployment_logs.txt
186+
xcrun simctl spawn "$SIMULATOR_ID" log show --predicate 'subsystem contains "com.softwareone"' --last 5m >> deployment_logs.txt 2>&1 || echo "No recent logs found" >> deployment_logs.txt
187+
188+
- name: Upload Deployment Logs
189+
if: always()
190+
uses: actions/upload-artifact@v4
191+
with:
192+
name: ios-deployment-logs-${{ github.run_id }}
193+
path: |
194+
deployment_logs.txt
195+
/tmp/appium.log
196+
retention-days: 7
197+
198+
# Screenshots from failed tests (if any)
199+
- name: Upload Test Screenshots
200+
if: failure() && inputs.run_tests == true
201+
uses: actions/upload-artifact@v4
202+
with:
203+
name: test-screenshots-${{ github.run_id }}
204+
path: app/screenshots/
205+
retention-days: 7
206+
if-no-files-found: ignore
Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,60 @@ appium driver list --installed
3737

3838
### 2. iOS Simulator Setup and App Deployment
3939

40-
#### Method 1: Using Deploy Script (Recommended)
40+
#### Method 1: Using Local Test Script (Recommended)
4141

42-
The easiest way to build and deploy the app to a simulator is using the provided deployment script:
42+
The easiest way to build, deploy, and test the app is using the integrated local test script:
43+
44+
```bash
45+
# Navigate to project root
46+
cd /path/to/mpt-mobile-platform
47+
48+
# Run tests with existing app (fastest)
49+
./scripts/run-local-test.sh welcome
50+
51+
# Build fresh Release app and run tests (production-like testing)
52+
./scripts/run-local-test.sh --build --client-id YOUR_AUTH0_CLIENT_ID welcome
53+
54+
# Run with verbose output for debugging
55+
./scripts/run-local-test.sh --build --client-id YOUR_AUTH0_CLIENT_ID --verbose welcome
56+
57+
# Run specific test file
58+
./scripts/run-local-test.sh ./test/specs/welcome.e2e.js
59+
60+
# Get help and see all options
61+
./scripts/run-local-test.sh --help
62+
```
63+
64+
The `run-local-test.sh` script provides a complete testing solution:
65+
- **Builds** Release version of the app (optional with `--build`)
66+
- **Sets up** iOS simulator and installs the app
67+
- **Starts** Appium server automatically
68+
- **Runs** your specified test suite or spec file
69+
- **Cleans up** Appium processes when done
70+
71+
This is the **recommended approach** for local development as it handles the entire workflow automatically.
72+
73+
#### Method 2: Using Deploy Script Only
74+
75+
If you only want to build and deploy without running tests:
4376

4477
```bash
4578
# Make sure you're in the project root directory
4679
cd /path/to/mpt-mobile-platform
4780

4881
# Run the iOS deployment script
49-
./scripts/deploy-ios.sh
82+
./scripts/deploy-ios.sh --client-id YOUR_AUTH0_CLIENT_ID
5083

5184
# The script will:
5285
# 1. Build the iOS app for simulator
53-
# 2. Boot an available iOS simulator
86+
# 2. Boot an available iOS simulator
5487
# 3. Install the app on the simulator
5588
# 4. Launch the app
5689
```
5790

5891
The `deploy-ios.sh` script handles all the complexity of building, installing, and launching your app automatically. Once it completes successfully, your app will be ready for Appium testing.
5992

60-
#### Method 2: Manual Setup (Alternate)
93+
#### Method 3: Manual Setup (Advanced)
6194

6295
If you prefer manual control or need to troubleshoot, you can set up the simulator manually:
6396

@@ -84,7 +117,37 @@ If you prefer manual control or need to troubleshoot, you can set up the simulat
84117
xcrun simctl install booted path/to/your/app.app
85118
```
86119

87-
### 3. Start Appium Server
120+
### 3. Automated Testing with Local Script
121+
122+
The `run-local-test.sh` script provides the most streamlined testing experience:
123+
124+
```bash
125+
# Basic usage - run tests with existing app
126+
./scripts/run-local-test.sh welcome
127+
128+
# Full workflow - build Release app and test (recommended for production validation)
129+
./scripts/run-local-test.sh --build --client-id YOUR_AUTH0_CLIENT_ID welcome
130+
131+
# Available options:
132+
# --build, -b Build release version of the app before testing
133+
# --client-id, -c ID Set Auth0 client ID for build (required with --build)
134+
# --verbose, -v Enable verbose output for debugging
135+
# --help, -h Show help message
136+
```
137+
138+
**Script Features:**
139+
-**Automatic build** (optional): Builds Release configuration using Expo prebuild + xcodebuild
140+
-**Simulator management**: Boots simulator and installs app automatically
141+
-**Appium lifecycle**: Starts/stops Appium server as needed
142+
-**Flexible execution**: Run from project root or scripts directory
143+
-**Production parity**: Uses same build process as CI/CD pipeline
144+
-**Environment setup**: Handles Auth0 configuration for builds
145+
146+
### 4. Manual Appium Testing (Alternative)
147+
148+
If you need more control over the testing process:
149+
150+
#### Start Appium Server
88151

89152
```bash
90153
# Start Appium server with logging
@@ -96,7 +159,7 @@ appium --log-level info --log appium.log &
96159

97160
The server will start on `http://localhost:4723` by default.
98161

99-
### 4. Configure WebDriverIO
162+
#### WebDriverIO Configuration
100163

101164
The project includes a pre-configured `wdio.conf.js` file with iOS-specific settings. Key configuration:
102165

0 commit comments

Comments
 (0)