Locators - TestlumFramework/Testlum GitHub Wiki
Before describing the Web related commands, it is necessary to know how to create a
locatorand connect it to ascenario.
Available types of locators in Testlum
idclassxpathcssSelectortext
Testlum supports using locators by two different ways
- By using
locatorattribute in needed web commandfrom special separate filesin special folders with names that can be used in different scenarios without duplicating the entire locator.- Directly in the field for the locator - the locator is entered in the field in its entirety each time.
Locators from files
To create locators for the locator field you need:
Create a file in the
locatorsfolder with the name of the page or component (e.g:loginPage.xml)
componentfolder - contains files from page components that do not change according to the page (it can be afooter, aheader). Also, for use, these locators must be included in thepagesfile required for usepagesfolder - contains files of different pages that change according to the link.
📁 Example folder structure:
locators/ ├── component/ │ └── header.xml ├── pages/ │ └── loginPage.xml
componentlocator file structure<component> <locators> <locator locatorId="searchField"> <xpath>.//input[@type='text']</xpath> </locator> </locators> </component>
pageslocator file structure<page> <details> <name>Sign In</name> <url>http://localhost:3000/</url> <description>Sign In for regression tests</description> </details> <include component="header.xml"/> <locators> <locator locatorId="email"> <xpath>.//input[@type="email"]</xpath> <id>email</id> <className>emailClass</className> <cssSelector>.emailClass</cssSelector> <text>Input Your Email</text> </locator> </locators> </page>
| Element | Type | Required | Default | Description |
|---|---|---|---|---|
name |
String | true | - | Name of the test or scenario (e.g., "Sign In") |
url |
String | true | - | URL where the scenario starts |
description |
String | false | - | Description of the test's purpose |
After including
componentto locator'spageyou can access included locator by:locator="pageFileName.locatorIdFromComponentFile"<click comment = "Click on 'email' button" locator="loginPage.searchField"/>
| Attribute | Type | Required | Default | Description |
|---|---|---|---|---|
component |
String | true | - | Path to the component XML file to be included (e.g., reusable blocks like headers or footers) |
| Attribute / Element | Type | Required | Default | Description |
|---|---|---|---|---|
locatorId (attribute) |
String | true | - | Unique identifier to reference the locator |
xpath |
String | false | - | XPath expression used to find the element in the DOM |
id |
String | false | - | HTML id attribute of the element |
className |
String | false | - | HTML class name used to locate the element |
cssSelector |
String | false | - | CSS selector to identify the element |
text |
String | false | - | Text inside the element for matching or validation |
Now you can use your locator
loginPage.emailfor any command you need, and for any test.<click comment = "Click on 'email' button" locator="loginPage.email"/>
Direct usage of locators in the command field
- Use the
locatorStrategyattribute in each command that you need to specify locator type (xpathidclassNamecssSelectortext)- Write locator in the
locatorfield.<click comment = "Click on 'email' button" locator="//input[@type='email']" locatorStrategy="xpath"/>