Documentation
Overview
Thanks to the flexible system, every element in a document can be checked for existence. There are several ways to select an element, since not all selectors are equally easy to use.
- Text selectors are the easiest to use selectors. They are used to define text that must appear on a web page. The text must appear exactly as described. A text selector is suitable for all types of documents.
- CSS selectors or CSS paths are best suited for selecting elements that are in the visible area of HTML documents. In most cases, these are determined by certain classes or IDs.
- XPath selectors are among the more complex selectors, but they gain more flexibility. XPath selectors can be used to name individual elements or just attributes in great detail, which then need to be checked. In contrast to CSS selectors, XPath can also be used to address elements that are located, for example, in the <head> of an HTML document.
- Regular expressions are the supreme discipline among selectors. They can be used to search for anything you want. The high flexibility, however, is paid for by increased complexity. If you decide to use regular expressions, you should familiarize yourself with the website regex101.
Leankoala distinguishes between two sources on which the checks can be performed. On the one hand, the HTML document can be used as the basis. This source contains the HTML that is delivered directly from the server and has not yet been processed by the browser. This source is very stable and causes hardly any false positives. If a page is barely modified by JavaScript, it is recommended to select the HTML content.
The second option is to select the DOM document as the source. This includes the HTML as rendered by the browser. This is necessary to test JavaScript applications like vue, angular or react, which display all information only in the browser.
Editorially maintained websites can be challenging if they are very advertising intensive. Advertising is often not neatly programmed and leads to syntactically incorrect HTML code. In this case, all checks that can be covered by HTML as a source should use this. The others where it is important to check the DOM should use it. This should not be many.
- exists - checks whether an element occurs at least once in the document.
- contains - checks if an element exists and if the content contains a certain text. Only the first element found is checked.
- equals - the selected element must correspond to the exact text. Only the first element found is checked.
- occurs at most - the specified selector must occur at least X times in the document.
- occurs at least - the selected selector must not occur more than X times in the document.
Sometimes it is not easy creating stable selectors that are still valid after the next deployment or code change. There are some tricks and helpers for doing it.