Customizing the XPath Provider
XPath is a query language that is used to find and select XML nodes. In a Web page, XPath can be used to find and identify HTML elements.
During an automated test, the Possum Labs framework searches for elements on Web pages that match the elements defined in the test steps. The XPath provider lists which types of elements the framework should look for, categorized by function. These categories include content elements, clickable elements, settable elements, and more. The full list can be found in XpathProvider.cs
in the PossumLabs.DSL.Web > Selectors
folder.
If your tests need to follow a style guide, or if you are using different HTML tags than those defined in the framework, you can create a custom XPath provider to add and remove HTML element types within each category. You can also change how content is matched and replace or trim non-breaking white spaces.
Open the example project
- Open the
Tutorials > Advanced
folder in the Possum Labs DSL project and expand the project called1 Customizing the XpathProvider
.
Create and Register the Custom XPath Provider
- Open the file in the project called
CustomXpathProvider.cs
. This file defines a new XpathProvider called CustomXpathProvider. - Expand the
English
folder and openFrameworkInitializationSteps.cs
. - Find the line in the file that reads
Register<XpathProvider>(new CustomXpathProvider());
. This line registers the CustomXpathProvider that is defined inCustomXpathProvider.cs
. There can only be one XPath provider, so all overrides must go in a single file.
Create XPath Overrides
- Return to
CustomXpathProvider.cs
. - Several example overrides have been included to show syntax. To override an element category, copy in the corresponding statement from
XpathProvider.cs
(found in thePossumLabs.DSL.Web > Selectors
). Add or remove element types as needed, and leave the rest of the list as part of the override. The lists are not prioritized, so you can add element types in any order.
XPath Tutorials
The W3C maintains the XPath standards. If you would like to learn more about XPath syntax, there is an XPath tutorial available as a part of W3schools.