A4Q Foundation Level Tester for Appium study materials
A4Q Foundation Level Tester for Appium study resources

Parallel Test Execution Causes Intermittent Failures

A4Q Foundation Level Tester for Appium · Put your knowledge to work in context.

All case studies

Parallel Test Execution Causes Intermittent Failures

You are running a suite of 50 Appium tests in parallel across 4 Android emulators using Appium's built-in parallel support. Each test is independent and uses a unique user account. The suite passes when run sequentially but fails intermittently (about 20% of tests) when run in parallel. Failures include StaleElementReferenceException, NoSuchElementException, and timeouts. The emulators are identical (Pixel 4, API 30) and run on a machine with 16GB RAM and 8 CPU cores. Each emulator is allocated 2GB RAM. Appium server logs show that some sessions receive commands meant for other sessions. You use a single Appium server instance with --session-override and default settings. The tests use the same app package and activity.

1. What is the most likely cause of the intermittent failures, and how would you fix the configuration?

Read the worked answer

The most likely cause is that a single Appium server instance with --session-override is allowing session overlap or command misrouting when multiple sessions are created concurrently. The --session-override flag allows new sessions to override existing ones, which can cause commands to be sent to the wrong session. Additionally, the default settings may not handle parallel sessions well. To fix, start multiple Appium server instances, each on a different port, and assign each emulator to a specific server and port. Use a unique udid for each emulator in the desired capabilities. Remove --session-override and instead use --allow-insecure if needed for parallel execution. Also, ensure each test uses a unique device and that the Appium server is configured with sufficient resources. Consider using a test runner that supports parallel execution with separate driver instances per thread.

2. What other factors could contribute to the flakiness, and how would you address them?

Read the worked answer

Other factors include resource contention: 4 emulators on 8 cores and 16GB RAM may cause CPU and memory starvation, leading to slow responses and timeouts. Each emulator using 2GB RAM leaves only 8GB for the host OS and Appium servers, which may be insufficient. Increase RAM allocation per emulator or reduce the number of parallel emulators. Also, ensure that the app's backend can handle concurrent requests from multiple users; use unique accounts and consider rate limiting. Network latency and emulator performance can cause stale elements; use explicit waits and retry mechanisms. Additionally, verify that the tests do not share any global state (e.g., files, databases) and that each test cleans up after itself. Use a robust test framework that handles parallel execution and isolates test data. Finally, monitor system resources during parallel runs to identify bottlenecks.