Writing Your First Test

In this guide, we'll write a simple test for the standard Unreal Engine 5 Third Person Template. We'll connect to the game, make the mannequin jump, and verify that the jump actually worked.

The Test Script

Create a new file named first.spec.tsin your project. If you've ever used Playwright for web testing, this syntax will look immediately familiar:

import { test, expect } from '@specter-automation/test';

test('Mannequin can jump', async ({ world }) => {
  // 1. Query the player's character using its Blueprint class name
  const player = world.actor('BP_ThirdPersonCharacter');

  // 2. Tap the SpaceBar: press it, hold it for a few frames, release it
  await player.tapKey('SpaceBar');

  // 3. Assert that the character left the ground, then landed again
  await expect(player).toBeFalling();
  await expect(player).not.toBeFalling();
});

Step-by-Step Breakdown

1. The Actor Locator

Notice how we didn't have to manually connect to Unreal Engine? Specter's test runner automatically handles WebSocket connections, waits for the map to load, and injects the active world instance as a fixture into your test! The world.actor() method is Specter's equivalent of Playwright's page.locator().

2 & 3. Action & Assertion

We simulate a real keystroke using player.tapKey('SpaceBar'), which goes through the player's Enhanced Input like a physical keyboard would. Since Specter understands Unreal Engine's internal states, we can directly assert the outcome using expect(player).toBeFalling(), then .not.toBeFalling() to confirm the landing, without writing brittle timeout loops or querying the character movement component manually. Both assertions retry until they pass or time out.

Why tapKey and not pressKey? pressKey only presses the key, and it stays held until you release it. The template binds Jump to the input's Started event, which fires when a key goes from up to down, so a key that's still held can't jump again. tapKey presses, holds for a few frames and releases, like a real tap. Use pressKey when you want to hold a key (sprinting, charging an attack) and release it yourself with pressKey(key, 'Released'). Specter releases any key a test leaves held when the test ends.

Automated Failure Screenshots

If a test fails or times out in your pipeline, Specter's built-in autoScreenshot fixture automatically captures a high-resolution PNG of the active Unreal Engine viewport and attaches it directly to your Playwright HTML Report under "Unreal Engine Viewport".