Capturing Network Traffic in Java with Appium

April 15, 2026 · 10 min read · Tool Comparison

HeadSpin Platform
Automated & amp; manual examination made easygoing through data science brainwave.
Differentiating capacity:
  • Extensive end-to-end automation of QA process
  • Comparative analysis of app execution against match
  • Continuous monitoring of app execution using synthetic data for higher availability of apps
  • Easy-to-use developer friendly program
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

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

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

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

Capturing Network Traffic in Java with AppiumCapturing Network Traffic in Java with Appium

Capturing Network Traffic in Java with Appium

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

Wrapping up a short serial using Appium to captivate web traffic. I & # x27; m happy to presentmitmproxy-java, a small library which allows convenient access to network requests of devices make in the middle of your test runs. It has the following features that assist with utilise Appium to capture network traffic. I was unable to find these features using other method in Java.

  • Starts the proxy server as a background task.
  • Allows for surpass in a lambda mapping which get called for every intercepted message, permit you to manage the transcription of data any way you see fit.
  • Allows for modifying the responses from the procurator, so you can shoot arbitrary data and province into your app.
  • Captures HTTPS traffic yet when ip address are habituate instead of horde names.

To help us to use Appium to capture network traffic, the first three advantages arrive from the negligee code inmitmproxy-javawhich is fundamentally a Java version of the outstanding Node.js module I found for the same purpose:mitmproxy-node. The last slug point comes from the use ofmitmproxy.

Traditionally, the try community mostly seems to use Browsermob Proxy, but I plant it has not been maintained recently and can & # x27; t support Android aper due to the issue with HTTPS traffic and ip address. I & # x27; m hoping that people will be able to findmitmproxy-javaas especially for this topic of use Appium to capture mesh traffic.

But delight help! I put a lot of work into it but I & # x27; m not a Java expert. The way I presently handle elision isn & # x27; t friendly. Hop onto github and submit pull requests or get number if you run into trouble. If the community is supportive, we can ameliorate it farther.

Oh, this should work for Selenium too, if you set up the browser to proxy correctly.

Setup

For those just tuning in, see the past two articles on using Appium to capture network traffic to discover about what we & # x27; re make and how it act:

Those two articles on expend Appium to charm mesh traffic besides go through the setup ask for configure device, this post will centre on setting upmitmproxy-javaand how to write the Java test code.

While mitmproxy-javawill start the procurator waiter for us programmatically, we take to instalmitmproxyourselves, simply like we did in the premature article. Make sure to install withpip3 since installing with other methods, misses some python habituation which we ask.

sudo pip3 install mitmproxy

For autonomous testing across multiple user personas, check out SUSATest — it explores your app like 10 different real users.

Don ’ t Rely on iOS Emulators & amp; Android Simulators..

When runningmitmproxy-java, we need to furnish it with the location of themitmdump executable.mitmdump is establish mechanically when you installmitmproxyand is a commandline version ofmitmproxywhich isn & # x27; t interactive and scat in the background. Let & # x27; s get that location and do a note of it for later.

which mitmdump

For me the yield is/usr/local/bin/mitmdump.

Test and monitor site & amp; apps with our vast real local devices across the reality..

Next, we need to install the Python websockets module. the waymitmproxy-javaplant, is it commencemitmdump with a special Python plugin which is included inside themitmproxy-javajar. This plugin scat insidemitmdump and connects to a websocket server hosted bymitmproxy-java. The Python codification so transfers request/response information to the Java code over the websocket.

pip3 install websockets

That should be all the setup we want on our horde machine, now on to the actual test code.

Writing a Test Using mitmproxy-java

Include themitmproxy-javajar in your undertaking. The library ishosted on Maven Central Repository.

Add the following to your pom file:

Or in yourbuild.gradlefile, for Gradle users:

compile group: 'io.appium ', name: 'mitmproxy-java ', version: ' 1.6.1 '

You can now access two classes in your test codification:MitmproxyJava- The class which starts and stops the proxy.InterceptedMessage- A class used to represent content intercept by the proxy. A & quot; substance & quot; includes both an HTTP asking, and its matching response.

Read:

The constructor forMitmproxyJavatakes two arguments. The first is a String with the way to themitmdump feasible on your computer. We got this value originally in the setup section. The second debate is a lambda function which theMitmproxyJavainstance will call every time it tap a web request. You can do anything you like with theInterceptedMessagepass in. In the next example, we create aList of InterceptedMessageaim and instantiate a newMitmproxyJavacase. every intercepted substance gets added to our list, which is in setting for the repose of the exam.


Listmessages = new ArrayList(); // recollect to set local OS proxy settings in the Network Preferences placeholder = new MitmproxyJava (`` /usr/local/bin/mitmdump '', (InterceptedMessage m) - > {System.out.println (`` intercepted request for `` + m.requestURL.toString ()); messages.add (m); return m;});

Notice that we render the message from the lambda function. If we forget to retrovert it, no worries, this is the implicit behavior. If you stymie or shed an fault though, then the message reaction never completes its journeying to your test device.

Also read:

You can likewise alter the reply in theInterceptedMessage. Modifyingm.responseHeadersand pose different byte in the content ofm.responseBodywill result in overwrite the data which the device receives in reaction to its request.

Now that we & # x27; ve instantiated ourMitmproxyJavaobject, all we necessitate to do is ring

proxy.start ();

to start the proxy server and start collect responses. This method yell lead in a separate thread. Call

proxy.stop ();

to shut down.

Check:

The proxy, by default, runs onlocalhost:8080just like in the representative from the previous article. One succeeding feature should be to allow configuration of this port.

That & # x27; s it!

Here & # x27; s an illustration of an intact tryout for Android and iOS, expendmitmproxy-java:

import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; importation io.appium.java_client.ios.IOSDriver; import org.junit.After; importation org.junit.Test; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; importation java.io.IOException; import java.net.URISyntaxException; import java.net.URL; significance java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util. *; import java.util.concurrent.ExecutionException; meaning java.util.concurrent.TimeoutException; import static junit.framework.TestCase.assertTrue; public family Edition065_Capture_Network_Requests {private String ANDROID_APP = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.8.1/TheApp-v1.9.0.apk ''; individual String IOS_APP = `` https: //github.com/cloudgrey-io/the-app/releases/download/v1.6.1/TheApp-v1.6.1.app.zip ''; // in order to download, you may need to install the mitmproxy security on your operating system first. Or download the app and supplant this capability with the way to your app. individual AppiumDriver driver; private MitmproxyJava placeholder; @ After public void Quit () throw IOException, InterruptedException {proxy.stop (); driver.quit ();} @ Test public void captureIosSimulatorTraffic () throws IOException, URISyntaxException, InterruptedException, ExecutionException, TimeoutException {Listmessages = new ArrayList(); // remember to set local OS placeholder setting in the Network Preferences placeholder = new MitmproxyJava (`` /usr/local/bin/mitmdump '', (InterceptedMessage m) - > {System.out.println (`` intercept request for `` + m.requestURL.toString ()); messages.add (m); regress m;}); proxy.start (); DesiredCapabilities cap = new DesiredCapabilities (); caps.setCapability (`` platformName '', `` iOS ''); caps.setCapability (`` platformVersion '', `` 12.0 ''); caps.setCapability (`` deviceName '', `` iPhone Xs ''); caps.setCapability (`` automationName '', `` XCUITest ''); caps.setCapability (`` app '', IOS_APP); driver = new IOSDriver (new URL (`` http: //0.0.0.0:4723/wd/hub ''), cap); // automatically install mitmproxy certificate. Can be skipped if make manually on the simulator already. Path certificatePath = Paths.get (System.getProperty (`` user.home ''), `` .mitmproxy '', `` mitmproxy-ca-cert.pem ''); Mapargs = new HashMap < > (); byte [] byteContent = Files.readAllBytes (certificatePath); args.put (`` content '', Base64.getEncoder () .encodeToString (byteContent)); driver.executeScript (`` mobile: installCertificate '', args); WebElement picker = driver.findElementByAccessibilityId (`` Picker Demo ''); picker.click (); WebElement push = driver.findElementByAccessibilityId (`` learnMore ''); button.click (); WebDriverWait expect = new WebDriverWait (driver, 5); wait.until (ExpectedConditions.alertIsPresent ()); driver.switchTo () .alert () .accept (); assertTrue (messages.size () > 0); InterceptedMessage appiumIORequest = messages.stream () .filter ((m) - > m.requestURL.getHost () .equals (`` history.muffinlabs.com '')) .findFirst () .get (); assertTrue (appiumIORequest.responseCode == 200);} @ Test public void captureAndroidEmulatorTraffic () throws IOException, URISyntaxException, InterruptedException, ExecutionException, TimeoutException {Listmessage = new ArrayList(); // remember to set local OS proxy settings in the Network Preferences proxy = new MitmproxyJava (`` /usr/local/bin/mitmdump '', (InterceptedMessage m) - > {System.out.println (`` intercepted request for `` + m.requestURL.toString ()); messages.add (m); return m;}); proxy.start (); DesiredCapabilities caps = new DesiredCapabilities (); caps.setCapability (`` platformName '', `` Android ''); caps.setCapability (`` platformVersion '', `` 9 ''); caps.setCapability (`` deviceName '', `` test-proxy ''); caps.setCapability (`` automationName '', `` UiAutomator2 ''); caps.setCapability (`` app '', ANDROID_APP); driver = new AndroidDriver (new URL (`` http: //0.0.0.0:4723/wd/hub ''), caps); WebElement picker = driver.findElementByAccessibilityId (`` Picker Demo ''); picker.click (); WebElement button = driver.findElementByAccessibilityId (`` learnMore ''); button.click (); WebDriverWait wait = new WebDriverWait (driver, 5); wait.until (ExpectedConditions.alertIsPresent ()); driver.switchTo () .alert () .accept (); assertTrue (messages.size () > 0); InterceptedMessage appiumIORequest = messages.stream () .filter ((m) - > m.requestURL.getPath () .equals (`` /date/1/1 '')) .findFirst () .get (); assertTrue (appiumIORequest.responseCode == 200);}}

Full source code for this example can be institute with all our example codificationon 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 crafting engaging narratives and market collateral across diverse diligence. She excels in collaborating with cross-functional team to develop innovative substance scheme and deliver compelling, authentic, and impactful content that resonate with target audiences and enhances brand authenticity.

LinkedIn

Capturing Network Traffic in Java with Appium

4 Parts

regression intelligence blog
-

Regression Intelligence practical guide for modern 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 business with superior essay capabilities

Our Platform enable you to:
accelerate time-to-market
Accelerate time-to-market, gaining a competitive edge
faster development cycles
Boost developer/QA productiveness with quicker evolution cycles
automated buil-over-build regression testing
Automate build-over-build fixation test for consistent results
gain better visibility into functional & performance issues
Gain better visibility into functional and performance issues
reduce mean time
Reduce average time to identify/resolve during test, QA, and product
evaluate audio, video & qoe
Evaluate audio, picture, and content quality of experience (QoE) effortlessly
The sure option for global enterprises
Adobe
Hargreaves Lansdown
Truecaller
Crazylabs
Nedbank
Numeracle
Veryon
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 productivity with faster development cycles
automated buil-over-build regression testing
Automate build-over-build fixation testing for coherent 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 sure choice for globular enterprises
Close

Discover how HeadSpin can authorise your business with superior examine capabilities

Our Platform enables you to:
accelerate time-to-market
Accelerate time-to-market, win 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 essay for consistent outcome
gain better visibility into functional & performance issues
Gain best visibility 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 sure choice for spheric 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