LeanFT C# Tutorial Part 9 – Using LeanFT and Selenium Together !

I don’t want to debate which tool is better, of course both tools have their advantages and disadvantages. So lets use all the advantages together in a mega script which uses both technologies. For doing this, you have to:-

  1. Create a LeanFT Test Project in Visual Studio.
  2. Download Selenium Libraries from here.
  3. From the downloaded folder, add the reference for the following DLLs your Visual Studio project:-
    1. Selenium.WebDriverBackedSelenium.dll
    2. ThoughtWorks.Selenium.Core.dll
    3. WebDriver.dll
    4. WebDriver.Support.dll
  4. If you are working with Chrome, you need to additionally download the chromedriver.exe from here and put it in the bin\debug folder.
  5. Now the setup is done, you can get your hands dirty with the following code:-

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using HP.LFT.SDK.Web;
using HP.LFT.SDK.Insight;
using System.Drawing;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using System.IO;

namespace LeanFtTestProject1
{
    [TestClass]
    public class LeanFtTest : UnitTestClassBase<LeanFtTest>
    {
        IBrowser browser;
        IWebDriver chromeDriver;

        [ClassInitialize]
        public static void ClassInitialize(TestContext context)
        {
            GlobalSetup(context);
        }

        [TestInitialize]
        public void TestInitialize()
        {
            //browser = BrowserFactory.Launch(BrowserType.Chrome);
            ChromeOptions CO = new ChromeOptions();
            CO.AddExtension(@"C:\Program Files (x86)\HP\LeanFT\Installations\Chrome\Agent.crx");
            chromeDriver = new ChromeDriver(CO);
            browser = BrowserFactory.Attach(new BrowserDescription
            {
                Type = BrowserType.Chrome
            });
        }


After writing the above code, your “browser” and “chromeDriver” objects are pointing to the same browser instance. You can now use chromeDriver and browser objects interchangeably in your script!

For more information on using Selenium in C#, you can refer many blogs that write about it.

Happy Automating!
Harshit Kohli

5 Replies to “LeanFT C# Tutorial Part 9 – Using LeanFT and Selenium Together !”

  1. Hi Birendra,

    As per the 12.5 release of LeanFT, JavaFX applications should be supported. You can spy on them just like the Web objects in these tutorials. Just make sure you have the Java Add-in selected by right clicking the LeanFT icon in the taskbar and then selecting the add-in from the available options.

    Is there any specific problem you need help with ?

Leave a comment