Skip to content

Commit bebfcfb

Browse files
committed
test(appium): add Android support and device flag
1 parent 1ade972 commit bebfcfb

File tree

3 files changed

+39
-11
lines changed

3 files changed

+39
-11
lines changed

appium/scripts/.env.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ ONESIGNAL_API_KEY=your-api-key
88
# BUNDLE_ID=com.onesignal.example
99

1010
# ── Optional (defaults shown) ────────────────────────────────────────────────
11-
# DEVICE=iPhone 17 # iOS default; Android default: Google Pixel 8
1211
# OS_VERSION=26.2 # iOS default; Android default: 14
1312

1413
# iOS-only
15-
# IOS_SIMULATOR=iPhone 17 # Simulator name (defaults to DEVICE)
14+
# IOS_SIMULATOR=iPhone 17 # Simulator name (defaults to --device)
1615
# IOS_RUNTIME=iOS-26-2 # simctl runtime identifier
1716

1817
# Android-only
19-
# AVD_NAME=Pixel_8 # AVD to boot
18+
# AVD_NAME=Pixel_8 # Defaults to --device with spaces replaced by underscores
2019

2120
# APPIUM_PORT=4723

appium/scripts/run-local.sh

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ for arg in "$@"; do
3434
case "$arg" in
3535
--platform=*) PLATFORM="${arg#--platform=}" ;;
3636
--sdk=*) SDK_TYPE="${arg#--sdk=}" ;;
37+
--device=*) DEVICE="${arg#--device=}" ;;
3738
--skip) SKIP_BUILD=true; SKIP_DEVICE=true; SKIP_RESET=true ;;
3839
--skip-build) SKIP_BUILD=true ;;
3940
--skip-device) SKIP_DEVICE=true ;;
@@ -52,6 +53,7 @@ via flags or env vars.
5253
Options:
5354
--platform=P ios | android
5455
--sdk=S flutter | react-native
56+
--device=NAME Device/simulator/AVD name (default: iPhone 17 / Google Pixel 8)
5557
--skip Skip build, device launch, and app reset (rerun tests only)
5658
--skip-build Skip app build (reuse existing)
5759
--skip-device Skip simulator/emulator launch
@@ -64,9 +66,7 @@ Env vars (set in .env or export):
6466
BUNDLE_ID Bundle/package id (default: com.onesignal.example)
6567
ONESIGNAL_APP_ID OneSignal app ID (written to demo app .env)
6668
ONESIGNAL_API_KEY OneSignal REST API key (written to demo app .env)
67-
DEVICE Device name for wdio (default: iPhone 17 / Google Pixel 8)
6869
OS_VERSION Platform version (default: 26.2 / 14)
69-
AVD_NAME Android AVD to boot (default: Pixel_8)
7070
IOS_SIMULATOR iOS simulator name (default: iPhone 17)
7171
IOS_RUNTIME simctl runtime id (default: iOS-26-2)
7272
APPIUM_PORT Appium port (default: 4723)
@@ -114,7 +114,6 @@ case "$PLATFORM" in
114114
*) error "PLATFORM must be 'ios' or 'android', got '$PLATFORM'" ;;
115115
esac
116116

117-
[[ "$PLATFORM" == "android" ]] && error "Android is not supported yet. Only iOS is available for now."
118117
[[ "$SDK_TYPE" != "flutter" ]] && error "Only flutter is supported for now. Got '$SDK_TYPE'."
119118

120119
BUNDLE_ID="${BUNDLE_ID:-com.onesignal.example}"
@@ -123,7 +122,11 @@ if [[ "$SDK_TYPE" == "flutter" ]]; then
123122
FLUTTER_DIR="${FLUTTER_DIR:-$SDK_ROOT/OneSignal-Flutter-SDK}"
124123
[[ -d "$FLUTTER_DIR" ]] || error "Flutter SDK not found at $FLUTTER_DIR — set FLUTTER_DIR in .env"
125124
DEMO_DIR="$FLUTTER_DIR/examples/demo"
126-
APP_PATH="${APP_PATH:-$DEMO_DIR/build/ios/iphonesimulator/Runner.app}"
125+
if [[ "$PLATFORM" == "ios" ]]; then
126+
APP_PATH="${APP_PATH:-$DEMO_DIR/build/ios/iphonesimulator/Runner.app}"
127+
else
128+
APP_PATH="${APP_PATH:-$DEMO_DIR/build/app/outputs/flutter-apk/app-debug.apk}"
129+
fi
127130
fi
128131

129132
# ── Platform defaults ────────────────────────────────────────────────────────
@@ -135,7 +138,7 @@ if [[ "$PLATFORM" == "ios" ]]; then
135138
else
136139
DEVICE="${DEVICE:-Google Pixel 8}"
137140
OS_VERSION="${OS_VERSION:-14}"
138-
AVD_NAME="${AVD_NAME:-Pixel_8}"
141+
AVD_NAME="${AVD_NAME:-${DEVICE// /_}}"
139142
fi
140143

141144
# ── 1. Build app ─────────────────────────────────────────────────────────────
@@ -164,6 +167,28 @@ EOF
164167
info "App built: $APP_PATH"
165168
}
166169

170+
build_flutter_android() {
171+
if [[ -n "${ONESIGNAL_APP_ID:-}" && -n "${ONESIGNAL_API_KEY:-}" ]]; then
172+
info "Writing .env for demo app..."
173+
cat > "$DEMO_DIR/.env" <<EOF
174+
ONESIGNAL_APP_ID=$ONESIGNAL_APP_ID
175+
ONESIGNAL_API_KEY=$ONESIGNAL_API_KEY
176+
E2E_MODE=true
177+
EOF
178+
else
179+
warn "ONESIGNAL_APP_ID / ONESIGNAL_API_KEY not set — skipping demo .env"
180+
fi
181+
182+
info "Installing Flutter dependencies..."
183+
(cd "$FLUTTER_DIR" && flutter pub get)
184+
185+
info "Building debug APK (this may take a few minutes)..."
186+
(cd "$DEMO_DIR" && flutter build apk --debug)
187+
188+
[[ -f "$APP_PATH" ]] || error ".apk not found after build at $APP_PATH"
189+
info "App built: $APP_PATH"
190+
}
191+
167192
build_app() {
168193
if [[ "$SKIP_BUILD" == true ]]; then
169194
if [[ "$PLATFORM" == "ios" && ! -d "$APP_PATH" ]] || [[ "$PLATFORM" == "android" && ! -f "$APP_PATH" ]]; then
@@ -173,7 +198,11 @@ build_app() {
173198
return
174199
fi
175200

176-
build_flutter_ios
201+
if [[ "$PLATFORM" == "ios" ]]; then
202+
build_flutter_ios
203+
else
204+
build_flutter_android
205+
fi
177206
}
178207

179208
# ── 2. Start device ──────────────────────────────────────────────────────────

appium/wdio.android.conf.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export const config: WebdriverIO.Config = {
88
{
99
platformName: 'Android',
1010
'appium:app': isLocal ? process.env.APP_PATH : process.env.BROWSERSTACK_APP_URL,
11-
'appium:deviceName': process.env.DEVICE || 'Google Pixel 8',
12-
'appium:platformVersion': process.env.OS_VERSION || '14',
11+
'appium:deviceName': process.env.DEVICE || 'Samsung Galaxy S26',
12+
'appium:platformVersion': process.env.OS_VERSION || '16',
1313
'appium:automationName': 'UiAutomator2',
1414
...(process.env.BUNDLE_ID ? { 'appium:appPackage': process.env.BUNDLE_ID } : {}),
1515
'appium:autoGrantPermissions': true,

0 commit comments

Comments
 (0)