public sealed class UiTestAn interface under test: a document, a clock, a pointer, and the frames between them.
No guide page documents this yet — the page shows what the code says about itself.
Remarks
The whole of the harness. It owns a real UiDocument — not a stub, not a recording of one — so a test drives the same cascade, the same flexbox, the same event routing and the same draw list the game does. What it adds is the three things a test has that an application does not: a clock it controls, an input source it can speak into, and a loop it can step.
⚠ Commands run eagerly, unlike Cypress's. Cypress enqueues and returns a chainable promise because it is JavaScript and the browser is somebody else's loop; translating that faithfully into C# would buy a debugger that never stops on the line that failed. Here Get(".save").Click() has clicked by the time it returns, and each command does its own waiting inside itself. The chaining reads the same and the stack traces are real.
using var ui = UiTest.Create(800, 600); ui.Load(".btn { width: 120px; height: 40px; }"); var button = ui.Create("button", ui.Document.Root, "save", "btn"); button.Text = "Save"; ui.Get("#save").ShouldBeVisible().ShouldHaveText("Save").Click(); ui.Get(".toast").ShouldExist(); // runs frames until it appears ui.Screenshot("save-pressed");
Fields and properties (10)
public UiDocument DocumentThe interface being tested.
public UiTestOptions OptionsHow long commands wait and where pictures live.
public CommandLog LogEverything this test has done.
public TimeSpan NowWhat time it is, on the clock the document's gestures read.
public int FrameCountHow many frames have run.
public Vector2 PointerWhere the first pointer is.
public ModifierKeys ModifiersWhich modifiers a test has said are held.
public UiSubject RootEverything in the document, as a subject to chain from.
public const int PointerIdThe pointer a single-pointer command uses.
public const int SecondPointerIdThe pointer a two-finger gesture uses for its second finger.
Events (2)
public Action? TickedRuns once per frame, before the passes.
public Action? UpdatedRuns once per frame, after the passes and before the draw.
Methods (30)
public static UiTest Create(float width = 1280, float height = 720, UiTestOptions? options = null)Opens an interface of the given size.
public static UiTest Adopt(UiDocument document, UiTestOptions? options = null)Drives an interface somebody else built.
public int Load(string css)Adds a stylesheet.
public UiElement Create(string tag, UiElement? parent = null, string? id = null, params string[] classNames)Creates an element.
public void Frame()Runs one frame: the clock moves, gestures tick, the passes run, the interface draws.
public void Frames(int count)Runs several frames.
public void Advance(TimeSpan duration)Runs frames until at least this much time has passed.
public UiTest Hold(ModifierKeys modifiers)Holds modifiers down for the commands that follow.
public UiSubject Get(string selector)Everything matching a CSS selector.
public UiSubject Contains(string text)Everything whose text contains this.
public UiSubject At(float x, float y)Whatever is under a point, if anything.
public UiElement? MovePointer(float x, float y, int pointer = 1)Moves a pointer, without pressing anything.
public UiElement? PressPointer(PointerButton button = Primary, int pointer = 1)Presses a pointer button where that pointer is.
public UiElement? ReleasePointer(PointerButton button = Primary, int pointer = 1)Releases a pointer button where that pointer is.
public Vector2 PointerAt(int pointer)Where a pointer is.
public UiElement? Drag(float fromX, float fromY, float toX, float toY, int steps = 8)Drags from one point to another, in steps.
public UiElement? Wheel(float deltaX, float deltaY)Turns a wheel where the pointer is.
public UiElement? PressKey(InputKey key)Presses and releases a key, with whatever Hold is holding.
public UiElement? KeyDown(InputKey key, bool isRepeat = false)Puts a key down.
public UiElement? KeyUp(InputKey key)Lets a key up.
public UiElement? TypeText(string text)Sends typed text to whatever has the focus.
public bool Tab(bool backwards = false)Moves the focus the way Tab does.
public Bitmap Capture()Draws the interface as it stands, on the CPU.
public void Screenshot(string name, ImageTolerance? tolerance = null)Checks the interface against a committed picture, or records it as the new one.
public string? StyleOf(UiElement element, string property)What the cascade resolved a property to on an element, as text.
public Color4? ColorOf(UiElement element, string property)The colour the cascade resolved a property to, if it resolved one.
public float? LengthOf(UiElement element, string property)The absolute length the cascade resolved a property to, if it resolved one.
public float? NumberOf(UiElement element, string property)The bare number the cascade resolved a property to, if it resolved one.
public string Tree()The interface written out, one element per line.
public void Dispose()Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Used by (46, showing 40)
- ControlHarnessVixen.Ui.Controls.Tests
- ControlVisualTestsVixen.Ui.Controls.Tests
- DisabledStateTestsVixen.Ui.Controls.Tests
- IconArtTestsVixen.Ui.Controls.Tests
- InteractionTestsVixen.Ui.Testing.Tests
- NavigationInteractionTestsVixen.Ui.Controls.Tests
- OverlayInteractionTestsVixen.Ui.Controls.Tests
- QueryTestsVixen.Ui.Testing.Tests
- RangeInteractionTestsVixen.Ui.Controls.Tests
- RasterizerTestsVixen.Ui.Testing.Tests
- RetryTestsVixen.Ui.Testing.Tests
- ScreenshotTestsVixen.Ui.Testing.Tests
- SelectorQueryVixen.Ui.Testing
- ToggleInteractionTestsVixen.Ui.Controls.Tests
- TransformTestsVixen.Ui.Testing.Tests
- UiSubjectVixen.Ui.Testing
- VisibilityTestsVixen.Ui.Testing.Tests
- VisualBaselineVixen.Ui.Testing
- AudioMixerViewTestsVixen.Editor.AssetEditors.Tests
- ChromeFixtureVixen.Editor.Ui.Tests
- CompiledSceneTestsVixen.Editor.AssetEditors.Tests
- DeclaredContributionTestsVixen.Editor.App.Tests
- DropIntoFieldTestsVixen.Editor.App.Tests
- DropIntoSceneTestsVixen.Editor.App.Tests
- EditorAffordanceTestsVixen.Editor.App.Tests
- EditorChromeVisualTestsVixen.Editor.Ui.Tests
- EditorScriptWorkflowTestsVixen.Editor.App.Tests
- EditorSessionVixen.Editor.Testing
- EditorViewTestsVixen.Editor.AssetEditors.Tests
- FlameChartViewTestsVixen.Editor.Profiler.Tests
- GridViewTestsVixen.Editor.App.Tests
- HarnessViewTestsVixen.Editor.AssetEditors.Tests
- ImportViewTestsVixen.Editor.AssetEditors.Tests
- InspectorFixtureVixen.Editor.Inspector.Tests
- MilestoneE5TestsVixen.Editor.App.Tests
- MoveSetTestsVixen.Editor.AssetEditors.Tests
- OutOfTreePluginTestsVixen.Editor.App.Tests
- ProxyShapeEditorTestsVixen.Editor.AssetEditors.Tests
- ScenarioTestsVixen.Editor.App.Tests
- SceneMenuTestsVixen.Editor.App.Tests