How to use LeanFT with C# Visual Studio Applitools

Test Automation Published on:
Visual Validation Tools

Last week, I was a guest speaker for an HP/Applitools webinar about Advanced Cross-Browser Testing Techniques. I also demonstrated how to use Applitools with LeanFT, HP's new automation tool. I'd like to share some of my notes from a few of the things I shared on the call.

What is LeanFT?

First of all, you may be asking, “What is LeanFT?” LeanFT is HP's new test tool, which they have developed to handle the modern automation demands of things like continuous testing and dev-ops.

LeanFT for modern test automation

What's really cool is that LeanFT fits into the developer's ecosystem, so you can use the same tools your developers use to create automation scripts. LeanFT supports technologies like Visual Studio and Eclipse, using either C# or Java, and supports unit testing frameworks like jUnit, NUnit, MSTest, and versioning control systems like GIT.

LeanFT supports many technologies

Bonus — LeanFT allows you to be able to access HP's Windows-based technologies that Selenium does not allow, since Selenium is for browser testing only. If you work for a large organization, undoubtedly your end-to-end tests often require some sort of interaction with a non-browser application. With LeanFT, you can script everything — browser and non-browser interactions — all in one framework!

Using C# and LeanFT

Let's take a look at how to create a LeanFT test in Visual Studio using C#.

For this demonstration I'm navigating to the https://saas.hp.com/software/leanft web page, then clicking on the resources link.

Create a simple LeanFT script

  • First, select your test type. When you start up Visual Studio on your LeanFT machine you'll notice three new templates under the C# section. You can create LeanFT script using either MSTest or NUnit. (For this example I'll be using MSTest.) When you select one of the templates, your new project will include all the MSTest or NUnit framework annotations you'll need to get started.
  • Next, because we want to test a web application we'll first need to import the HP.LFT.SDK.Web
  • Under the TestMethod section, declare a Chrome browser instance:

IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

Once we have a browser variable of type Browser we can access all the methods available for the browser object. Many of the methods that you're already familiar with for the Browser object in UFT/QTP are also available in LeanFT. Now let's navigate to our website:

browser.Navigate(“https://saas.hp.com/software/leanft”);

  • Next, click on the Resources link. We're going to create a test object that includes unique property values to help ID the object you want LeanFT to work with in your app. There are a few ways to do this, but for now we will use the LeanFT Object Recognition Center (ORC — think QTP spy) to help create the object description we need.
  • Click on the LeanFT ORC icon in Visual Studio, then click on the Star spying option.


  • Open up a browser and navigate to LeanFT, then point to the Resources link.
  • The LeanFT ORC will list all the properties it found for the object, and will place a Start icon next to all the properties it recommends you use to uniquely identify that object. For the Resources link it recommends InnerText, TagName and Index,
    so go ahead and click them.


  • Ensure that it finds the object by clicking on the Highlight option. It should locate the Resources link.


  • Next, click on the Generate code to clipboard option.
  • Close the ORC and the browser.


  • In your test under the browser navigate statement, paste the object definitions that the OR created for us, then add a variable named resourceLink in front of it:
var resourceLink = browser.Describe(new LinkDescription
{
TagName = @"A",
InnerText = @"Resources",
Index = 0
});
  • Next let's click on the Resources link — but before we do, let's make sure that the link exists. To do this we'll use the good old QTP/UFT Exist method.
Boolean doesExits = resourceLink.Exists(5);

 

  • If the link exists we will click on it. If it doesn't, we'll report a failure to the new LeanFT HTML report option.
if(doesExits ==true)
{
Reporter.ReportEvent("Link Exist Check,"Verify that link exists value is=" + doesExits, HP.LFT.Report.Status.Passed);
resourceLink.Click();
}
else
{
Reporter.ReportEvent("Link Exist Check","Verify that link exists value is= + doesExits, HP.LFT.Report.Status.Failed);
}
  • Once again — if you've used QTP or UFT before, this syntax should look very familiar to you.
  • Lastly we will close the browser:

browser.Close();

  • Run the test in Visual Studio by clicking on the Test>Run>All Tests menu option.

Easy cross browser testing using LeanFT

Cool! Now, to run against another browser all you have to do is change the browser type and rerun. No other code needs to be changed. For instance, to run against Firefox, just change the BrowserType to Firefox.

Applitools Eyes

In the webinar, I demonstrated how easy it is to add visual validation functionality to an existing LeanFT test. (I'll go over this step by step in another post.) But for now, be sure to check out the entire webinar to learn about all the benefits of visual validation testing and why it's so important.

More on LeanFT

For a more detailed demonstration of using LeanFT, be sure to sign up for the HP VIVIT LeanFT webinar Shift Left with Lean Functional Testing that I will be a guest speaker on next Friday.

Visual Validation Tools