Calling Methods Inside Your App From Appium

January 25, 2026 · 9 min read · Tool Comparison

HeadSpin Platform
Automated & amp; manual testing do leisurely through datum science insights.
Differentiating capableness:
  • Extensive end-to-end automation of QA procedure
  • Comparative analysis of app performance against peers
  • Continuous monitoring of app performance utilize synthetic data for higher availability of apps
  • Easy-to-use developer friendly platform
cloudtest go
Affordable Real Device Testing for Emerging Teams
cloudtest go
Affordable 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

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

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

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

Calling Methods Inside App From AppiumCalling Methods Inside App From Appium

Calling Methods Inside Your App From Appium

Published on
January 9, 2019
Updated on
Published on
April 26, 2022
Updated on
 by 
 Jonathan LippsJonathan Lipps
Jonathan Lipps

Appium is traditionally see a & quot; black box & quot; testing tool, meaning it has no access to your application & # x27; s internal methods or province. We use Appium aright by thinking like a user would (interacting with the surface of the app), not thinking like an app developer would (calling internal codification straightaway).

Accelerate Appium exam round with the HeadSpin, a solution for wandering app mechanisation.!

Black box testing has its restriction, principally in requiring the automation to go through user steps many times, even when it would be more convenient to skip to a sure known province. This is one reason that some modern testing technologies, like Espresso, allow for awhite box testingapproach, where internal app methods are accessible from the automation context.

Read:

Thanks to Appium & # x27; s Espresso driver, Appium can now take advantage of this approach. (If you recall, Espresso is also what enable us to). To make this more general white box strategy employment, you take two things:

  1. Knowledge of a particular public method located on your Android application, activity, or UI ingredient. This is the method that your examination script will finally trigger in the line of your automation. You can either code this method up yourself or ping your Android app developer to add one that encounter your specifications.
  2. The new mobile: backdoor method available on the Appium Espresso driver. This is the existent method you will call in your trial code, which will tell the Espresso driver what to run inside your app. (It & # x27; s ring & quot; backdoor & quot; because Appium is getting inside of your app through the & quot; back doorway & quot; of Espresso, not the & quot; front doorway & quot; of the UI that a user would use. This approach was 1st publically suggested by Rajdeep Varma in hisAppiumConf 2018 talk, and Rajdeep was the one who contributed the code to create it a realism in Appium today. Thanks!)

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

Also read:

To instance how this works, I & # x27; ve lend a method to the application class ofThe App, in its MainApplication.java:

public nihility raiseToast (String message) {Toast.makeText (this, message, Toast.LENGTH_LONG) .show ();}

This method simply take an arbitrary string and habituate it to make an Android Toast message seem on the screen. The result of calling this method looks like this:

Android Toast message

With a normal Appium test, there & # x27; s no way I would be able to spark this toast to appear, unless the developer had hooked it up to a text field and a button. But with roving: backdoor, I can simply point the name of the method I want to call in my app, the types and values of its parameters, and off we go! So, here & # x27; s how I would do this in Java:

ImmutableMapscriptArgs = ImmutableMap.of (`` target '', `` application '', `` methods '', Arrays.asList (ImmutableMap.of (`` gens '', `` raiseToast '', `` args '', Arrays.asList (ImmutableMap.of (`` value '', `` Hello from the test script! ``, `` character '', `` String ''))))); driver.executeScript (`` mobile: backdoor '', scriptArgs);

It & # x27; s a little verbose, so let & # x27; s expression at the argument I & # x27; m passing to mobile: backdoor as a JSON object instead:

{`` mark '': `` covering '', `` methods '': [{`` name '': `` raiseToast '', `` args '': [{`` value '': `` Hello from the test script! ``, `` type '': `` String ''}]}]}

I set two main bits of information: thetargetof my backdoor (which type of thing am I call the method on), and themethodsI desire to call on it. In this case I have implemented my method on the application class, so I delineate covering as the mark. Other possible value are activity (for methods implemented on the current activeness), or element (for method apply on a specific UI element -- in this causa, an elementId argument is too required).

Check out:

The most significant information resides in methods. In our instance I & # x27; m merely calling one method, though we could call multiple. For each method, we receive to specify its gens (raiseToast -- it must exactly match the gens in my Android codification), and the potentially multiple arguments we want to pass in to call the method with. For each of these arguments in turn we must specify both its type and value (the type is necessary because Java!).

Once we & # x27; ve got all this put together, we simply bundle it up and pass it as the argument to executeScript (& quot; mobile: backdoor & quot;). Using the ImmutableMap.of construction as I & # x27; ve shown above is the most concise way, I & # x27; ve found so far to do this in Java.

Automated & amp; manual testing made easygoing through datum science insights.for more information.

That & # x27; s all there is to it! This method in conjunction with the Espresso driver frees us from the shackles of the UI, and enables us to target specific method inside our app. The possibleness here are endless, so please write to us and let us know what cool things you find to do with the feature. But remember, with great power comes great responsibility! It would probably be very leisurely to use this lineament to ram your app during screen, too.

Test your mobile apps and browsers on existent Android devices.!

Here & # x27; s a full exemplar that shows the toast message be raised on our test app:

import com.google.common.collect.ImmutableMap; importee io.appium.java_client.AppiumDriver; significance java.io.IOException; import java.net.URL; import java.util.Arrays; import org.junit.After; meaning org.junit.Before; significance org.junit.Test; import org.openqa.selenium.remote.DesiredCapabilities; public family Edition051_Android_Backdoor {private String APP = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.8.1/TheApp-v1.8.1.apk ''; individual AppiumDriver driver; @ Before public nihility setUp () drop IOException {DesiredCapabilities caps = new DesiredCapabilities (); caps.setCapability (`` platformName '', `` Android ''); caps.setCapability (`` deviceName '', `` Android Emulator ''); caps.setCapability (`` automationName '', `` Espresso ''); caps.setCapability (`` app '', APP); driver = new AppiumDriver (new URL (`` http: //localhost:4723/wd/hub ''), detonator);} @ After public emptiness tearDown () {try {driver.quit ();} haul (Exception ign) {}} @ Test world vacancy testBackdoor () {ImmutableMapscriptArgs = ImmutableMap.of (`` prey '', `` covering '', `` method '', Arrays.asList (ImmutableMap.of (`` name '', `` raiseToast '', `` args '', Arrays.asList (ImmutableMap.of (`` value '', `` Hello from the test handwriting! ``, `` type '', `` String ''))))); driver.executeScript (`` mobile: backdoor '', scriptArgs); try {Thread.sleep (2000);} catch (Exception ign) {} // pause to permit visual verification}}

(As always, the entire code sampling is too upon GitHub)

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 employ narratives and marketing collateral across diverse industries. She excels in collaborating with cross-functional teams to develop innovational content strategies and render compelling, unquestionable, and impactful content that resonates with quarry audiences and enhances make authenticity.

LinkedIn

Calling Methods Inside Your App From Appium

4 Parts

regression intelligence blog
-

Regression Intelligence practical usher for advanced users (Part 3)

Coming Soon
Regression Intelligence practical guide for advanced users
-

Regression Intelligence practical usher for modern users (Part 4)

Coming Soon

Discover how HeadSpin can empower your business with superior testing capabilities

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

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 competitory edge
faster development cycles
Boost developer/QA productivity with faster ontogeny cycles
automated buil-over-build regression testing
Automate build-over-build regression screen for consistent results
gain better visibility into functional & performance issues
Gain better profile into functional and performance issues
reduce mean time
Reduce hateful 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 line with superior testing capableness

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, gaining a private-enterprise edge
faster development cycles
Boost developer/QA productivity with faster growth cycles
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 time to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate audio, video, and contented caliber of experience (QoE) effortlessly
The trusted choice for global endeavour
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