Overview

Debugging mobile app tests is not as straightforward as the web as dev tools is not available. In order to debug mobile app tests, Appium inspector will have to be setup and attached to a test session

Pre-requisites

Appium inspector is recommended for debugging tests. To setup Appium inspector follow this guide

Debugging using Appium Inspector

Step 1

Add a debug point just before the error using .debug() command in the test script as shown below

test.js

app
  .useXpath()
  .click('//XCUIElementTypeSearchField[@name="Search Wikipedia"]')
  .sendKeys('//XCUIElementTypeSearchField[@name="Search Wikipedia"]','browserstack')
  .click('//XCUIElementTypeStaticText[@name="BrowserStack"]')
  .debug()

Step 2

Run the test so that the Nightwatch test session is created

Step 3

Open Appium Inspector and attach session

Debugging setup with Appium Inspector

If you are using Appium 1 add /wd/hub to the Remote path field for Appium inspector to be able to get the active sessions from the Appium server.

That's it! Your test session has been setup for debugging

Step 4

Once the tests' session is attached, you can select elements in the left pane to highlight it in the App Source pane and view all the details & attributes in the Selected Element pane as shown below.

Debugging with Appium Inspector

You can also run Appium commands in the Commands tab as shown below

Running commands with Appium inspector

Debugging with debugger console in terminal

Step 1

Add a debug point just before the error using .debug() command in the test script as shown below

test.js
app
  .useXpath()
  .click('//XCUIElementTypeSearchField[@name="Search Wikipedia"]')
  .sendKeys('//XCUIElementTypeSearchField[@name="Search Wikipedia"]','browserstack')
  .click('//XCUIElementTypeStaticText[@name="BrowserStack"]')
  .debug()

Step 2

Run the test so that the Nightwatch test session is created.

Step 3

Pass Nightwatch commands/assertions to Nightwatch debug console open in the terminal.