Extensability- Extend Existing Elements- Child Elements

Learn how to extend BELLATRIX iOS elements using child elements.

Example

[TestFixture]
public class ExtendExistingElementWithChildElementsTests : IOSTest
{
    [Test]
    public void ButtonClicked_When_CallClickMethod()
    {
        var button = App.Components.CreateByName<ExtendedButton>("ComputeSumButton");

        button.SubmitButtonWithScroll();
    }
}

Explanations

public class ExtendedButton : Button
{
    public void SubmitButtonWithScroll()
    {
         this.ToExists().ToBeClickable().WaitToBe();
         ScrollToVisible(ScrollDirection.Down);
         Click();
    }
}

The second way of extending an existing element is to create a child component. Inherit the element you want to extend. In this case, a new method is added to the standard Button component. Next in your tests, use the ExtendedButton instead of regular Button to have access to this method. 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.Components.CreateByName<ExtendedButton>("ComputeSumButton");

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

button.SubmitButtonWithScroll();

Use the new custom method provided by the ExtendedButton class.