Skip to main content
Hytale’s server-side UI system sends commands to the client to build and update pages. HRTK intercepts these commands during tests, letting you verify that your UI logic sends the correct instructions without needing a real client connection.

Core Concepts

  • UICommandCapture — records all UI commands (SET, APPEND, REMOVE) sent during a test
  • UIAssert — asserts on the captured commands
  • UITestAdapter — server-side adapter that creates captures from page builds

UICommandCapture Interface

MethodDescription
getCommands()Get all captured UI command records
hasCommand(path, operation)Check if a command was sent for the path with the operation
hasSet(path, value)Check if a SET command was sent with the given value
getCount()Total number of captured commands

UIAssert Methods

MethodDescription
assertCommandSent(capture, path, operation)Assert a command was sent for path + operation
assertCommandSentWithValue(capture, path, value)Assert a SET command with specific value
assertPageAppended(capture, pagePath)Assert an APPEND operation at the path
assertHasCommands(capture)Assert at least one command was captured
assertCommandCount(capture, expected)Assert exact number of captured commands

Building and Capturing UI Commands

Use UITestAdapter to trigger a page build and capture the resulting commands:
import com.frotty27.hrtk.api.assert_.UIAssert;
import com.frotty27.hrtk.api.mock.UICommandCapture;

@HytaleTest
void dashboardPageSendsCommands() {
    UICommandCapture capture = buildTestPage();
    UIAssert.assertHasCommands(capture);
}

Examples

@HytaleTest
void pageSetsPlayerName() {
    UICommandCapture capture = buildPlayerInfoPage("TestPlayer");

    UIAssert.assertCommandSent(capture, "player.name", "SET");
    UIAssert.assertCommandSentWithValue(capture, "player.name", "TestPlayer");
}
@HytaleTest
void pageAppendsInventorySection() {
    UICommandCapture capture = buildInventoryPage();

    UIAssert.assertPageAppended(capture, "inventory.items");
    UIAssert.assertCommandSent(capture, "inventory.header", "SET");
}
@HytaleTest
void emptyPageSendsNoCommands() {
    UICommandCapture capture = buildEmptyPage();
    UIAssert.assertCommandCount(capture, 0);
}
@HytaleTest
void uiAssertApiWorks() {
    // Create a minimal capture for unit testing UI logic
    UICommandCapture capture = createEmptyCapture();
    UIAssert.assertCommandCount(capture, 0);
    HytaleAssert.assertFalse(capture.hasCommand("any.path", "SET"));
}

UITestAdapter

The UITestAdapter on the server side bridges between your page-building code and the test capture system. It intercepts the PageManager command stream and records every command that would normally be sent to the client.
// Server-side usage (inside hrtk-server)
UITestAdapter adapter = new UITestAdapter();
UICommandCapture capture = adapter.buildPage(pageManager, playerRef, store, myPage);
In your test code, you typically do not interact with UITestAdapter directly. Instead, write helper methods in your test suite that invoke your page-building logic and return the captured commands.

Complete Example

@HytaleSuite("UI Tests")
@Tag("ui")
public class MyUITests {

    @HytaleTest
    @DisplayName("Settings page has all sections")
    void settingsPageStructure() {
        UICommandCapture capture = buildSettingsPage();

        UIAssert.assertHasCommands(capture);
        UIAssert.assertCommandSent(capture, "settings.graphics", "SET");
        UIAssert.assertCommandSent(capture, "settings.audio", "SET");
        UIAssert.assertCommandSent(capture, "settings.controls", "SET");
        UIAssert.assertPageAppended(capture, "settings.sections");
    }
}

Next Steps