Skip to content

@gtkx/testing / screen

Variable: screen

const screen: object

Defined in: screen.ts:65

Global query object for accessing rendered components.

Provides the same query methods as render result, but automatically uses the most recently rendered application as the container.

Type Declaration

NameTypeDescriptionDefined in
debug()() => voidPrint the widget tree to console for debuggingscreen.ts:68
findAllByLabelText()(text, options?) => Promise<Widget[]>Find all elements by label/text content (waits and throws if none found)types.ts:142
findAllByName()(name, options?) => Promise<Widget[]>Find all elements by widget name (waits and throws if none found)types.ts:146
findAllByRole()(role, options?) => Promise<Widget[]>Find all elements by accessible role (waits and throws if none found)types.ts:140
findAllByText()(text, options?) => Promise<Widget[]>Find all elements by visible text (waits and throws if none found)types.ts:144
findByLabelText()(text, options?) => Promise<Widget>Find single element by label/text content (waits and throws if not found)types.ts:134
findByName()(name, options?) => Promise<Widget>Find single element by widget name (waits and throws if not found)types.ts:138
findByRole()(role, options?) => Promise<Widget>Find single element by accessible role (waits and throws if not found)types.ts:132
findByText()(text, options?) => Promise<Widget>Find single element by visible text (waits and throws if not found)types.ts:136
logRoles()() => voidLog all accessible roles to console for debuggingscreen.ts:72
queryAllByLabelText()(text, options?) => Widget[]Query all elements by label/text content (returns empty array if none found)types.ts:126
queryAllByName()(name, options?) => Widget[]Query all elements by widget name (returns empty array if none found)types.ts:130
queryAllByRole()(role, options?) => Widget[]Query all elements by accessible role (returns empty array if none found)types.ts:124
queryAllByText()(text, options?) => Widget[]Query all elements by visible text (returns empty array if none found)types.ts:128
queryByLabelText()(text, options?) => Widget | nullQuery single element by label/text content (returns null if not found)types.ts:118
queryByName()(name, options?) => Widget | nullQuery single element by widget name (returns null if not found)types.ts:122
queryByRole()(role, options?) => Widget | nullQuery single element by accessible role (returns null if not found)types.ts:116
queryByText()(text, options?) => Widget | nullQuery single element by visible text (returns null if not found)types.ts:120
screenshot()(selector?, options?) => Promise<ScreenshotResult>Capture a screenshot of the application window, saving it to a temporary file and logging the file path. Throws Error if no windows are available or no matching window is found Example await screen.screenshot(); // First window await screen.screenshot(0); // Window at index 0 await screen.screenshot("Settings"); // Window with title containing "Settings" await screen.screenshot(/^My App/); // Window with title matching regexscreen.ts:92

Example

tsx
import { render, screen } from "@gtkx/testing";

test("finds button", async () => {
  await render(<MyComponent />);
  const button = await screen.findByRole(Gtk.AccessibleRole.BUTTON);
  expect(button).toBeDefined();
});

See