LeanFT Java 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 JUnit Project in Eclipse.
  2. Download Selenium Libraries from here and extract to a desired location.
  3. In your Eclipse project, right click the Project name and goto Build Path -> Configure Build Path.
  4. Click on Add External Jars option and add the selenium-java-{version}.jar from the extracted location.
  5. Also add all the jars in the libs folder.
  6. If you are working with Chrome, you need to additionally download the chromedriver.exe from here.
  7. Now the setup is done, you can get your hands dirty with the following code:-

package l2a;
import static org.junit.Assert.*;
import java.io.File;
import org.junit.*;
import com.hp.lft.sdk.*;
import com.hp.lft.sdk.web.*;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
import unittesting.*;

public class LeanFtTest extends UnitTestClassBase {

 public LeanFtTest() {
 //Change this constructor to private if you supply your own public constructor

 public static void setUpBeforeClass() throws Exception {
 instance = new LeanFtTest();

 public static void tearDownAfterClass() throws Exception {

 public void setUp() throws Exception {

 public void tearDown() throws Exception {
 public void leanFTSelenium()
 //Setting the Path for Chrome Driver
 System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
 //Adding the Chrome Extension for LeanFT
 ChromeOptions CO = new ChromeOptions();
 CO.addExtensions(new File("C:\\Program Files (x86)\\HP\\LeanFT\\Installations\\Chrome\\Agent.crx"));
 //Launching Chrome with Selenium 
 WebDriver driver = new ChromeDriver(CO);
 //Navigating to Google
 //Attaching to the Browser with LeanFT
 Browser browser = BrowserFactory.attach(new BrowserDescription.Builder()
 //Navigating to Learn2Automate on the same browser instance
 catch(Exception ex)
 Assert.fail("Unexpected Error occurred - " + ex.getMessage());


After writing the above code, your “browser” and “chromeDriver” objects are pointing to the same browser instance. You can now use both objects interchangeably in your script, this essentially means you can write either Selenium or LeanFT code for performing an action on your browser. Talk about Flexibility !

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

In case you are interested in knowing about a TestNG based LeanFT framework, click here.

Happy Automating!
Harshit Kohli


22 thoughts on “LeanFT Java Tutorial Part 9 – Using LeanFT and Selenium Together !

  1. Hi,
    First of all,thanks for a good leanft blog. I’ve two question about leanFT, but not about this topic.

    1- How can I switch frame using LeanFT?
    2- How can I automated Oracle Forms applications?


    1. Hi Ismail,

      Following are the answers to your questions:-

      1. You don’t need to switch frame in LeanFT. What you need to do is call the command – BrowserFactory.attach() which takes the browser description and returns a Browser object that you can work with.

      2. You need to check the documentation whether LeanFT supports Oracle Forms applications. In case you have an HP license, you can log in to HP and see the Product Availability Matrix. FYI, latest version is 14. In case, it supports, you need to right click the LeanFT Runtime engine from the task bar(bottom right corner) and select Settings where you will be able to see the add-ins available. Select Oracle Forms and restart the engine.

      Happy Automating !
      Harshit Kohli

      1. Hi,
        Thanks alot.

        1- I tried BrowserFactory, but not worked. What’s wrong?

        Browser customerFrame = BrowserFactory.attach(new BrowserDescription.Builder()

        System.out.println(“New Frame added”);

        EditField txtCustomerID = customerFrame.describe(EditField.class,
        new EditFieldDescription.Builder().id(“txtGlbCustomerSearch”).build());

  2. Yes I tried it. In simple mode, I saw highlighting success; but when I switched from simple mode to Edit mode, highlighting not working. I changed properties and then tried again; but problem not resolved. And When I copied & paste code, IOC only generated “browser;”

  3. Hi there. Great tut !!!. I was wondering, is it possible to parallel test with the leanFT like we do with Selenium grid. Cheers

  4. Hi Harshit,
    How to save images in LeanFT.
    After spying to the image in my application, i can see getSnapShot() for this. But no where it is saving in my local.

    Also, tried like this:
    RenderedImage img = browser.describe(Image.class, new XPathDescription(“//IMG[@id=\”labelImage\”]”)).getSnapshot();
    File snapshotFile = new File(“C:\\Users\\rakshith.k02\\Desktop\\tabletImage2.jpg”);
    ImageIO.write(img, “jpg”, snapshotFile);

    But the image is not saving as expected. It is dispalying in reddish color. I want my image to save in original color only. Please help me how to save images in LeanFT.

      1. Hi Harshit,
        My requirement is to save an image that is generated in my web application. From object identification center, I can able to spy. But how to save in my local system?

    1. Hi Sajin,

      The basic approach remains the same :-

      1. Use the object spy to look for properties
      2. Generate the code to clipboard
      3. Use the code and create your tests!

      You can try this out on any supported thick client.

  5. Hey Harshit,

    I’m wondering how does the leanFT run parallely on same browser using testng xml parallel attribute.

    As LeanFT opens up chrome tabs instead of browser windows, i think its impossible to trigger parallel tests similar to selenium does with testng same browser.

    I saw your post in Stackoverflow, https://stackoverflow.com/questions/35547519/leanft-and-test-in-multiple-browsers

    As you said, if open up 3 browser instances from selenium driver, suppose my test has the same url, how can i assign back the browser even though i get all browser from browserfactory

    1. Yes, i tried, but as i said, i’m not able to assign browser returned from getAllOpenBrowsers, methods as they all will have same attributes like title, url or browserType….It returns in not handling browser and providing null pointer exception …

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 )

Connecting to %s