About Article:
This article will describe the preference for choosing the selectors for element identification during test authoring in Virtuoso.
Problem Statement:
Virtuoso can utilise a variety of selectors, but is there a preferred type to use? Does Virtuoso prioritise certain selectors over others?
Solution:
Depending upon the use cases of automation, the method of identifying a control or an element may differ from case to case, however, generally the following element identification preference can be followed to author the tests in Virtuoso as per the best practices.
Element Identification Preference While Authoring:
- Hint Selectors:
- Visible Hints on Screen: Utilises text or elements that are visibly present on the screen to identify and interact with elements.
- Visible Hints with Relative Position and Element Type: Considers the position of an element relative to other elements and its type (e.g., button, link) for identification.
- Element Technical Details: Uses attributes such as ID, class name, inner text, name, value, and index of the element to identify it accurately.
- Explicit Selectors:
- XPath or CSS: Directly uses XPath or CSS selectors to pinpoint elements, providing precise and flexible ways to locate elements in the DOM (Document Object Model).
Elements and Self-Healing in Virtuoso
Virtuoso simplifies the challenging task of finding and targeting elements for end-to-end tests through two key features:
- Intelligent Element Selection: Use plain English hints to target elements without needing explicit selectors.
- Automatic Self-Healing: Virtuoso automatically maintains and updates selectors to ensure tests remain functional over time.
Self Healing Process:
- When adding a test step, such as "Click on 'Save'", Virtuoso creates a test step with a hint selector.
- During the first execution, Virtuoso infers specific identifiers (e.g., XPath, CSS) for stable element selection.
- If webpage elements change, Virtuoso automatically suggests and updates selectors to maintain accuracy and successfully steer the element even if some details associated with it have changed (for e.g. - dynamic ids within the xpath etc.).
Disabling self-healing:
Self-healing can be disabled using the “Lock explicit selectors” toggle button present in the Step Editor tab of the Step Details window.
Using Hints Only for element identification
- Purpose: Target a specific named element with precision.
- Method: Use only hint selectors and remove all explicit selectors.
- Test Step: The test step will try to find the element with the available hint and will fail if the target element is not found using the hint.
Using Hints and Explicit Selectors for element identification
- Purpose: Locate an element using a hint and a specific static selector.
- Method:
- Provide the hint and the static selector.
- Lock the explicit selectors to prevent other selectors from being added or existing selector to get self-healed.
- Test Step: The test step will look for both the hint and the specific selector, and it will pass if either of the elements is present. It will fail only if the element is not found using hint or the selectors defined.
Note: Self-healing should be used when the details associated with an element are bound to get updated in subsequent executions, while locked explicit selectors are best for targeting specific elements assuming there won’t be any changes with the selectors.
References:
Refer this to get a detailed understanding of element identification in Virtuoso
Comments
0 comments
Please sign in to leave a comment.