Windows application testing using LeanFT

LeanFT supports testing of standard windows based applications, .Net applications, WPF applications etc.

Testing these applications is very easy with the help of Object Identification Center(OIC) tool which allows generating the code for the objects on the fly.

In sample test below,  We are going to verify if calculator + operator is working correctly or not. If the result of 8+3 is 11, our test passes else it will fail.

Instead of using Description programming, we can also create the application model of the calculator using OIC. Application model in LeanFT is equivalent to the Object repository in UFT (QTP). In below example, we have used both approaches to test the calculator – Description as well as Application model.

 

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