AI engineering

A green Save test should mean the change survives

Use Playwright to check what the application retained and who was allowed to change it.

Published · AI disclosure

A customer changes an order’s delivery instructions and sees “Saved.” Before using that test to approve a release, the business needs to know that:

  • The intended order received the change
  • The value remains when the customer reopens the order
  • Another customer cannot make the same change
  • A rejected edit leaves the original instructions intact

These are separate claims. A useful test makes each one observable, so a passing result answers the question the release owner actually cares about.

Start with an order and a known owner

Choose one feature: editing delivery instructions before dispatch. Define who may edit the order, which fields may change, and what “saved” means. If fulfillment reads a separate system, its accepted update may also belong in the completion criteria.

Before each test, create or reset an isolated, editable order owned by the test account, with known starting instructions. Pass its identifier as ORDER_ID. Afterward, delete the disposable order or reset it using authorized test-environment cleanup, including after failures. Parallel tests need separate orders and appropriate account isolation. An arbitrary existing ORDER_ID is insufficient setup.

Use the real application backend for this check. A mocked save response can test the interface’s reaction, but it does not establish what the backend retained.

Follow the save beyond the success message

Playwright explicitly supports checking server-side results after browser actions. That lets the test combine the customer’s action with a separate read of the resulting order.

This TypeScript example checks browser/API agreement. Pair it with the storage check below before treating it as evidence of a committed write. It assumes cookie authentication, a string order identifier, configured baseURL, and authorized PATCH/GET endpoints. The example contract returns 204 after committing a PATCH; adapt it to the application.

TypeScript example
import { test, expect } from '@playwright/test';

test('delivery instructions survive saving', async ({ page }) => {
  const id = process.env.ORDER_ID!;
  expect(id).toBeTruthy();
  const path = `/api/orders/${encodeURIComponent(id)}`;
  const note = `Use side entrance ${Date.now()}`;

  await page.goto(`/orders/${encodeURIComponent(id)}`);
  await page.getByLabel('Delivery instructions').fill(note);

  const response = page.waitForResponse(r =>
    new URL(r.url()).pathname === path &&
    r.request().method() === 'PATCH');
  await page.getByRole('button', { name: 'Save', exact: true }).click();
  expect((await response).status()).toBe(204);

  const stored = await page.request.get(path, { maxRedirects: 0 });
  expect(stored.status()).toBe(200);
  expect(await stored.json()).toMatchObject({
    id, deliveryInstructions: note
  });

  await page.reload();
  await expect(page.getByLabel('Delivery instructions')).toHaveValue(note);
});

Registering the response wait before clicking avoids missing a fast response. The API read checks the identifier and new value, and reopening checks what the customer sees. page.request shares the browser context’s cookies, so this is the owner’s read rather than an administrator’s shortcut. Bearer-token applications need their own authenticated request setup.

A reload and GET can both return cached values. Add a companion integration test: perform the authorized edit against an isolated database using the actual provider; after the request completes, open a new database context or connection outside its transaction, query by order and owner identifiers, and assert the stored instructions. For an asynchronous save, wait for the agreed completion signal within a bounded time before reading. This storage check must be implemented in the target application.

Can someone else change the same order?

Hiding Save is useful interface behavior. The server still has to enforce ownership on a direct request; OWASP recommends permission checks on every request.

Add a separate scenario with a second authenticated customer who has no access to the owner’s order. First confirm that customer can edit their own order using the same endpoint and request setup. Then target the other customer’s order and require the application’s specified denial, such as 403 or a deliberate 404. Finally, read the protected order as its owner and check that its original instructions remain unchanged.

That positive control matters. An expired session, missing anti-forgery token, or malformed request could otherwise make the negative test pass without exercising the ownership rule. Disable automatic redirects where needed so a login page does not hide the actual response.

Repeat the unchanged-data check for a rejected business edit, such as an order already dispatched. A denial response alone does not demonstrate that no update occurred.

Make the release evidence specific

The example’s TypeScript and Playwright API usage were checked; it was not run against a live order application. Its route names, response contract, fixture, and storage check must be implemented and exercised in the target system.

For this feature, record the roles and order states tested, the independent storage results for accepted edits, and unchanged-data results for rejected edits. Use that evidence to approve the feature or identify the remaining release blocker.

Discuss a verification engagement

Sources

Written with AI and not reviewed by a human. It may contain mistakes.