In this tutorial, I will show you how to use XPath in LeanFT.LeanFT has been officially rebranded as UFT Developer by Miro Focus. It has a very powerful mechanism to identify objects in a test application. It can identify objects by using object properties, CSS Selection, and XPath.In Open source tools, XPath is widely used to identify web objects.LeanFT also supports XPath to identify all kinds of web objects. To know more about XPath expressions and how to create them, please refer to my post on XPath in Selenium WebDriver with Example which is a generic article on XPath and is not specific to a specific automation tool. The core concepts of XPath are the same across all automation tools.
Example of Using XPath in LeanFT | UFT Developer
LeanFT is capable enough to uniquely identify objects using its property. However, there might be some scenarios wherein you would like to use XPath to identify a test object.LeanFT gives us the option to use the XPath of the object along with other properties. Nevertheless, you can also use the only XPath to identify an object as a valid XPath alone is sufficient to identify an object. The following example illustrates how to use XPath in LeanFT.In the following test, the script enters the user credential and presses the login button using XPath of the respective objects.
public class XPATHLeanFTTest extends UnitTestClassBase
public void testMercury() throws GeneralLeanFtException, ReportException
//Open the Chrome browser.
Browser browser = BrowserFactory.launch(BrowserType.CHROME);
EditField userNameEditField = browser.describe(EditField.class, new XPathDescription("//input[@type='text' and @name='userName']"));
EditField passwordEditField = browser.describe(EditField.class, new XPathDescription("//input[@type='password' and @name='password']"));
Image signInImage = browser.describe(Image.class, new XPathDescription("//input[@type='image' and @name='login']"));
Reporter.reportEvent("Runtime error occured","Failed during test",Status.Failed, e);
You can write your own custom XPath if you are well versed in writing XPath or you can take the help of the Object Identification Centre (OIC) to create the descriptive object using XPath Description. During object identification using OIC, you can uncheck all other properties except XPath to create the object using the XPath description.
You can copy the XPath value in your clipboard and used it in your scripts. To know more about how to use the Object Identification Center please refer to the following posts.
- Object Identification Center in LeanFT | UFT Developer
- Spy Multiple Objects in LeanFT Using Object Identification Center | OIC
- Create Application Model Project in LeanFT | UFT Developer & Write First Test in Java
- Create a UFT Developer | LeanFT Testing Project & Write Your First Test
- Overview of Micro Focus UFT Developer | LeanFT
- Intuitive Way of MySQL Database Testing in Selenium | LeanFT
- Read and Write Excel File in Java Using Apache POI Lib