AI AGENT · NEW

Add a custom component

When a BELLATRIX component does not fit a control, your agent adds a custom one in your project. The framework itself stays unchanged.

When you need one

Most controls map to a built-in BELLATRIX component such as Button or ComboBox. Some controls behave differently. For example, the items of a WinUI dropdown appear at the root of the window, not under the dropdown. A custom component wraps that behaviour once, so every test can use it.

The agent often finds such a gap itself while it runs a test case. You can also ask for a component directly.

What to say to your agent

  • The unit dropdowns are WinUI ComboBoxes. Add a custom BELLATRIX component for them and use it in UnitConverterWindow.
  • Create a custom component for this date picker.
  • Why did you add WinUiComboBox?

What you will see

  1. The agent explains the gap: what the built-in component does and why it fails here.
  2. It adds a class that inherits from the closest BELLATRIX component and overrides only what differs.
  3. It switches the page object's map to the new component.
  4. It builds the project.

Where the files end up

The component goes to Components/ in your test project. The page object's map uses it like any other component:

public class WinUiComboBox : ComboBox
{
    public override void SelectByText(string value)
    {
        // Click the ComboBox to expand the dropdown flyout
        WrappedElement.Click();

        // Find the list item from the root of the window (WinUI3 popup items may
        // appear at the root level of the accessibility tree, not as element children)
        new App().Components.CreateByXPath<Button>($"//ListItem[@Name='{value}']").Click();
    }
}
Example code from the BELLATRIX demo project: Components/WinUiComboBox.cs (shortened).
public WinUiComboBox InputUnitComboBox =>
    App.Components.CreateByAutomationId<WinUiComboBox>("Units1");
The same demo project: the window map uses the custom component.
Under the hood
  • The components skill shows the agent how to inherit from a BELLATRIX component and create child elements through the component factories, never through raw driver calls.
  • The gap shows up while the agent runs the steps live through the CLI, before it writes any code.
  • More: How the agent works.