Validate Assertions
Learn how to use BELLATRIX Validate assertion methods.
Example
[Test]
public void CommonAssertionsAndroidControls()
{
var button = App.Components.CreateByIdContaining<Button>("button");
button.ValidateIsNotDisabled();
var checkBox = App.Components.CreateByIdContaining<CheckBox>("check1");
checkBox.Check();
checkBox.ValidateIsChecked();
var comboBox = App.Components.CreateByIdContaining<ComboBox>("spinner1");
comboBox.SelectByText("Jupiter");
comboBox.ValidateTextIs("Jupiter");
var label = App.Components.CreateByText<Label>("textColorPrimary");
label.ValidateIsVisible();
var radioButton = App.Components.CreateByIdContaining<RadioButton>("radio2");
radioButton.Click();
radioButton.ValidateIsChecked(timeout: 30, sleepInterval: 2);
Bellatrix.Assertions.Assert.Multiple(
() => label.ValidateIsVisible(),
() => Assert.IsTrue(label.IsPresent),
() => comboBox.ValidateTextIs("Jupiter"));
}
Explanations
button.ValidateIsNotDisabled();
//Assert.AreEqual(false, button.IsDisabled);
We can assert whether the control is disabled. The different BELLATRIX Android elements classes contain lots of these properties which are a representation of the most important app element attributes. The biggest drawback of using vanilla assertions is that the messages displayed on failure are not meaningful at all. If the bellow assertion fails the following message is displayed: “*Message: Assert.AreEqual failed. Expected:
var checkBox = App.Components.CreateByIdContaining<CheckBox>("check1");
checkBox.ValidateIsChecked();
Here we assert that the checkbox is checked. On fail the following message is displayed: “Message: Assert.IsTrue failed.” Cannot learn much about what happened. Now if we use the ValidateIsChecked method and the assertion does not succeed the following error message is displayed: “The control should be checked but was NOT.”
var comboBox = App.Components.CreateByIdContaining<ComboBox>("spinner1");
comboBox.ValidateTextIs("Jupiter");
Assert that the proper item is selected from the combobox items.
var label = App.Components.CreateByText<Label>("textColorPrimary");
label.ValidateIsVisible();
See if the element is present or not using the IsPresent property.
var radioButton = App.Components.CreateByIdContaining<RadioButton>("radio2");
radioButton.ValidateIsChecked(timeout: 30, sleepInterval: 2);
By default, all Validate methods have 5 seconds timeout. However, you can specify a custom timeout and sleep interval (period for checking again).
Bellatrix.Assertions.Assert.Multiple(
() => label.ValidateIsVisible(),
() => Assert.IsTrue(label.IsPresent),
() => comboBox.ValidateTextIs("Jupiter"));
You can execute multiple validate assertions failing only once viewing all results.
Bellatrix provides you with a full BDD logging support for Validate assertions and gives you a way to hook your logic in multiple places.