LeanFT

LeanFT C# Tutorial Part 1 – Introduction

If you are searching for the Java Tutorial and landed on this page, please click this link.

If you are looking for a basic overview of LeanFT, You can check out my post here.

This tutorial will basically get you started with the tool and further things will be covered after that. You will notice that LeanFT uses more or less the same concepts that UFT does but with a better IDE and a cleaner approach.

In case you don’t have LeanFT installed on your machine, you can either install a standalone version of LeanFT or use the bundled version which comes with UFT 12.5. While installing, please make sure you select Visual Studio 2012/2013 depending on which version of Visual Studio you have installed on your machine.

Once the installation is sorted, when you launch Visual Studio, and create a new project, you should see 3 types of LeanFT projects available to you under the Test projects section. These are :-

  1. LeanFT Application Model Project – An application model is LeanFT’s way of saying Object Repository(referring to UFT concept here). You should create this project if you want to create a collection of objects of your AUT (read Application under test).
  2. LeanFT MSTest Project – This is a Unit Test project based on MSTest. You can know more about MSTest from here.
  3. LeanFT NUnit Project – This is a Unit Test project based on NUnit. You can know more about NUnit from here.

Once you have made up your mind about which framework to use (MSTest vs NUnit), you can create your first LeanFT Project. I have used MSTest for the purpose of this tutorial.

In order to create a new Project, go to File-> New-> Project -> Installed Templates -> Visual C# -> Test -> LeanFt MSTest Project. Once you create a new project, it should look something like :-


using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;

namespace LeanFtTestProject1
{
[TestClass]
public class LeanFtTest : UnitTestClassBase<LeanFtTest>
{
[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
GlobalSetup(context);
}

[TestInitialize]
public void TestInitialize()
{

}

[TestMethod]
public void TestMethod1()
{
}

[TestCleanup]
public void TestCleanup()
{
}

[ClassCleanup]
public static void ClassCleanup()
{
GlobalTearDown();
}
}
}

Lets look at the code line by line and understand it. Firstly we are importing the System namespace for obvious reasons. Then the Microsoft.VisualStudio.TestTools.UnitTesting namespace which gives us support for Unit Testing features offered by Visual Studio( like assertions, test methods etc). Then the HP.LFT.SDK which provides LeanFT’s sdk for Functional Testing.

[TestClass] – This attribute defines a Unit Test class which is a collection of [TestMethod] (s). Our LeanFTTest class is inherited from the UnitTestClassBase which is part of the LeanFT template and present in the UnitTestClassBase.cs file in the solution. It contains the definitions for the GlobalSetup and GlobalTeardown functions present in our Test class.

[ClassInitialize] – This attribute contains the method which gets executed when the class is instantiated. Here, this is used to call the GlobalSetup function defined in the UnitTestClassBase class. Under the hood, this function is initializing the LeanFT SDK as well as the Report.

[TestInitialize] – This attribute contains the method which gets executed before each [TestMethod].

[TestMethod] – This attribute contains the definition of a unit test method.

[TestCleanup] – This attribute contains the method which gets executed after each [TestMethod].

[ClassCleanup] –  This attribute contains the method which gets executed when the class is destroyed. Here, this is used to call the GlobalTeardown function defined in the UnitTestClassBase. Under the hood, this function cleans up the LeanFT SDK and generates the Report.

Note that we can use this template to automate any types of application that LeanFT supports – Web, Java,.NET, Windows and many more.

Now since we are familiar with the structure of the MSTest project template, we are in a position to write our first Web automation script which we’ll be covering in the next post.

LeanFT C# Tutorial Part 2 – Create First Test

Happy Automating !

Harshit Kohli

 

Advertisements

Categories: LeanFT

Tagged as: , , , , , , , , ,

3 replies »

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