LeanFT C# – Writing first test

Hi,

In this article we will discuss about how to create a basic test using HP’s LeanFT. To create the first test, you need to have visual studio 2012 or 2013 or Eclipse(I will write another post or explaining eclipse LeanFT integration) installed with HP’s LeanFT (Except express edition of visual studio). For this post we will use visual studio for writing LeanFT tests. Make sure that you install visual studio first.

Note : I have used Visual studio 2013, Windows 10, UFT 12.5 and IE 11 for this article

Browser Setup

You have to enable “HP Functional testing agent” in chrome and IE, before running the tests using LeanFT.

For chrome Settings->Extension

Chrome_Browser_Setup

For IE Tools->Manage Add-ons

IE_Browser_Setup

Create your first test

Once everything is installed and setup is done, open visual studio and click on file -> new project.

VisualStudioLeanFTOpen

Click on test under C#.Net(you wont find leanFT under any other tests) and you will see three options(template projects)

LeanFT application Model : An application model, is the model of the application you are testing. It acts as the object repository for LeanFT tests. So you can choose this project to create the model which acts as the OR for the project. You can also add the application model to the other two types of projects. We will discuss it later.

LeanFT MSTest Project : MSTest is the Microsoft’s unit testing framework. you will use the classes and members in the Microsoft.VisualStudio.TestTools.UnitTesting for creating an MSTest unit test. You can read more about MSTest Framework Here

LeanFT NUnit project : NUnit is the unit testing framework for the .Net languages. Its open source and completely written in the C#.net. To use this framework you will have to install the NUnit adapter from the extensions. you will be using classes and members from NUnit.Framework namespace. You can read more about NUnit framework Here

For this post i will select MSTest project.

Once you create the project you will see the below code already created


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();
}
}
}

Once the sample code is generated. You can add your code within the testmethod1. After adding the code it will look like this


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

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()
{
IBrowser OBrowser = BrowserFactory.Launch(BrowserType.InternetExplorer);

OBrowser.Navigate("Google.com");

OBrowser.Sync();

OBrowser.CloseAllTabs();
}

[TestCleanup]
public void TestCleanup()
{
}

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

In the above code we have included the code for invoking the browser and navigating it to the google.com. Once the navigation is done browser will be close.

Running tests

First open the test explorer, this is used to see the test execution results within Visual studio. To open test explorer, click on test->Windows->test explorer. Now to run the test, you can click on the Run Link in the test explorer.

Test Explorer

Here is the detailed Microsoft article about ways to run the test

How to Run test from visual studio

Viewing results

Once the execution is done you will see the test results in the test explorer window.

Test Execution results

This is the results generated by the MSTest framework, but you can also see the results generated by the LeanFT. LeanFT results can be viewed under bin\debug\runresults inside your project folder.

Let me know, if you have any questions.

Advertisements

One response to “LeanFT C# – Writing first test

  1. Pingback: Creating LeanFT C# NUnit test | Automation Insights·

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 )

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s