Creating Application models using LeanFT

There are 2 ways to create or manage the test objects in LeanFT.

  1. Description programming
  2. Application model (Just like old Object repository in UFT)

In this article, we are going to see how to create the application model from scratch and access it in the code.

In your visual studio project, you will have to add the new application model item as shown in below image.

add-application-model

Below screen shot shows the new application model with one object (Calculator window) added into it.

add-new-object-in-application-model

 

 

Once your model is ready, you can access it from the code as shown in below lines.

var calculatorModel = new CalculatorModel();
calculatorModel.CalculatorWindow.ButtonPlus.Click();

Here is the complete example on calculator addition operator. Please note that to use models, you need to add reference of System.Drawing namespace into your project

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK.Descriptions;
using HP.LFT.UnitTesting;
using HP.LFT.Common;
using HP.LFT.SDK.Web;
using HP.LFT.SDK;
using HP.LFT.Report;
using HP.LFT.SDK.StdWin;
using System.Diagnostics;

namespace leanFT
{
    [TestClass]
    public class UnitTest1
    {

        [TestMethod]
        public void TestCalculator()
        {
            SDK.Init(new SdkConfiguration());
            Reporter.Init(new ReportConfiguration());
            Process.Start(@"d:\Windows\System32\calc.exe");
           IWindow win = Desktop.Describe<IWindow>(new WindowDescription
            {
                IsOwnedWindow = false,
                IsChildWindow = false,
                WindowClassRegExp = @"CalcFrame",
                WindowTitleRegExp = @"Calculator"
            });

           Trace.WriteLine("Calculator window title is " + win.WindowTitleRegExp);
           

           var button8 = win.Describe<HP.LFT.SDK.StdWin.IButton>(new HP.LFT.SDK.StdWin.ButtonDescription
           {
               Text = string.Empty,
               WindowId = 138,
               NativeClass = @"Button"
           });
           button8.Click();

          var result = win.Describe<IStatic>(new StaticDescription
           {
               WindowId = 150,
               NativeClass = @"Static"
           });
          Trace.WriteLine("Result text contains " + result.Text);

          var calculatorModel = new CalculatorModel();
          calculatorModel.CalculatorWindow.ButtonPlus.Click();
          calculatorModel.CalculatorWindow.Button3.Click();
          calculatorModel.CalculatorWindow.ButtonEquals.Click();
          Trace.WriteLine("Result of addition is " + result.Text);
          Assert.AreEqual("11", result.Text, "Addition of 8 and 3");
           win.Close();
           Reporter.GenerateReport();
           SDK.Cleanup();

        }

    }
}

You may also like...