Skip to content

ui::testing::TestAutomationEvents

Header: winui/testing/TestAutomationEvents.hpp.

Derives from ui::AutomationEvents.

AutomationEvents test double: keeps a line of text for every event a window reports, the way a screen reader would hear about it. Structure changes go to structure instead, as they come with many changes and say little on their own.

Install it with seams(window).set_automation_events(); the window then reports to it after each layout. Set listening_now to false to act as if no screen reader is listening, and the window reports nothing.

Example:

ui::testing::TestAutomationEvents events;
ui::testing::seams(window).set_automation_events(&events);
ui::testing::seams(window).handle_key({ui::Key::Tab, ui::KeyAction::Down});
REQUIRE(events.log == std::vector<std::string>{"focus Button \"Save\""});

listening_now

bool listening_now = true

Whether the window should report; true by default.

log

std::vector<std::string> log

One line per event: focus <role> "<name>", or <property> "<name>": <before> -> <after>.

focused

std::vector<Element*> focused

The node of each focus event, in order.

structure

std::vector<Element*> structure

The node of each structure change, in order.

listening

bool listening() const override

Whether a client is listening; while false the window skips the checks.

focus_changed

void focus_changed(Element& node) override

node took keyboard focus as automation sees it.

property_changed

void property_changed(Element& node, AutomationProperty property, const AutomationValue& before, const AutomationValue& after) override

property of node, the node with automation focus, went from before to after.

void menu_opened(Element& menu) override

A menu (a node with AutomationRole::Menu) opened.

void menu_closed(Element& menu) override

A menu closed.

structure_changed

void structure_changed(Element& node) override

node's automation children changed: one came, went or was renamed.