This topic explains how the CreateXPath hook allows you to create custom locators that can be used to identify elements when recording web scenarios tests. These custom locators can then be used for validations and extractions.
Customized hooks can be used to record or modify the values passed at specific points during execution.
Hooks are defined and customized in scripts using custom methods. The same file can define multiple hooks. If you add more than one method to a hook, all methods defined for that hook will be executed when the hook is called.
version>/root/startup directory; then, any time the program calls the hook, the associated user-defined methods will be executed. The methods will be executed until you call clear () on the hook.
About the CreateXPath Hook
When recording web scenarios, SOAtest identifies the elements that you interacts with by certain attributes of those elements. For example, SOAtest will use the ID of an element, or the text content of an element to locate that element. If you need to extend the attributes used to identify elements during functional testing, you can use the CreateXPath hook.
The CreateXPath hook takes two arguments. The first is an instance of org.w3c.dom. Node, and is the node that the locator will be built for. The second is an instance of org.w3c.dom.Document, and is the document where the node was found. The CreateXPath function should return an XPath that identifies the node in the document, or null if no XPath can be created.
For example, if you want to identify elements by their "class" attribute, you could use the CreateXPath hook to create a custom identifier that checks elements for a "class" attribute and, if it finds one, returns an XPath that identifies the element by the value of the "class" attribute.
When selecting an element to validate, or clicking an element during recording, SOAtest would then use this custom hook. The element would be passed to the custom hook, which would then check the element for a "class" attribute. If it found one, it would return an XPath using the "class" attribute value to identify the element.
Here is a sample script that identifies elements using the "class" attribute and an index (when more than one node has the same "class").