Extensability- Extend Existing Elements- Child Elements

Learn how to extend BELLATRIX web elements using child elements.

Example

[TestClass]
[App(Constants.WpfAppPath, AppBehavior.RestartEveryTime)]
public class ExtendExistingElementWithChildElementsTests : DesktopTest
{
    [TestMethod]
    [App(Constants.WpfAppPath, AppBehavior.RestartOnFail)]
    [ScreenshotOnFail(false)]
    public void MessageChanged_When_ButtonClicked_Wpf()
    {
        var button = App.ElementCreateService.CreateByName<ExtendedButton>("E Button");

        button.SubmitButtonWithEnter();

        var label = App.ElementCreateService.CreateByName<Button>("ebuttonClicked");
        Assert.AreEqual("ebuttonClicked", label.InnerText);
    }
}

Explanations

public class ExtendedButton : Button
{
    public void SubmitButtonWithEnter()
    {
        var action = new Actions(WrappedDriver);
        action.MoveToElement(WrappedElement).SendKeys(Keys.Enter).Perform();
    }
}

The second way of extending an existing element is to create a child element. Inherit the element you want to extend. In this case, two methods are added to the standard Button element. Next in your tests, use the ** ** instead of regular Button to have access to these methods. The same strategy can be used to create a completely new element that BELLATRIX does not provide. You need to extend the ‘Element’ as a base class.

var button = App.ElementCreateService.CreateByName<ExtendedButton>("E Button");

Instead of the regular button, we create the ExtendedButton, this way we can use its new methods.

button.SubmitButtonWithEnter();

Use the new custom method provided by the ExtendedButton class.