Guide
How to check API calls inside an end-to-end test, without code
A page can say "Order confirmed" while the order never reached the server, or reached it twice. A network check makes the test look at the request behind the click: its status, how long it took, what was sent and what came back. This guide shows how to add one in Assertline by pointing at the request, not by writing code.
What a check on the page cannot see
- A failure the page hides. The server answers with an error and the page still shows the happy message it had ready.
- A call made twice. A double click places two orders. The page looks the same.
- A call that must not happen. A retry of a payment, or a tracking call before consent was given.
- An answer that got slow. The page works, three seconds later than last month.
Each of these is a fact about the request, so that is where the test has to look.
What you can assert about a request
| About the request | Example |
|---|---|
| Status | The order request was answered with 201. |
| Response time | It was answered in less than 800 ms. |
| Headers | The answer carries the content type you expect. |
| Query | The search request was sent with page=2. |
| JSON fields | In the answer, $.order.total equals 48.00. |
| Number of calls | The order request was made exactly once. |
| Never called | No request was made to the payment retry address. |
How to add a network check
- Record your journey with the free recorder. (How to record a test.)
- After the step that sends the request, for example the click on "Place order", press Add check and choose the network check.
- Pick the request from the ones that step caused. You do not type its address: the recorder saw it happen.
- Say what must be true about it: its status, a field of its answer, how often it was made.
When the test runs, the check waits for the request to be made and answered before it decides, so a slow server does not fail it by accident.
An example: placing an order
The step is a click on "Place order", which sends POST /api/orders. Four checks on that one request, and one on a request that must not happen:
| Check | Expected | Found in the run |
|---|---|---|
| Status | equals 201 | 201 |
| Response time | less than 800 ms | 182 ms |
JSON field $.order.total | equals 48.00 | 48.00 |
| Calls | exactly 1 | 1 |
| Never called | POST /api/payments/retry | 0 calls |
Together with a check that the words "Order confirmed" are on the page, the test now proves both halves: what the customer saw, and what the server was told.
Every run also keeps the requests it made
Apart from the checks you add, each step of a run keeps the network calls it caused, so a failed run can be read without running it again: which request failed, with which status and which answer.
Sign-in headers, cookies and credential fields are removed before a log leaves the computer the test ran on.
What a network check does not do
- It looks at requests your page makes in the browser. It does not call your API by itself: it is not a tool for testing an API without a page.
- Network checks are made in Chromium. When a test runs in Firefox or WebKit, they are reported as not checked, never as passed.
- It does not change or fake an answer. The test sees what your server really sent.
Questions
Do I need to write code to check an API call?
No. You pick the request from the ones a step caused and choose what must be true about it. A field of a JSON answer is named by its path, such as $.order.total.
Can a test check that a request was not made?
Yes. "Never called" passes only when no matching request was made, for example no second payment.
Are network checks on the Free plan?
Yes. Page, network and design checks are included on every plan.
Is this the same as API testing?
Not quite. A network check looks at the requests your page makes while a person-like journey runs in a browser. It does not send requests to your API on its own.
Check what the server was told
Record a journey, pick the request behind its last click, and say what must be true. The recorder and the Free plan cost nothing.