Appium · Test automation · Mobile · QA
Flaky Appium Tests: 8 Root Causes and Lasting Fixes
The eight most common reasons Appium tests pass one run and fail the next, from timing and selectors to device state and test data, and how to fix them for good.

A test that sometimes passes and sometimes fails does more harm than no test at all: the team stops trusting red results and real bugs slip through. Reviewing thousands of runs on a real-device testing platform, I found that flaky tests almost always come down to the same handful of causes.
1. Fixed sleeps
sleep(3000) is too short on a slow device and wasted time on a fast one. Always wait for a condition: an element being displayed, being enabled, a spinner disappearing.
await driver.$('~loading').waitForDisplayed({ reverse: true, timeout: 20000 });
await driver.$('~checkout').waitForEnabled();
2. Animations
If an element is visible but still sliding into place, the tap lands on the wrong coordinates. On test devices, turn off animation scales in Android developer options:
adb shell settings put global window_animation_scale 0
adb shell settings put global transition_animation_scale 0
adb shell settings put global animator_duration_scale 0
3. Brittle selectors
Indexed XPath, text-based selectors (which break when a translation changes) and dynamic ids are the most common culprits. Agree with developers to add accessibility ids to critical elements; it improves tests and accessibility alike.
4. Tests that depend on each other
"If the previous test logged in, this one adds to the cart" breaks as soon as order changes or tests run in parallel. Each test must set up its own preconditions. Doing repeated steps such as login through an API instead of the UI is faster and more stable.
5. Shared test data
If two parallel tests use the same test user, one empties the other's cart. Generate unique data per run (a timestamped email, for example) or lease records from a pool.
6. Device state
System-update dialogs, low-battery warnings, full storage, a locked screen, a keyboard left open. A short health check at session start and, where needed, a step that resets the device to a known state removes almost this entire class. I go into detail in the device farm section of the Appium real-device testing guide.
7. Network and backend
If a test waits on a slow service in staging, the result depends on the network's mood. Options:
- Mock non-critical external services in the test environment.
- Keep timeouts realistic but generous.
- Attach request logs to the report on failure, to tell a backend error from a test error.
8. Leaked sessions and resources
Tests that crash without calling deleteSession leave the device locked, and the next test gets "device busy". Close the session in afterEach no matter what, and give device locks an expiry.
How to catch flaky tests
- Track rerun statistics. Tests that fail and then pass on the same commit are flaky candidates.
- Look per device. If a test fails only on one device, the device is probably the problem.
- Collect evidence. Without screenshots, video,
logcatand the Appium server log, root-cause analysis is guesswork.
Are retries a fix?
Automatic retries turn the pipeline green but hide the problem. If you use them, keep them limited (at most one retry), report every retry, and put the test on a flaky list until the root cause is fixed.
Conclusion
Flaky tests are not bad luck; they have systematic causes. Condition-based waits, disabled animations, stable selectors, independent tests and a clean device state raise your stability rate dramatically.


