Skip to content
Tutorials Center
My learning

Topics

Lesson 33 of 37 ยท CI and Best Practices

Debugging and Performance: Logs, Inspector and Faster Sessions

Debug Appium sessions with the Inspector, server logs and page source, and make tests faster by skipping UI steps, reusing sessions, and trimming commands.

Two questions occupy most of the time of anyone who maintains mobile tests: "why did this fail?" and "why is this so slow?" Both have systematic answers. This lesson gives you a debugging routine (what to look at, in which order), the tools Appium provides, and the main techniques to shorten test time without making tests less reliable.

The tools themselves, the Inspector, the server and a device, cannot run on this site, so commands and settings are read-only. The runnable stand-ins analyze a page source and compare command counts.

A debugging routine

When a test fails, go through these in order:

  1. Read the error. NoSuchElementException means the locator found nothing at that moment; StaleElementReferenceException means the screen changed after you found the element; SessionNotCreatedException means the capabilities or environment are wrong; a timeout means a wait expired.
  2. Look at the screen. Screenshot or video at the moment of failure often answers it: a permission dialog, an error banner, the wrong screen.
  3. Read the page source. Compare the element you expected with what is really there (a different ID, a different text, hidden).
  4. Read the Appium server log. It shows the exact command and the exact response.
  5. Read the device log. logcat or syslog shows app crashes and exceptions.
  6. Reproduce interactively in the Appium Inspector.

Appium Inspector

The Appium Inspector is a desktop app (separate from the server) that connects to a running Appium server, starts a session with your capabilities and shows a live screenshot next to the element tree. You click an element on the screenshot and it shows the attributes: accessibility ID, resource ID, class, text, bounds, and suggested locators. You can then test a locator, tap, swipe and type from the Inspector to check what works before you write code.

Typical use:

  1. Start the Appium server (appium).
  2. Open Inspector, set the server URL (host 127.0.0.1, port 4723, path / for Appium 2 and later).
  3. Paste your capabilities as JSON, using appium: prefixed keys, and start the session.
  4. Click elements, copy locators, use "Search for element" to test a strategy.
  5. Close the session; an open Inspector session blocks the device for your tests.

Inspector's page source is the same XML the driver would give your code with driver.page_source.

Reading page source

Python
source = driver.page_source

Android's source has nodes like <android.widget.Button resource-id="com.example.shop:id/pay" content-desc="Pay" text="Pay now" clickable="true" enabled="true" displayed="true" bounds="[40,1650][1040,1790]"/>. iOS has XCUIElementTypeButton nodes with name, label, value, enabled, visible, x, y, width, height.

Python Auditing locators in a page source (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Any clickable element without an ID or description will end up as a fragile XPath or text locator. A small audit like this one is a nice review artifact for the app team.

Logs and server flags

Raise the server's verbosity while debugging, and save logs to a file:

Terminal
appium --log-level debug --log appium.log --log-timestamp --log-no-colors
appium --relaxed-security            # only for local experiments, never shared servers

Read the log for the failing command: its request body, the response, and the driver's own lines. On Android also fetch the device log from your test: driver.get_log("logcat"), or run adb logcat -d > device.log after the failure.

Session-level help: appium:newCommandTimeout ends idle sessions, and the capability appium:printPageSourceOnFindFailure (check that your driver version supports it) makes the server print the page source into the log whenever a lookup fails, which saves many reproductions. Use it while debugging; it slows failing lookups.

Making tests faster

Start by measuring where the time goes: startup, setup (login, data), the flow under test, and teardown. Most gains come from setup.

Technique Saves
Skip login through a deep link, a token or a pre-authenticated state 10 to 60 seconds per test
Create data through an API, not the UI Seconds to minutes
noReset with a clean-app step instead of reinstalling Install time per test
Reuse one session per group, resetting the app (terminate_app, activate_app) Session startup
Disable device animations Frequent small waits
Prefer accessibility ID or ID to XPath Hundreds of ms per lookup
find_element once, reuse; avoid find_elements in loops Many round trips
Skip full screenshots except on failure Per-step cost
Parallelize (see Parallel Runs) Wall-clock time

Every command is an HTTP round trip to the server and then to the device. Fewer commands mean faster tests, especially on a cloud farm.

Python Counting commands: UI setup versus shortcut (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common debugging traps

  • Debugging against the wrong build. Confirm the installed version (adb shell dumpsys package <id> | grep versionName).
  • A stale Appium server. Restart it; zombie sessions hold devices.
  • Changing the test when the app is wrong. If the screenshot shows a real bug, report it.
  • Leaving the Inspector connected while the suite starts.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does the Appium Inspector show?

    It combines a screenshot with the page source and lets you test locators.
  2. 2. Which is usually the biggest source of time savings in a mobile test?

    Setup done through the UI repeats in every test; shortcuts remove it.
  3. 3. Why is printPageSourceOnFindFailure best kept to debugging sessions?

    The server must fetch and print the full source on every failed find.
  4. 4. A StaleElementReferenceException means:

    Re-find the element after the UI updates.

Summary

  • Debug in order: error, screenshot, page source, Appium log, device log, then reproduce in the Inspector.
  • Close the Inspector before running suites; it holds the device.
  • Use debug logging and save logs; keep insecure flags off shared servers.
  • Speed comes from fewer commands and skipping UI setup; measure first.
  • Audit page source for elements without IDs and ask developers for accessibility labels.

Next: The Mobile Test Automation Checklist