Validating Android Toast Messages

January 27, 2026 · 8 min read · Mobile Testing

HeadSpin Platform
Automated & amp; manual examination made easy through data skill insights.
Differentiating capabilities:
  • Extensive end-to-end automation of QA process
  • Relative analysis of app performance against peers
  • Continuous monitoring of app execution using man-made data for higher availability of apps
  • Easy-to-use developer friendly program
cloudtest go
Affordable Existent Device Testing for Emerging Teams
cloudtest go
Low-priced 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 performance in cloud
cyol
Enhance Your Accessibility Testing With HeadSpin
cyol
Automate camera-based testing

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

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

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

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

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

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

retail

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

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

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

Validating Android Toast MessagesValidating Android Toast Messages

Validating Android Toast Messages

Published on
April 10, 2019
Updated on
Published on
April 20, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

If you & # x27; ve used Android apps for any length of time, you & # x27; ve no uncertainty noticed these little notifications that pop up and pass forth with clip:

Toast App Android

These are calledtoast message, and are an important tool for Android app designers, because they don & # x27; t steal focus from the current activity. Your app might complete a ground task while the user is playing a game, and with toast you are able to communicate this information without occupy the user away from their present circumstance.

SUSA automates exploratory testing with persona-driven behavior, catching bugs that scripted automation misses.

Check out:

Of line, toast messages can prove a challenge for automation, not only because of their short-lived nature. From the position of the Android Accessibility stratum, goner messages aren & # x27; t visible! If you try to get the XML source from an Appium session while a toast is present on screen, you won & # x27; t observe its textbook anyplace. Luckily, with the coming of theEspresso driver, we feature the power to match textbook against on-screen toasts! Let & # x27; s see how it all works.

Also assay:

First, we need a way to actually create toast content we can use for testing. I could add some behavior in my app that produces toasts, like a real app would, but instead I & # x27; m proceed to rely on another cool feature of the Espresso driver we & # x27; ve covered in the past --. Since I & # x27; ve already got the plumbing hooked up in The App, I can exactly indite myself a handy little benefactor method that will display toasts for me from my exam code:

individual void raiseToast (String textbook) {ImmutableMapscriptArgs = ImmutableMap.of (`` mark '', `` application '', `` method '', Arrays.asList (ImmutableMap.of (`` name '', `` raiseToast '', `` args '', Arrays.asList (ImmutableMap.of (`` value '', text, `` case '', `` String ''))))); driver.executeScript (`` mobile: backdoor '', scriptArgs);}

(Of line, in a real testing scenario, the toasts would be generated as a result of some app behavior). Once I & # x27; ve got toasts showing up, I take a way to see what they say for verification. Unfortunately, we don & # x27; t have a method for getting the schoolbook from a toast message. What we have instead is a method which guide a string and tells us whether the on-screen toast matches that thread or not. This is enough for our intent of confirmation. So, let & # x27; s check out how to use themobile: isToastVisible method:

Read:
ImmutableMapargs = ImmutableMap.of (`` text '', `` toast textbook to match '', `` isRegexp '', false); driver.executeScript (`` mobile: isToastVisible '', args);

Like all mobile: method, we first need to manufacture a map of our arguments. This method takes two parameters: the text we want to look for, and a masthead which tells Appium whether this textbook is in the form of a bare string or a regular expression. If we setisRegexp to true, then we can look for toast messages using more forward-looking criterion, limited just by what we can express in a regular expression. Finally, we callexecuteScriptas the way of accessing the mobile: method.

Also read:

This is great, but as we & # x27; ve mention already, toasts are a time-sensitive phenomenon. So, we probably require to part looking for a matching goner before it start up, so we & # x27; re sure we don & # x27; t miss it. To this end, we can use a usage Explicit Wait. It & # x27; s possible to use the Java client & # x27; sExpectedConditioninterface to define our own custom expected weather, so that & # x27; s what we & # x27; ll do. Here & # x27; s a helper method that defines a newExpectedConditioncalled toastMatches:

public static ExpectedConditiontoastMatches (String matchText, Boolean isRegexp) {return new ExpectedCondition() {@ Override public Boolean apply (WebDriver driver) {ImmutableMapargs = ImmutableMap.of (`` text '', matchText, `` isRegexp '', isRegexp); return (Boolean) ((JavascriptExecutor) driver) .executeScript (`` mobile: isToastVisible '', args);} @ Override public String toString () {return `` goner to be present '';}};}

All we do is override the appropriate methods of theExpectedConditionclass, and ensure we hold appropriate typewriting in a few places, and we & # x27; ve got ourselves a skillful self-contained way of wait for goner messages, in conjunction with (for example)WebDriverWait. Since all the pieces are now in places, let & # x27; s conduct a look at what our test method itself could look like:

@ Test public void testToast () {WebDriverWait look = new WebDriverWait (driver, 10); final String toastText = `` Catch me if you can! ``; raiseToast (toastText); wait.until (toastMatches (toastText, false)); raiseToast (toastText); wait.until (toastMatches (`` ^Catch.+! ``, true));}

In this test, we delineate aWebDriverWaitand use it with ourtoastMatchescondition. You can see that we perform a match with both available style, first by matching the precise toast twine, and second by habituate a regular expression, foreground how we could verify the presence of a valid goner message even if it contains dynamically return content.

That & # x27; s it! If you haven & # x27; t assure out Appium & # x27; s Espresso driver for Android, validating goner messages is a full reason to give it a try. And if you want to see a working example with all the boilerplate, you can discover iton GitHubas always.

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 crafting engaging narrative and marketing collateral across diverse industries. She surpass in collaborating with cross-functional teams to develop innovative content strategies and deliver compelling, authentic, and impactful content that vibrate with quarry audiences and enhances brand authenticity.

LinkedIn

Validating Android Toast Messages

4 Parts

regression intelligence blog
-

Regression Intelligence hard-nosed guidebook for advanced users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence practical guide for advanced users (Part 4)

Coming Soon

Discover how HeadSpin can empower your line 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 productivity with faster development round
automated buil-over-build regression testing
Automate build-over-build regression testing for ordered results
gain better visibility into functional & performance issues
Gain better profile into functional and execution issues
reduce mean time
Reduce mean clip to identify/resolve during test, QA, and production
evaluate audio, video & qoe
Evaluate sound, picture, and content character of experience (QoE) effortlessly
The trusted choice for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
Close

Discover how HeadSpin can endue your occupation with superior testing capabilities

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

Discover how HeadSpin can empower your business with superior prove potentiality

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, profit a competitory edge
faster development cycles
Boost developer/QA productiveness with faster ontogenesis round
automated buil-over-build regression testing
Automate build-over-build regression testing for consistent results
gain better visibility into functional & performance issues
Gain best visibility into functional and execution issue
reduce mean time
Reduce mean time to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate audio, video, and contented quality of experience (QoE) effortlessly
The trusted choice for global 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