Improve Appium (UiAutomator2) driver creation reliability#710
Conversation
…on slow devices - Implemented a new function to force-stop the UiAutomator2 server processes to prevent transient session errors. - Enhanced driver creation reliability by adding timeout settings for various Appium capabilities. - Improved retry logic for Appium driver creation, including cleanup of the UiAutomator2 server state before retries.
🔎 ZeuZ PR ReviewOpen the full report in ZeuZ: Review findings and apply suggestions
Agent breakdown→ General ReviewStatus: ✅ Completed No clear correctness or maintainability regressions stood out in this diff; the retry logic and cleanup are narrowly scoped to Android and appear internally consistent. → Security ReviewStatus: ✅ Completed One critical command-injection issue was introduced in the new UiAutomator2 reset helper; the retry logic itself is otherwise fine. → Performance ReviewStatus: ✅ Completed No high-signal performance issues found in this PR diff. The changes are bounded retry/recovery logic for Appium driver creation, with no obvious new N+1, unbounded data growth, or hot-path algorithmic regression. → Testing ReviewStatus: ✅ Completed The PR changes the Appium driver startup flow in a way that clearly needs regression coverage, but I found no tests exercising the new retry/reset behavior or the new capability defaults.
|
Problem
Android test runs intermittently fail at session startup with:
SessionNotCreatedException: A new session could not be created.
java.lang.IllegalStateException: UiAutomation not connected
This is a UiAutomator2 race: when Appium creates a session it launches an on-device instrumentation server (io.appium.uiautomator2.server.test) that must hook into Android's UiAutomation accessibility service. On slow or just-booted emulators/devices — or when a prior session left the instrumentation in a bad state — that hook isn't ready in time and NEW_SESSION fails.
The existing retry loop masked the issue most of the time (the second attempt usually succeeds), but it could still fail outright due to three weaknesses:
Changes (Framework/Built_In_Automation/Mobile/CrossPlatform/Appium/BuiltInFunctions.py)