Creating LeanFT C# NUnit test

In this post we will discuss about how to create LeanFT NUnit tests. To read about how to create LeanFT MSTest projects Click Here

Required Components

  1. Visual studio 2012, 2013 or 2015(LeanFT 12.51+).
  2. UFT 12.5+
  3. NUnit framework
  4. NUnit test adapter

You don’t have to buy visual studio, you can use the community edition for free (check license, before using it).

Installation of NUnit

After the installation of visual studio, if you try to create LeanFT template project, you will see an error message that NUnit.Framework is missing. For resolving this error you will have to install NUnit framework files. To install it navigate to the below link and download and install the windows package

http://www.nunit.org/index.php?p=download

Once the installation is done, install the NUnit test adapter for visual studio

  1. In visual studio, open Tools->Extensions and updates->online and search for NUnit. Select Download.
  2. Once download and install is done, restart your visual studio.

Once all of the installations are done, you can proceed with the creation of NUnit tests.

Creating test with NUnit template

For creating the NUnit tests

  1. Open Visual studio and click File->New->Project
  2. Select C# and then select Test.
  3. Select LeanFT NUnit template

  4. Click OK.
  5. Visual studio will now create the Empty LeanFT NUnit project, and you can view or update the code in LeanFTTest.cs file.

using System;
using NUnit.Framework;
using HP.LFT.SDK;

namespace LeanFtTestProject2
{
    [TestFixture]
    public class LeanFtTest : UnitTestClassBase
    {
       [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            // Setup once per fixture
        }
        [SetUp]
        public void SetUp()
        {
            // Before each test
        }
        [Test]
        public void Test()
        {
        // 
        }
       [TearDown]
        public void TearDown()
        {
            // Clean up after each test
        }
        [TestFixtureTearDown]
        public void TestFixtureTearDown()
        {
            // Clean up once per fixture
        }
    }
}

Updating the Code

For creating your first test copy the following code and update it into your LeanFTTest.cs file

using System;
using NUnit.Framework;
using HP.LFT.SDK;
using HP.LFT.SDK.Web;

namespace LeanFtTestProject2
{
    [TestFixture]
    public class LeanFtTest : UnitTestClassBase
    {
        IBrowser OBrowser;
        
        [TestFixtureSetUp]
        public void TestFixtureSetUp()
        {
            // Setup once per fixture
            OBrowser = BrowserFactory.Launch(BrowserType.InternetExplorer);
        }
        [SetUp]
        public void SetUp()
        {
            // Before each test
        }

        [Test]
        public void Test()
        {
            OBrowser.Navigate("Google.com");
            var GoogleSearchTextBox = OBrowser.Describe<IEditField>(new EditFieldDescription
            {
                Type = @"text",
                TagName = @"INPUT",
                Name = @"q"
            });
            OBrowser.Sync();

            GoogleSearchTextBox.SetValue("This is leanft test");
            var GoogleSeachButton = OBrowser.Describe<IButton>(new ButtonDescription
            {
                ButtonType = @"submit",
                TagName = @"INPUT",
                Name = @"Google Search"
            });

            GoogleSeachButton.Click();
            OBrowser.Sync();
        }

        [TearDown]
        public void TearDown()
        {
            // Clean up after each test
        }

        [TestFixtureTearDown]
        public void TestFixtureTearDown()
        {
            // Clean up once per fixture
        }
    }
}

In the above code you will notice that I have included the reference to the namespace “HP.LFT.SDK.Web”. This reference is required if you are working with the Web based applications. If you want to work with other technologies then you can include it in the same way.

I have created a web browser object and navigated it to the google.com website. Then I have searched for the text “This is LeanFT test”. Sections where I am creating the description of the object are simply copied from the object identification center. You can read about object identification center here

Running your NUnit test

To run your NUnit test

  1. Open Test explorer. Test->Windows->Test explorer

  2. Click on Run all in the test explorer.

  3. NUnit test results will be visible in the test explorer.

  4. To see the LeanFT test execution results, Goto the project folder and open Bin->Debug->RunResults->RunResults.HTML.

Let me know, if you have any questions.

Advertisement

2 responses to “Creating LeanFT C# NUnit test

  1. Hi Sumeet,

    Great to see early adaptation of LeanFT and codes coming out from you and other experts. Can you guide what will be a good source of repository of examples/samples of java code for LeanFT ?
    Also, if you can share your experience and feelings after working on this brand new avatar of UFT

    Regards,
    Rahul

    Like

  2. Hi Rahul,

    Java code samples for LeanFT is available in the below website

    http://leanft-help.saas.hp.com/en/latest/JavaSDKReference/index.html?com/hp/lft/sdk/example-files/master-examples-list.html

    You can get the details about the java packages and classes available for leanFT below

    http://leanft-help.saas.hp.com/en/latest/JavaSDKReference/index.html

    I tried LeanFT with couple of websites and its working great, i haven’t faced any issues.

    let me know, if you have any other questions.

    Like

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 )

Connecting to %s