Making Your Appium Tests Fast and Reliable, Part 3: Waiting for App States

April 10, 2026 · 11 min read · Tool Comparison

HeadSpin Platform
Automated & amp; manual examination made easy through data science insights.
Differentiating capabilities:
  • Extensive end-to-end automation of QA procedure
  • Comparative analysis of app execution against peers
  • Continuous monitoring of app execution using synthetic data for higher availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Affordable Real Device Testing for Emerging Teams
cloudtest go
Low-cost Real Device Testing for Digital Enterprises
cloudtest go
The Ultimate Solution for a Powerful Blend of Functional & amp; Performance Testing!
cyol
TEM
New
Centralized mobile test execution in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based testing

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

retail

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎

Making Your Appium Tests Fast and Reliable, Part 3: Waiting for App StatesMaking Your Appium Tests Fast and Reliable, Part 3: Waiting for App States

Making Your Appium Tests Fast and Reliable, Part 3: Waiting for App States

Published on
June 13, 2018
Updated on
Published on
June 5, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps
This article is the tertiary in a multi-part series on test speed and reliableness, inspired by a webinar I gave recently on the like subject (you canwatch the webinar hither). You might too require to check out and.

Using bad locator strategies is one cause of elements in your app not being found, and contributing to flakiness and unreliability. But still when you & # x27; re using the correct locator strategy and are undertake to find the like component every clip you appear, that doesn & # x27; t mean the element will be there rightwhenyou look! What happens when you try to happen an element which just isn & # x27; t there? This is a signally common issue, and it & # x27; s part of a more general phenomenon in functional trial: race weather due to poor assumptions about app state.

Check out:

Race Conditions

A race condition is when two processes or procedures are operating simultaneously, and either one could finish before the other. This is a problem in scripts because our code usually handles solely one scenario. So, in the substitute world where the unintuitive subprogram finishes first, our trial will fail.

To use our exemplar of chance ingredient: our code usually implicitly assumes that the element will be present before we try to find it. In reality, the petition to find an element and the app & # x27; s own process of working to display the element are in a race. As human users of the app, we cognize how to gracefully lose the race: we only await! If we want to tap a button and it & # x27; s not yet on the screen, we wait for it to show up (for a few seconds, anyways, then we get bored and unfastened Twitter instead).

Also tab:

Appium is less refined and does exactly what the node tells it to do, even if that means trying to find an component before it has been properly render on the screen. This is just one example of many potential examples in the family of tryout code assuming the app is in a certain province but being proven wrong. It can be a specially vexing problem because it might only show up infrequently, or only in CI environments. When we develop test code locally, we can often be tricked into do all kinds of assumptions about how race will adjudicate. Just because the app constantly wins a race (like we expect) when testing locally does not entail the app will behave the same in early environments.

Read:

Waiting for App States

The solvent is to teach our test code to gain a bit of the gracility of the human loser, and not blow up with exceptions just because the state wasn & # x27; t what it expected. There are three basic agency to wait in your Appium scripts.

Static Waits

Waiting & quot; statically & quot; simply entail use a lot of good oldThread.sleepall over the place. This is the brute force solution to a race condition. Is your test script trying to find an element before it is present? Force your test to slow down by adding a static sleep! Taking the login test, which is very conversant to our readers, this is what it would seem like habituate unchanging waits:

Pro tip: Tools like SUSA can handle this autonomously — upload your app and get results without writing a single test script.

@ Test world void testLogin_StaticWait () throws InterruptedException {Thread.sleep (3000); driver.findElement (loginScreen) .click (); Thread.sleep (3000); driver.findElement (username) .sendKeys (AUTH_USER); driver.findElement (password) .sendKeys (AUTH_PASS); driver.findElement (loginBtn) .click (); Thread.sleep (3000); driver.findElement (getLoggedInBy (AUTH_USER));}

I chose 3 seconds as my static wait amount. Why did I take that value? I & # x27; m not sure. It worked for me locally and clear my race condition job. Good enough, flop? Not exactly. There are some major problems with this approach:

  • My trial is now much longer than it needs to be (up to 9 seconds longer!), wasting my clip and my habitus & # x27; s time and therefore my squad & # x27; s clip and my company & # x27; s time. And time is money, friend! Oops.
  • I have staved off the chaos of a race stipulation ... for now. Who & # x27; s to say I won & # x27; t wind up in some former scenario where 3 seconds won & # x27; t be enough? What if one of the elements demo up based on a net asking, and every so often the network is just a bit slower? My only recourse would be to keep increase the stable wait, thereby get the problem above even worse. And meanwhile I however can & # x27; t kip at nighttime.
  • Unless I & # x27; m diligent at experiment and commenting, no one will know why I picked the precise values that I did. Was it random or was there a understanding?

So, what else can we do?

Also read:

Implicit Waits

Because the designers of Selenium were well mindful of the element finding race conditions, a long time ago they added the ability in the Selenium (and we copied it with the Appium) waiter for the client to set an & quot; implicit wait timeout & quot;. This timeout is remembered by the host and used in any instance of element determination. If an element can & # x27; t be found instantly, the waiter will keep examine to find it up to the specified timeout. The like test implemented with implicit waits would look like:

@ Test public void testLogin_ImplicitWait () {driver.manage () .timeouts () .implicitlyWait (10, TimeUnit.SECONDS); driver.findElement (loginScreen) .click (); driver.findElement (username) .sendKeys (AUTH_USER); driver.findElement (countersign) .sendKeys (AUTH_PASS); driver.findElement (loginBtn) .click (); driver.findElement (getLoggedInBy (AUTH_USER));}

Wow! That codification is a lot nicer, for one. We & # x27; ve besides completely solved the problem about the ever-increasing waste of time we ran into with electrostatic waits. Because the server-side element-finding retry is on a pretty taut loop, we & # x27; re guaranteed to detect the element within (say) a second of when it really shew up, intend we waste really small time while simultaneously make our tryout lots more robust.

There & # x27; s however a trouble or two with this attack, nevertheless:

  • Using unquestioning wait, we tend to set one timeout and forget about it. Inevitably, this timeout turn passably high because it has to be high plenty to account for the slowest factor we could validly wait for. This means that for other elements, which we know would ne'er direct as long to show up, we withal end up wasting clip waiting for them. In former words, we however want our find element command to fail relatively quickly in the instance where an element truly ne'er create an appearance. We don & # x27; t want to wait for a whole minute to decide when a few sec would have done.
  • We & # x27; ve been focusing on look for component, which is what implicit waits are plan around. But an element & # x27; s presence is just one example of an app state that we might want to wait for. What about an element & # x27; s text, or visibleness? Implicit wait won & # x27; t help us thither.

Thankfully, there & # x27; s an even more general solution that gets us past these (avowedly more minor) issues as well.

Explicit Waits

Explicit waits are just that: they make explicit what you are wait for and how long it will take. At the cost of a little more verbosity, we get much more fine-grained control, and are able to teach our exam playscript how to wait for just the right condition in our app before moving on. For model:

@ Test public nothingness testLogin_ExplicitWait () {WebDriverWait wait = new WebDriverWait (driver, 10); wait.until (ExpectedConditions.presenceOfElementLocated (loginScreen)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (username)) .sendKeys (AUTH_USER); wait.until (ExpectedConditions.presenceOfElementLocated (watchword)) .sendKeys (AUTH_PASS); wait.until (ExpectedConditions.presenceOfElementLocated (loginBtn)) .click (); wait.until (ExpectedConditions.presenceOfElementLocated (getLoggedInBy (AUTH_USER)));}

Here we use the WebDriverWait constructor to initialize a wait object with a certain timeout. We can reuse this object anytime we require the same timeout. We can configuredifferentwait objects with different timeouts and use them for different sort of waiting or elements. Then, we use the until method on the wait object in conjunction with something called an & quot; expected condition & quot;.

An expected condition is just a especial method which returns an anonymous inner class whose apply method will be call sporadically until it returns something. The ExpectedConditions class has a number of useful, pre-made condition methods. What & # x27; s great about explicit waits, though, is that we & # x27; re not limited to what arrive in the box. We can make our own!

Custom Explicit Waits

If the app state we want to wait for is particularly complex, we can always do our own expected condition. For example, let & # x27; s say that the detent () command is awful unreliable, and often it fails, still when our element is found. So, what we want is to maintain retrying both the findandclick actions until theybothsucceed one after the other. We could make a custom wait condition, like so:

private ExpectedConditionelementFoundAndClicked (By locator) {return new ExpectedCondition() {@ Override public Boolean apply (WebDriver driver) {WebElement el = driver.findElement (locator); el.click (); return true;}};}

We simply regress a newExpectedConditionand override theapply method with our special logic. Then we can use this in our examination codification, for example as in this revise of the previous test:

@ Test populace void testLogin_CustomWait () {WebDriverWait wait = new WebDriverWait (driver, 10); wait.until (elementFoundAndClicked (loginScreen)); wait.until (ExpectedConditions.presenceOfElementLocated (username)) .sendKeys (AUTH_USER); wait.until (ExpectedConditions.presenceOfElementLocated (countersign)) .sendKeys (AUTH_PASS); wait.until (elementFoundAndClicked (loginBtn)); wait.until (ExpectedConditions.presenceOfElementLocated (getLoggedInBy (AUTH_USER)));}

Granted, this is a bit of a useless model, but it demonstrates how easy it is to create utilitarian and reusable waits that your whole team can use. And this completes our tour of scheme for expect for app states with Appium. Don & # x27; t forget to direct a look at thefull codefor the examples shown hither, including all the setup and teardown boilerplate! Interested in the future episode in this series on speed and reliability? Head on over to.

Author & # x27; s Profile

Jonathan Lipps

LinkedIn
Author & # x27; s Profile

Piali Mazumdar

Lead, Content Marketing, HeadSpin Inc.

Piali is a dynamic and results-driven Content Marketing Specialist with 8+ years of experience in craft prosecute narrative and market collateral across diverse industries. She excels in collaborating with cross-functional teams to acquire innovative content scheme and deliver compelling, authentic, and impactful substance that resonate with target audiences and enhances brand authenticity.

LinkedIn

Making Your Appium Tests Fast and Reliable, Part 3: Waiting for App States

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for advanced users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence virtual guide for innovative users (Part 4)

Coming Soon

Discover how HeadSpin can empower your occupation with superior examine capabilities

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, profit a competitive edge
faster development cycles
Boost developer/QA productivity with quicker development cycles
automated buil-over-build regression testing
Automate build-over-build fixation testing for consistent upshot
gain better visibility into functional & performance issues
Gain best visibility into functional and performance subject
reduce mean time
Reduce mean time to identify/resolve during trial, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and content quality of experience (QoE) effortlessly
The trusted choice for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can empower your occupation with superior examine potentiality

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a private-enterprise edge
faster development cycles
Boost developer/QA productiveness with faster development round
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent results
gain better visibility into functional & performance issues
Gain better visibility into functional and performance issues
reduce mean time
Reduce mean clip to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate sound, video, and content quality of experience (QoE) effortlessly
The trusted choice for global enterprises
Close

Discover how HeadSpin can empower your business with superior testing capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productiveness with faster ontogenesis cycles
automated buil-over-build regression testing
Automate build-over-build regression essay for consistent results
gain better visibility into functional & performance issues
Gain better visibility into functional and performance matter
reduce mean time
Reduce mean time to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate audio, video, and contented quality of experience (QoE) effortlessly
The trusted pick for globose enterprises
Close

Connet Now

Wipro LogoVMLYR Logo
Close
Book a Meeting
Products
footer down arrow
Solutions
footer down arrow
Industries
footer down arrow
Features
footer down arrow
Support
footer down arrow
Resource Center
footer down arrow
Why Choose HeadSpin?
footer down arrow
Copyright © 2026 HeadSpin, Inc. All Rights Reserved.

Automate This With SUSA

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts needed.

Try SUSA Free

Test Your App Autonomously

Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.

Try SUSA Free