Skip to content

Commit b90ecbe

Browse files
committed
Test popup
1 parent 3bc3f33 commit b90ecbe

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

integration-test/Integration.Tests.Android.ps1

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,133 @@ function script:Invoke-AndroidApp {
111111
throw "Failed to start activity: $startOutput"
112112
}
113113

114+
# Wait briefly for app to start
115+
Write-Host "Waiting for app to start..." -ForegroundColor Cyan
116+
Start-Sleep -Seconds 2
117+
118+
# Auto-dismiss any system dialogs/popups that might block the app
119+
# This handles popups like "OpenGL ES 3.2 is not supported" on emulators
120+
# Try multiple times over a period since popup might appear after a delay
121+
Write-Host "Monitoring for system popups (will check multiple times)..." -ForegroundColor Cyan
122+
123+
$popupCheckAttempts = 8 # Increased from 5 to cover longer period
124+
$popupDismissed = $false
125+
126+
for ($attempt = 1; $attempt -le $popupCheckAttempts; $attempt++) {
127+
try {
128+
Write-Host " Check attempt $attempt/$popupCheckAttempts..." -ForegroundColor Gray
129+
130+
# Try to detect if there's a visible popup/dialog
131+
# Use uiautomator to dump the UI hierarchy
132+
$uiDump = adb -s $deviceId shell "uiautomator dump /dev/tty" 2>&1 | Out-String
133+
134+
# Check if we actually got XML data (should start with <?xml)
135+
if (-not ($uiDump -match '<\?xml')) {
136+
if ($env:ANDROID_TEST_VERBOSE -eq "1") {
137+
Write-Host " uiautomator /dev/tty didn't work, using file method instead" -ForegroundColor DarkGray
138+
}
139+
# Try alternative method: dump to file then read it
140+
adb -s $deviceId shell "uiautomator dump /sdcard/ui_dump.xml" 2>&1 | Out-Null
141+
Start-Sleep -Milliseconds 200
142+
$uiDump = adb -s $deviceId shell "cat /sdcard/ui_dump.xml" 2>&1 | Out-String
143+
}
144+
145+
# Debug: Save UI dump to file for analysis
146+
if ($env:ANDROID_TEST_VERBOSE -eq "1") {
147+
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
148+
$dumpFile = Join-Path $PSScriptRoot "output/ui-dump-attempt-$attempt-$timestamp.xml"
149+
New-Item -ItemType Directory -Path (Split-Path $dumpFile) -Force | Out-Null
150+
$uiDump | Out-File -FilePath $dumpFile -Encoding UTF8
151+
Write-Host " UI dump saved to: $dumpFile" -ForegroundColor DarkGray
152+
Write-Host " UI dump length: $($uiDump.Length) chars, starts with: $($uiDump.Substring(0, [Math]::Min(50, $uiDump.Length)))" -ForegroundColor DarkGray
153+
}
154+
155+
# Look for the specific OpenGL error dialog we know appears
156+
# Check for: "Unable to run on this device!" title OR OpenGL version message OR the OK button
157+
# Note: The UI dump is one long line, so we need to be careful with regex
158+
$hasAlertTitle = $uiDump -match 'android:id/alertTitle'
159+
$hasButton1 = $uiDump -match 'android:id/button1'
160+
$hasOpenGLError = $uiDump -match 'Unable to run on this device'
161+
162+
$hasPopup = $hasAlertTitle -or $hasButton1 -or $hasOpenGLError
163+
164+
if ($env:ANDROID_TEST_VERBOSE -eq "1") {
165+
Write-Host " Detection results: alertTitle=$hasAlertTitle, button1=$hasButton1, openGLError=$hasOpenGLError" -ForegroundColor DarkGray
166+
}
167+
168+
if ($hasPopup) {
169+
Write-Host " System popup detected! Attempting to dismiss..." -ForegroundColor Yellow
170+
$popupDismissed = $true
171+
172+
# Try to extract OK button coordinates from UI dump
173+
$buttonCoords = $null
174+
if ($uiDump -match 'resource-id="android:id/button1".*?bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"') {
175+
# Calculate center of button from bounds [x1,y1][x2,y2]
176+
$x1 = [int]$matches[1]
177+
$y1 = [int]$matches[2]
178+
$x2 = [int]$matches[3]
179+
$y2 = [int]$matches[4]
180+
$buttonCoords = @{
181+
X = [int](($x1 + $x2) / 2)
182+
Y = [int](($y1 + $y2) / 2)
183+
}
184+
Write-Host " Found OK button at bounds [$x1,$y1][$x2,$y2], center: ($($buttonCoords.X),$($buttonCoords.Y))" -ForegroundColor Gray
185+
}
186+
187+
# Strategy 1: Tap the exact OK button location if we found it
188+
if ($buttonCoords) {
189+
Write-Host " Strategy 1: Tapping OK button at ($($buttonCoords.X),$($buttonCoords.Y))" -ForegroundColor Gray
190+
adb -s $deviceId shell input tap $buttonCoords.X $buttonCoords.Y 2>&1 | Out-Null
191+
Start-Sleep -Milliseconds 800
192+
} else {
193+
# Fallback: Tap typical OK button location (right side, lower portion)
194+
$screenSize = adb -s $deviceId shell wm size 2>&1 | Select-String "Physical size"
195+
$screenWidth = 1080 # Default
196+
$screenHeight = 1920 # Default
197+
198+
if ($screenSize -match "(\d+)x(\d+)") {
199+
$screenWidth = [int]$matches[1]
200+
$screenHeight = [int]$matches[2]
201+
}
202+
203+
$tapX = [int]($screenWidth * 0.85) # Right side
204+
$tapY = [int]($screenHeight * 0.72) # Lower portion
205+
Write-Host " Strategy 1: Tapping estimated OK location at ($tapX, $tapY)" -ForegroundColor Gray
206+
adb -s $deviceId shell input tap $tapX $tapY 2>&1 | Out-Null
207+
Start-Sleep -Milliseconds 800
208+
}
209+
210+
# Strategy 2: Try ENTER key (should activate default button)
211+
Write-Host " Strategy 2: Pressing ENTER key" -ForegroundColor Gray
212+
adb -s $deviceId shell input keyevent KEYCODE_ENTER 2>&1 | Out-Null
213+
Start-Sleep -Milliseconds 500
214+
215+
# Strategy 3: Press DPAD_CENTER (another way to click focused button)
216+
Write-Host " Strategy 3: Pressing DPAD_CENTER" -ForegroundColor Gray
217+
adb -s $deviceId shell input keyevent KEYCODE_DPAD_CENTER 2>&1 | Out-Null
218+
Start-Sleep -Milliseconds 500
219+
220+
Write-Host " Popup dismissal attempted" -ForegroundColor Green
221+
222+
# Wait a bit then check if popup is gone
223+
Start-Sleep -Seconds 1
224+
break
225+
}
226+
227+
# Wait before next check
228+
if ($attempt -lt $popupCheckAttempts) {
229+
Start-Sleep -Seconds 2
230+
}
231+
232+
} catch {
233+
Write-Host " Error during popup check (non-critical): $_" -ForegroundColor Yellow
234+
}
235+
}
236+
237+
if (-not $popupDismissed) {
238+
Write-Host "No system popup detected during monitoring period" -ForegroundColor Gray
239+
}
240+
114241
# Get process ID (with retries)
115242
Write-Debug "Waiting for app process..."
116243
Start-Sleep -Seconds $initialWaitSeconds

0 commit comments

Comments
 (0)