🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 4 Min Lesezeit
0

APIRequestContext Fundamentals (Playwright + TypeScript, Ch.11)

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

Welcome to Part 3 — API Testing. Until now the API was our setup helper. Now

we test it as a first-class surface. API tests need no browser, so they run in

milliseconds — and Inkwell speaks the documented — see

src/tests/api/articles.spec.ts and src/setup/global-setup.ts.






First, make the data deterministic



Read assertions are only stable if the data is. In Part 1 individual tests reset the

database, which raced each other. The clean fix for a read-heavy API suite is to

seed once, before everything, and never reset mid-run:




CODE
// src/setup/global-setup.ts
import { request } from "@playwright/test";
import { env } from "../utils/env";

export default async function globalSetup(): Promise<void> {
const ctx = await request.newContext({ baseURL: `${env.apiURL}/` });
try {
const res = await ctx.post("test/reset");
if (!res.ok()) throw new Error(`reset failed: HTTP ${res.status()}`);
} finally {
await ctx.dispose();
}
}









CODE
// playwright.config.ts
export default defineConfig({
globalSetup: "./src/setup/global-setup.ts",
// ...
});






globalSetup runs once before any worker starts. Now every test reads a known

baseline, and because nothing resets during the run, read tests can't wipe each

other. (Tests that create data make their own and clean up — Chapter 13.)





The api fixture is your client



We already have a worker-scoped api fixture — an APIRequestContext pointed at

the API. Its methods mirror HTTP: get, post, put, delete. Each returns an

APIResponse you assert on.




CODE
test("GET /articles lists the seeded article", async ({ api }) => {
const res = await api.get("articles");

expect(res.status()).toBe(200);
expect(res.headers()["content-type"]).toContain("application/json");

const body = await res.json();
expect(typeof body.articlesCount).toBe("number");
expect(Array.isArray(body.articles)).toBe(true);

const slugs = body.articles.map((a: { slug: string }) => a.slug);
expect(slugs).toContain("welcome-to-inkwell");
});






Three things to internalize:





  • res.status() vs res.ok(). ok() is true for any 2xx — fine for a happy
    path. For anything where the exact code matters (especially errors), assert
    status().


  • res.json() is awaited and returns the parsed body. res.text() and
    res.body() are there when you need raw payloads.


  • res.headers() is a plain lowercase-keyed object — handy for asserting
    content type, caching, or auth headers.






Query parameters



Don't hand-build query strings — pass params and Playwright encodes them:




CODE
test("GET /articles respects the limit query param", async ({ api }) => {
const res = await api.get("articles", { params: { limit: 1 } });
expect(res.ok()).toBeTruthy();

const body = await res.json();
expect(body.articles.length).toBeLessThanOrEqual(1);
});






The RealWorld list endpoint also takes offset, tag, author, and favorited

same mechanism for each.





Assert on errors, not just happy paths



A suite that only checks 200s misses half the contract. Inkwell returns a structured

404 for a missing article, and we assert both the status and the body shape:




CODE
test("GET /articles/:slug returns 404 for an unknown slug", async ({ api }) => {
const res = await api.get("articles/does-not-exist-xyz");

expect(res.status()).toBe(404);
const body = await res.json();
expect(body.errors.body[0]).toContain("not found");
});






Knowing the shape of an error ({ errors: { body: [...] } } here) is part of

testing an API contract — clients depend on it.






Why this is already clean



Notice what these tests don't do: no ${baseURL} plumbing (the api fixture owns

it), no manual context lifecycle (worker-scoped, Chapter 10), no data setup (global

seed). The fixture architecture from Part 2 pays off immediately — API specs are

almost pure assertions.






Next up



Reads are easy because they need no identity. Chapter 12 — Auth & sessions for the

API layer:
log in once, get a token, and build an authedApi fixture (a chained

fixture, as promised in Chapter 9) so authenticated calls are as effortless as

anonymous ones. Tag: ch-12.




Following along? Star the repo

and tell me: do your API suites assert error responses, or only happy paths?


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten APIRequestContext Fundamentals (Playwright + TypeScript, Ch.11)

Thematisch verwandte Begriffe: APIRequestContext, Fundamentals, Playwright, TypeScript · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...