Best Practices
These practices are inspired by Playwright's design philosophy and adapted for Unreal Engine game development. Follow these principles to keep your test suite fast, scalable, and resilient to engine changes.
1Use Auto-Retrying Assertions (No Sleeps)
Games are inherently asynchronous. Animations take time to finish blending, latent physics forces take time to resolve, and RPCs take time to arrive from the server.
const text = await modal.getChild('TitleText').getText();
expect(text).toBe('Are you sure?');
- No Retries: Fetches the value once at the exact millisecond. Flakily fails if UMG animations or network packets take 50ms to process.
- No Reporting Context: HTML reports just show
expect(received).toBe(expected)with no idea which widget or property failed.
await expect(modal.getChild('TitleText'))
.toHaveText('Are you sure?');
- Auto-Retrying: Listens for state updates and resolves the moment the condition is met without manual delays.
- Rich Matchers: Supports
toHaveText,toContainText,toHaveValue,toBeVisible, andtoBeEnabled. - HTML Report Steps: Clear breadcrumbs in trace reports.
2Use the Game Object Model (GOM)
Web developers use the Page Object Model (POM); game developers use the Game Object Model. Do not leak raw Blueprint string paths or widget hierarchy names directly into your test files. Encapsulate them inside specialized TypeScript classes.
If a Blueprint path changes or an ability tag is renamed, you only have to update it in one place. See our Game Object Model Guide.
3Use Fixtures for Test Isolation
Tests should never depend on each other. When a test fails, it should be able to run individually and produce the exact same failure.
Use Playwright's test.extend() to create isolated environments for each test. Specter handles connecting to the engine, spinning up the map, spawning actors, and cleaning them up before the next test runs: the actors a test spawned, and the ones the game spawned while it ran.
The rest of the game's state is yours to reset, because only your game knows where it starts. Tests share one running game, so a test that moves the camera, leaves a menu open or pauses the game changes what the next test sees. A test that later fails for no reason of its own is the usual sign. Put the game back in a resetGame fixture. Projects made with npm init @specter-automation start with one in fixtures/index.ts, ready to fill in:
// specter/fixtures/index.ts
export const test = base.extend<{ resetGame: void }>({
// Runs around every test on its own ({ auto: true }), after the test's afterEach hooks
resetGame: [async ({ world }, use) => {
await use();
await world.getByWidget("WBP_HUD").callFunction("CloseAllMenus");
await world.actor("BP_CameraRig").setLocation({ x: 0, y: 0, z: 1200 });
await world.console("pause 0");
}, { auto: true }],
});Specter tells you when a reset is missing. It notes the player's pawn and camera, the view target, the Widget Blueprints on screen, pause and time dilation when each test starts, and compares them when the test ends:
[SPECTER] This test left the game changed for the next test:
- The player's camera was left 840 cm from where it started (0, 0, 1200 -> 840, 0, 1200).
- Left showing (not showing when it started): WBP_PlacementBar.
Specter can't reset game state (only the game knows its start). Reset it in your fixture or afterEach if later tests depend on it.The warning shows in the test that left the change. If a later test fails, its failure report says what the previous test left changed, so the cause is on the same screen.
4Test the Game, Not the Implementation
Tests should verify player-visible outcomes, not internal variables. If you test internal implementation details, your tests will break every time a designer refactors a Blueprint.
- Bad: Checking if
bIsStunned == trueon the Character Movement Component. - Good: Checking if the character possesses the
Status.StunnedGameplay Tag, and asserting that their location hasn't changed.
5Locators, Not Coordinates
Never interact with a UI widget by clicking an absolute screen coordinate (X/Y). Screen resolutions, aspect ratios, and safe zones will immediately break these tests.
Instead, use world.widget('WidgetName') to locate the specific UI element in the UMG hierarchy, and let Specter calculate the dynamic bounding box at runtime.