LeanFT with C#.net
LeanFT Introduction Supported applications Installation of LeanFT Installing the browser extensions Setting up LeanFT project in Visual Studio LeanFT Settings Types of Licenses in LeanFT Object identification center Understanding LeanFT API in C#.Net LeanFT plugin in Visual StudioAutomating windows application Running first test Integrating LeanFT with Visual Studio Unit testing framework Viewing the results of the test Description programming in LeanFT application models regular expressions in LeanFT Web application testing using LeanFT Identifying the elements using xpath and css Firing events Executing JavaScript Calculator automation using LeanFT Notepad Automation using LeanFT Automation of Java Applications Automation of SAP Applications Automation of .Net Applications Visual Relational Identifier Synchronization in LeanFT in C#.Net Assertions in LeanFT Generating reports with screenshots and recordings Converting UFT object repository into application model Keyword driven frameworks Data Driven Frameworks SpecFlowNative objects LeanFT common issues and solutions Comparison of LeanFT with Selenium and Ranorex Difference between HP UFT and LeanFT. LeanFT references and Resources for .NetWeb application testing in leanft in C sharp
In this article, we will see how to automate web application with different browsers like Internet explorer, Firefox and chrome. Before you dive into the automation of browsers, ensure that HP Functional testing agent add-on (extension) is installed and enabled in your browsers. Below code will launch softpost.org and then click on first link containing text as “LeanFT”. We can use below example with little tweaks to handle many scenarios. For example – Suppose on the given page, there is a list of links with transaction ids and you want to click on the first link. In this scenario, you can change the InnerText property of the link so that LeanFT will identify the link.
InnerText =As.RegExp(@”d*”)
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 VerifySoftPost()
{
SDK.Init(new SdkConfiguration());
Reporter.Init(new ReportConfiguration());
IBrowser browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
browser.Navigate("softpost.org");
var leanFTLink = browser.Describe<ILink>(new LinkDescription
{
TagName = @"A",
InnerText =As.RegExp(@".*LeanFT.*"),
Index = 1
});
leanFTLink.Click();
browser.Close();
Reporter.GenerateReport();
SDK.Cleanup();
}
}
}
We can also write web tests using application model as illustrated in below example. Please notice how we have passed the browser to the calculator 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:WindowsSystem32calc.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();
IBrowser browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
var calculatorModel1 = new CalculatorModel(browser);
calculatorModel1.GooglePage.SearchEditField.SetValue("11");
Trace.WriteLine("Result of addition is " + result.Text);
Assert.AreEqual("11", result.Text, "Addition of 8 and 3");
win.Close();
Reporter.GenerateReport();
SDK.Cleanup();
}
}
}
Web development and Automation testing
solutions delivered!!