HTML Asserts
Telerik Testing Framework has a set of Assert classes to make validation of your HTML controls easier. An 'Assert' basically says "Verify the specified property of the control has the specified value or setting. If it doesn't have that setting/value, then throw an error and stop the test."
For example: AssertCheck.IsTrue() will verify the associated checkbox control is checked. If it isn't the framework will throw an assert exception and stop the test. If it is the test will simply continue to the next step. Nothing else happens for Asserts that pass validation.
Assert Class | Class Description | Assert method | Method Description |
---|---|---|---|
AssertAttribute | Validates the properties of an attribute. | Value | Checks the string value of the specified attribute. Asserts if the expected value was not found. |
Exists | Asserts if the specified attribute does not exist for this element. | ||
AssertCheck | Validates the checked state of check boxes and radio buttons. | IsFalse | Asserts if the control is checked. |
IsTrue | Asserts if the control is not checked. | ||
AssertContent | Validates the content of an HtmlControl. | InnerMarkup | Asserts if the inner HTML of the control does not match. |
InnerText | Asserts if the inner text of the control does not match. | ||
OuterMarkup | Asserts if the outer HTML of the control does not match. | ||
StartTagContent | Asserts if the value of the tag for this HTML control does not match. | ||
TextContent | Asserts if the text content of the HTML control does not match. | ||
AssertSelect | Validates the various properties of an HtmlSelect. | ItemsCountIs | Asserts if the total number of items in the list does not match the expected value. |
SelectedIndex | Asserts if the index value of the currently selected item does not match the expected value. | ||
SelectedText | Asserts if the text of the currently selected item does not match the expected value. | ||
SelectedValue | Asserts if the value of the currently selected item does not match the expected value. | ||
TextExists | Asserts if the expected value was not found in the list of text's to display for this control. | ||
TextExistsNot | Asserts if the expected value not found in the list of text's to display for this control. | ||
ValueExists | Asserts if the expected value was not found in the list of values for the items in this control. | ||
ValueExistsNot | Asserts if the expected value not found in the list of values for the items in this control. | ||
AssertStyle | Validates the various common styles of an HtmlControl. | Box | Asserts if a particular box style does not match (e.g. margin, border, padding). |
ColorAndBackground | Asserts if a particular color or background style does not match (e.g. background color, background image, etc.) NOTE: AssertStyle.ColorAndBackground() automatically detects colors and will perform the proper validation regardless of the format of the color encoding attached to the style e.g. "red" will match "#FF0000". | ||
Display | Asserts if a particular display style does not match (e.g. width, height, display, position, etc.) | ||
Font | Asserts if a particular font style does not match (e.g. family, variant, size, etc.) | ||
List | Asserts if a particular list style does not match (e.g. type, image, position, etc.) | ||
Text | Asserts if a particular text style does not match (e.g. word spacing, letter spacing, text align, etc.) | ||
AssertTable | Validates the common properties of an HtmlTable control. | ColumnCount | Asserts if the number of columns does not match the expected value. |
ColumnRange | Asserts if the number of columns is not inside or not outside of the specified range. | ||
Contains | Asserts if the table contains/does not contain the expected value. | ||
RowCount | Asserts if the number of rows does not match the expected value. | ||
RowRange | Asserts if the number of rows is not inside or not outside of the specified range. |
Now let's see how this works in action:
There are many other possible assert verification combinations built into the framework that you can take advantage of. The above examples are just a small subset of what is possible to help you get started implementing them in your code and crafting the kinds of verification you need for your particular website. Consult the API reference manual to learn about the other combinations.