Before describing the WEB related commands, it is necessary to know how to create a locator and connect it to a scenario.
Available types of locators:
- id
- class
- xpath
- cssSelector
- text
Locator for commands can be written in two types:
- locator - locators are created in 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.
To create locators for the l__ocator field you need:
To create a file in the locators folder with the name of the page or component (e.g: loginPages.xml)
- component folder - contains files from page components that do not change according to the page (it can be a footer, a header). Also, for use, these locators must be included in the pages file required for use;
- pages folder - contains files of different pages that change according to the link.
All files with locators have the required scheme format inside this file.
x
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.knubisoft.com/testlum/testing/model/pages" xsi:schemaLocation="http://www.knubisoft.com/testlum/testing/model/pages pages.xsd"></page>- Fill in the
<details>tag, enter the name, URL, and description information about this page.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.knubisoft.com/testlum/testing/model/pages" xsi:schemaLocation="http://www.knubisoft.com/testlum/testing/model/pages pages.xsd"> <details> <name>name_of_the_file_with_locators</name> <url>url_for_which_locators_are_written</url> <description>description_of_the_file_with_locators</description> </details> </page>- You can also use a component locator file inside a page locator file:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.knubisoft.com/testlum/testing/model/pages" xsi:schemaLocation="http://www.knubisoft.com/testlum/testing/model/pages pages.xsd"> <details> <name>name_of_the_file_with_locators</name> <url>url_for_which_locators_are_written</url> <description>description_of_the_file_with_locators</description> </details> <include component="header.xml"/> - inclusion of all locators that are in the header.xml file in loginPages.xml, accordingly, the path to these files will begin with loginPages(an example of a file name from the pages folder) <locators> <locator locatorId="username"> <id>LoginName</id> </locator> </page>- After the
<details>block, open the<locators>tag where you can write an unlimited number of<locator>.
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.knubisoft.com/testlum/testing/model/pages" xsi:schemaLocation="http://www.knubisoft.com/testlum/testing/model/pages pages.xsd"> <details> <name>name_of_the_file_with_locators</name> <url>url_for_which_locators_are_written</url> <description>description_of_the_file_with_locators</description> </details> <locators> <locator locatorId=""> < </locator> <locator locatorId=""> < </locator> </locators> </page>- To give a unique name to the locator’s element, which must start with a lowercase letter (e.g: emailField).
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.knubisoft.com/testlum/testing/model/pages" xsi:schemaLocation="http://www.knubisoft.com/testlum/testing/model/pages pages.xsd"> <locators> <locator locatorId="emailField"> - a unique name of the locator < </locator> </locators> </page>- To set a type of the locator ( id, xpath, class, etc.).
<page xmlns="http://www.knubisoft.com/testlum/testing/model/pages"> <locators> <locator locatorId="emailField"> - a unique name of the locator <xpath></xpath> - xpath type </locator> </locators> </page>- Fill in the selected locator type.
<page xmlns="http://www.knubisoft.com/testlum/testing/model/pages"> <locators> <locator locatorId="emailField"> - a unique name of the locator <xpath>.//input[@type='email']</xpath> - selected value of interaction </locator> </locators> </page>Now you can use your locator -loginPages.emailFieldfor any command you need, and for any test.
An example of using locatorId in a command:
<click comment = "Click on 'email' button" locator="loginPages.emailField"/> - path to desired elementAfter the element locator= "" - we’re paving the way to the locator we need in the format filename.locatorId.
To write locators directly in the field for the locator you need:
- Use the locatorStrategy attribute in each command that you need.
<click comment = "Click on 'email' button" locator="" locatorStrategy=""/>- Select the required locator type (locatorId - is default value, which there is no need to write).
<click comment = "Click on 'email' button" locator="" locatorStrategy="xpath"/> - the type of locator that will be in the locator field- Write locator in the 'locator' field.
<click comment = "Click on 'email' button" locator="//input[@type='email']" locatorStrategy="xpath"/>