GraphQL Testing

How TestInspector Tests GraphQL Subscriptions and Real-Time Query Updates: Subscription Assertions, WebSocket State Validation, and Live Data Testing Without Code

How TestInspector Tests GraphQL Subscriptions and Real-Time Query Updates

How TestInspector Tests GraphQL Subscriptions and Real-Time Query Updates: Subscription Assertions, WebSocket State Validation, and Live Data Testing Without Code

Why GraphQL Subscriptions Require a Different Testing Approach

GraphQL subscriptions maintain a persistent WebSocket connection between client and server, pushing data to clients as it changes rather than waiting for a poll. Testing them requires validating that the initial connection establishes correctly, that specific events trigger the expected messages, and that the client state transitions correctly as the subscription receives updates — all behaviors that point-in-time HTTP assertions cannot test alone. TestInspector models subscription testing through HTTP request steps for connection setup, visual regression snapshots for DOM state changes, and conditional step logic for multi-event assertion sequences, without requiring any test code.

The standard approach to testing REST APIs — send a request, assert on the response, done — does not transfer to GraphQL subscriptions. A subscription test has three distinct phases: establishing the connection, triggering an event that the subscription should receive, and asserting that the client rendered the expected update. Each phase has its own failure modes, and collapsing them into a single assertion misses the gaps between them.

By 2026, GraphQL subscriptions appear in most real-time product features: live dashboards, collaborative editing, notification feeds, chat, inventory updates, and order status tracking. QA teams that only test REST endpoints leave these features untested in CI, catching failures only after users report them. Building subscription coverage into the automated test suite requires a different mental model than the request-response cycle most QA tooling assumes.

See also: Astaqc's software testing services for how we build automated coverage for real-time and event-driven applications, and our guide to what software testing is and why it matters for a broader foundation.

PhaseWhat to ValidateFailure Mode
ConnectionWebSocket upgrades, authentication, protocol negotiationConnection refused, auth failure, wrong protocol version
Event triggerMutation or state change fires the subscriptionEvent not emitted, wrong payload, subscriber not notified
Client renderUI reflects the received message correctlyState not updated, stale render, duplicate notification

How TestInspector Models GraphQL Subscription Testing

TestInspector's execution model runs in a real browser (Chrome, Firefox, Edge, or Safari) using Selenium, which means it has direct access to the same WebSocket connection a real user's browser would open. The browser's WebSocket implementation handles the low-level protocol negotiation and connection management; TestInspector's test steps work above that layer, interacting with the page's rendered state after each subscription message arrives.

A subscription test in TestInspector follows a four-step pattern. First, a navigation step opens the application page that initiates the subscription on mount — the subscription connection is established as part of the page load, the same way a real user would experience it. Second, an HTTP request step fires a mutation or API call that triggers the backend event the subscription is listening for. Third, a wait condition or polling assertion checks for the DOM change that indicates the subscription message was received and rendered. Fourth, a visual regression screenshot captures the final state for baseline comparison on subsequent runs.

The key insight is that TestInspector does not inspect WebSocket frames directly — it treats the subscription as an observable side effect on the UI and asserts on what the UI shows, not on the wire protocol. This matches how end-to-end tests should work: testing what the user experiences, not implementation details. The tradeoff is that it requires the subscription to actually update the DOM in a way that is assertable, which is true of any well-implemented real-time feature.

For teams building on TestInspector, this means no test code, no WebSocket client libraries, no async assertion utilities to manage. The same no-code test builder that handles form submissions and API assertions handles real-time subscription flows.

Validating WebSocket Connections and Subscription Setup

The most reliable way to validate that a subscription connection was established correctly is to assert on the UI state that appears immediately after connection — the loading indicator that disappears, the connected badge that shows, or simply the absence of an error state. GraphQL subscription clients (Apollo Client, urql, Relay) all expose connection state to the UI; well-structured applications render that state, making it assertable without any special tooling.

For the HTTP layer, TestInspector's HTTP request steps let you send the WebSocket handshake upgrade request and assert on the 101 Switching Protocols response status. For applications that use a HTTP-first transport (GraphQL over Server-Sent Events or long-polling fallback), the HTTP step can directly validate the connection. For pure WebSocket transports, the connection validation happens through the page's rendered state.

Subscription authentication is a common failure point that is easy to miss in automated tests. GraphQL subscriptions typically send credentials in the connection_init message rather than in HTTP headers, because the initial WebSocket upgrade is an HTTP GET that does not carry a body. TestInspector handles this by navigating to the page with a valid session cookie set through a prior login step, letting the browser's WebSocket client send the correct authorization in the connection_init payload. The same TOTP and variable interpolation features that handle 2FA in HTTP tests work here — set up the authentication state once, and all subscription steps in the test suite inherit it.

Subscription PatternTestInspector ApproachWhat Gets Validated
Initial connectionPage navigation + connection UI state assertionConnection established, auth accepted
Event-triggered updateHTTP mutation step + DOM assertionMessage received, UI updated correctly
Multiple sequential eventsMultiple HTTP steps + intermediate assertionsState accumulates correctly, no dropped messages
Reconnection after disconnectPage reload + subscription re-establishmentReconnect logic works, no stale state

Testing Real-Time State Transitions Without Code

The most challenging aspect of subscription testing is timing. A subscription message arrives asynchronously — after the triggering event, but at an indeterminate time depending on network conditions, server processing, and client rendering. Tests that assert too quickly will fail intermittently because the update has not arrived yet. Tests that wait too long waste CI time.

TestInspector's self-healing retry mechanism handles this automatically. When a DOM assertion fails (the expected element is not visible, the expected text has not appeared), TestInspector retries with exponential backoff and AI selector suggestions before marking the step as failed. This retry behaviour is well-suited to subscription testing because it naturally waits for the message to arrive and render without requiring explicit wait steps or hardcoded delays.

For more complex subscription scenarios — where the application should show a specific sequence of states, not just a final state — TestInspector's step conditions and branch logic let you model the expected state machine. Assert that the loading state appears first, then disappears, then the data appears. Each condition in the sequence is a visual or DOM assertion; the test fails if any state in the sequence is missing or appears out of order.

Visual regression testing is particularly useful for subscription updates that change layout significantly — a notification that expands a panel, a live counter that increments, a feed that prepends new items. Take a visual baseline after the initial page load (subscription connected, waiting for events), then take a second baseline after the triggering event (subscription message received, UI updated). Compare these two baselines on future runs: the first confirms the initial state is consistent, the second confirms the update was applied correctly.

TestInspector's screenshot comparison uses SSIM (Structural Similarity Index) rather than pixel-perfect matching, which means minor rendering differences across browsers and operating systems do not cause false failures. The crop and exclusion selector features let you mask dynamic content — timestamps, user-generated data, animated elements — that changes legitimately between runs without indicating a regression. For subscription testing, exclude the timestamp on the most recent message but assert on the message content itself.

See test automation services for how Astaqc builds real-time test coverage for applications with event-driven and subscription-based architectures.

Frequently Asked Questions

Can TestInspector test GraphQL subscriptions over WebSocket without writing code?

Yes. TestInspector runs tests in a real browser, which establishes the WebSocket connection the same way the application does during normal use. No WebSocket client code is required in the test suite. Test steps interact with the page’s rendered output — DOM elements, visual states, HTTP assertions — rather than with the WebSocket protocol layer directly. This means any subscription-driven UI update that is visible to the user is assertable in TestInspector without code.

How do I assert that a specific message was received on a subscription?

Assert on the DOM change that the subscription message triggers in the UI. If your application updates a counter, prepends a list item, shows a toast notification, or changes a status badge when a subscription message arrives, assert on that element’s presence, text, or visual state. If the UI does not reflect subscription messages in the DOM, the assertion needs to be at the HTTP layer — trigger the event that fires the subscription and assert on the HTTP response from the mutation, then separately validate that the application state reflects the change on the next page load.

What is the difference between polling and subscription testing in TestInspector?

Polling tests follow the standard request-response model: a step fires an HTTP request at an interval, and each response is assertable independently. Subscription tests assert on the UI state that changes in response to push events — the trigger is a step in the test, but the assertion is on the page’s rendered state rather than on a response body. TestInspector’s retry behaviour makes subscription assertions resilient to the timing gap between trigger and render without requiring explicit polling loops in the test logic.

How do I test subscription error handling in TestInspector?

To test what happens when a subscription fails (server error, connection dropped, authentication expired), trigger the error condition through the application’s normal UI or through an HTTP step that sends an invalid subscription request, then assert on the error state the application renders. For authentication expiry scenarios, use TestInspector’s cookie and session management to clear the session mid-test, then assert that the application renders the expected re-authentication prompt or error message rather than hanging silently.

Can I use TestInspector to test GraphQL subscriptions in different browsers?

Yes. TestInspector runs the same test suite across Chrome, Firefox, Edge, and Safari using Selenium. Each browser uses its own WebSocket implementation, which means browser-specific subscription bugs — differences in connection_init timing, reconnection behaviour, or how the browser handles WebSocket upgrades through certain proxy configurations — are caught when the same test fails on one browser but passes on others. The visual regression comparison stores per-browser baselines when browser rendering differences are significant.

Summary: GraphQL Subscription Testing Without Framework Overhead

GraphQL subscriptions are the real-time backbone of modern web applications, and they are chronically undertested because most QA tooling assumes the request-response model. TestInspector’s execution model — a real browser, visual regression, HTTP steps, and self-healing retries — covers all three phases of subscription testing without custom WebSocket client code or complex async assertion utilities.

The practical approach: start by asserting on the connection state UI that appears on page load, then write one test per subscription event type that fires a triggering HTTP step and asserts on the resulting DOM change. Add visual regression baselines for subscription-heavy pages to catch layout regressions when the backend message schema changes. This builds meaningful real-time coverage into the automated suite without the overhead of a code-first test framework.

GraphQL subscription testing with TestInspector — 6-slide overview

Explore TestInspector for GraphQL and real-time application testing, or see Astaqc’s software testing services for teams that need to build subscription test coverage from the ground up.

GraphQL subscriptions require testing across three distinct phases — connection, event trigger, and client render — and TestInspector handles all three through DOM assertions and visual regression without custom WebSocket client code.

Astaqc Team

December 2, 2026

icon
icon
icon

Stop finding bugs after launch.

Talk to our QA team and start testing this week.

Get in touch →

Subscribe to our Newsletter

Sign up to receive and connect to our newsletter

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Ask our AI assistant…