Working with LeanFT’s Application Models

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

  1. In Visual studio, Click File->New->Project.
  2. Select C# and then Select Test.
  3. Select LeanFT Application Model Project.
  4. Click OK.

Add the application Model to the existing project

To add application model within existing project

  1. Within solution explorer, right click on the project name.
  2. Select Add LeanFT and Select application Model.

  1. 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

  1. Open the application model from solution explorer.
  2. Click on the Object identification center button within the application model.

  3. Object identification center will open. Click on the Spy button in the object identification center.

  4. Click on the object. Object properties will be loaded.

  5. Click on Add Object to application model button ().
  6. 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

  1. Open application model and Click on the “create new test object” button.

  2. New object pane will open in application model.

  3. Provide the object name, technology, type and description for the object.
  4. Once you select the technology and the type of the object, you will see the list of properties populated for the object.

  5. Check the properties you want to use and provide the values for the selected properties.
  6. You can provide regular expressions, by clicking on the star next to the value textbox.

  7. Click on the save button.
  8. If you want to see only the used properties, click on the used button.
  9. 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

  1. If you have the existing object repository and you want to create the leanft tests using the same OR.
  2. 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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s