Skip to main content
SOAP

SOAP Fault Handling

ErrorParseValidateMedium

What you will learn

  • Faults are first-class responses, not exceptions โ€” body returns <soapenv:Fault> with faultcode + faultstring
  • Distinguish Client faults (caller error, 400-like) from Server faults (server error, 500-like) โ€” retry semantics differ
  • Detail element carries structured error data โ€” parse it, don't just string-match the faultstring

Description

Handle SOAP fault responses for errors.

Test Scenario

// Divide by zero triggers fault
const envelope = `...<Divide><a>10</a><b>0</b></Divide>...`;
const response = await request.post('/api/soap', { data: envelope });

expect(response.status()).toBe(500);
const body = await response.text();
expect(body).toContain('soap:Fault');
expect(body).toContain('Division by zero');
Endpoint/api/soap

Testing Tips

  • โ€ขFaults use soap:Fault element
  • โ€ขCheck faultcode and faultstring
  • โ€ขStill returns 500 HTTP status
// Playwright API Testing - SOAP
import { test, expect } from '@playwright/test';
test('SOAP request', async ({ request }) => {
const soapEnvelope = `<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetUsers xmlns="http://api.example.com/"/>
</soap:Body>
</soap:Envelope>`;
const response = await request.post('/api/soap', {
headers: { 'Content-Type': 'text/xml' },
data: soapEnvelope
});
expect(response.ok()).toBeTruthy();
const text = await response.text();
expect(text).toContain('soap:Envelope');
});

Challenge ID: soap-fault-handling

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/soap

Press Enter to send