Skip to content

iOS UI-test network logs

Appelium can attach structured HTTP request and response data to an XCUITest run. Use it when a failure may be caused by fixture setup, backend availability, response content or timing rather than the UI action alone.

Automatic URLSession capture

Start AppeliumTests as early as possible in the test runner:

override func setUpWithError() throws {
    AppeliumTests.start(apiKey: "YOUR_TEST_API_KEY")
}

After startup, URL sessions created with URLSession.shared, .default, .ephemeral or a custom URLSessionConfiguration are instrumented automatically. The SDK injects its protocol handler and records a request and response pair.

Create long-lived custom sessions after AppeliumTests.start(...). A URLSession instance captured before SDK startup may continue to use its original configuration and therefore cannot be retroactively instrumented.

Automatic capture does not mean every request made by the application under test belongs to the test runner. The application process needs its own AppeliumFeedback network logging integration when that is the traffic you want to diagnose.

Manual request capture

Use the manual API for a networking stack that bypasses URLSession or for a test helper that completes a request before Appelium can observe it.

Start with either a URL and its parts:

let token = AppeliumTests.logRequestStart(
    url: requestUrl,
    method: "POST",
    headers: ["Content-Type": "application/json"],
    body: requestBody
)

or an existing request:

let token = AppeliumTests.logRequestStart(urlRequest: urlRequest)

Keep the returned token and finish the same request with the response:

AppeliumTests.logRequestFinish(
    token: token,
    statusCode: 201,
    headers: ["Content-Type": "application/json"],
    data: responseBody
)

If the request produced an HTTPURLResponse, pass it directly so the complete response metadata remains available:

AppeliumTests.logRequestFinish(
    token: token,
    response: response,
    data: responseBody
)

For a transport failure:

AppeliumTests.logRequestError(token: token, error: error as NSError)

Call exactly one finish or error method for each start token. The token links timing, request and terminal response.

Add test intent to the timeline

Network data alone does not explain why a request occurred. Pair it with the test phase:

AppeliumTests.logInfo(
    "Creating paid order fixture",
    domain: "Fixtures"
)