In this post we will discuss about how to work with LeanFT application Models.
What is LeanFT’s Application Model?
Application Model is the object repository for LeanFT. You can store the object hierarchy and description in the application model.
How to create Application Model?
There are two ways to create application Model within Visual studio.
Create a separate application model project from the installed templates
To create a new application model project
- In Visual studio, Click File->New->Project.
- Select C# and then Select Test.
- Select LeanFT Application Model Project.
- Click OK.
Add the application Model to the existing project
To add application model within existing project
- Within solution explorer, right click on the project name.
- Select Add LeanFT and Select application Model.
- Provide the name and the class name for the application model.
When you create application model within visual studio, a file with extension “.tsrx” will be created. You can open this file from the solution explorer.
To view application model’s editor, right click on the tsrx file and select “View code”.
To view the application model’s Xml file, right click on the tsrx file and select view code.
<?xml version="1.0" encoding="utf-8"?> <applicationModel> <name>GoogleTestAppModel</name> <className>GoogleTest</className> <description>This application model will be used for storing the objects from Google.com</description> <objects> <object technology="Web" type="Page"> <name>Google</name> <codeName>GooglePage</codeName> <identification /> <tags> <tag>Browser</tag> </tags> <children> <object technology="Web" type="Button"> <name>Submit_Button</name> <codeName>SubmitButton</codeName> <description>This is the submit button for the Google search window</description> <identification> <properties> <property name="ButtonType" type="string">submit</property> <property name="TagName" type="string">Input</property> <property name="Name" type="string">Google Search</property> </properties> </identification> <tags> <tag>Button</tag> </tags> </object> <object technology="Web" type="EditField"> <name>q</name> <codeName>QEditField</codeName> <identification> <properties> <property name="Type" type="string">text</property> <property name="TagName" type="string">INPUT</property> <property name="Name" type="string">q</property> </properties> </identification> <tags> <tag>textbox</tag> </tags> </object> </children> </object> </objects> </applicationModel>
You can edit this xml file directly to add or update the objects.
Adding Objects to application Model
Using Object identification center
It’s the easiest way for adding the object.
For adding the objects using the application model
- Open the application model from solution explorer.
-
Click on the Object identification center button within the application model.
-
Object identification center will open. Click on the Spy button in the object identification center.
-
Click on the object. Object properties will be loaded.
- Click on Add Object to application model button (
).
-
Open the application model. Object with the required parents should be present in the application model.
Adding object manually to application model
For adding the test objects manually
-
Open application model and Click on the “create new test object” button.
-
New object pane will open in application model.
- Provide the object name, technology, type and description for the object.
-
Once you select the technology and the type of the object, you will see the list of properties populated for the object.
- Check the properties you want to use and provide the values for the selected properties.
-
You can provide regular expressions, by clicking on the star next to the value textbox.
- Click on the save button.
- If you want to see only the used properties, click on the used button.
-
Click highlight button (
) to check if the LeanFT is able to identify the object. If everything works fine then you will see the following message
Using Application Model with C# code
When you compile your project after adding the application model, Visual studio will generate the class for the application model, this class will be used for referencing the objects within application model.
If you have created a separate application model project then you will have to add the reference to the project and add the reference of that project class in the test class
Using ApplicationModel1;
If you have added the application model within the LeanFT’s NUnit or MSTest projects then you can directly start using the application model.
Initializing application model object
Initialize the application model object after you have initialized the parent object. For web browsers first initialize the Browser object and then initialize the application model object.
IBrowser OBrowser; GoogleTest OGoogleTestAppModel; OBrowser = BrowserFactory.Launch(BrowserType.InternetExplorer); OGoogleTestAppModel = new GoogleTest(OBrowser);
Writing LeanFT tests with application model
Once the initialization is done you can start using the application model object and the code will very much look alike the UFT code.
Below is the code for opening google and searching text on it
using System; using NUnit.Framework; using HP.LFT.SDK; using HP.LFT.SDK.Web; namespace LeanFtTestProject2 { [TestFixture] public class LeanFtTest : UnitTestClassBase { IBrowser OBrowser; GoogleTest OGoogleTestAppModel; [TestFixtureSetUp] public void TestFixtureSetUp() { // Setup once per fixture OBrowser = BrowserFactory.Launch(BrowserType.InternetExplorer); OGoogleTestAppModel = new GoogleTest(OBrowser); } [SetUp] public void SetUp() { // Before each test } [Test] public void Test() { OBrowser.Navigate("Google.com"); OBrowser.Sync(); OGoogleTestAppModel.GooglePage.QEditField.SetValue("This is leanFT Test with Application Model"); OGoogleTestAppModel.GooglePage.SubmitButton.Click(); OGoogleTestAppModel.GooglePage.Sync(); } [TearDown] public void TearDown() { // Clean up after each test } [TestFixtureTearDown] public void TestFixtureTearDown() { // Clean up once per fixture } } }
Above code is using the LeanFT NUnit framework.
Converting Object repository to application model
You can convert the UFT’s object repository to the application model, using the OR2APPMODELCONVERTER.exe program. After you install LeanFT, this program will be available at
If LeanFT is install alone
<LeanFT installation folder>\bin
If LeanFT is installed with UFT
<UFT installation folder>\bin
Syntax
OR2AppModelConverter ExistingORPath NewAppModelPath
This converter utility will accept “.xml”, “.tsr” and “.bdb” file type for object repository.
When to use this utility
- If you have the existing object repository and you want to create the leanft tests using the same OR.
- When you have to add the multiple objects quickly, then you can add the object using the UFT and then convert it to the application model.
Searching for the objects within application model
When you have a bigger application model, you can take advantage of the searching feature of the application model to locate the objects. You can also add tags to the objects to group similar objects. Later you can use these tags for searching the objects.
In the above screenshot I am adding the tag button to Submit_Button.
In the above screenshot you can see the tags added for all of the objects.
In the above screenshot I am searching for the button tag.
If you want to see the objects with hierarchy then click on () Button.
Click on the advanced button to perform an advanced search for the objects
Let me know, if you have any questions.
Can we merge 2 application models? Say 2 resources are working in same application and then want to merge application model into 1, is it possible ?
LikeLike