Quality and Testing Blog
cancel

Selenium and LeanFT: Easily integrating LeanFT into your Selenium-based projects

Selenium and LeanFT: Easily integrating LeanFT into your Selenium-based projects

OriBendet

 

(This post was written by Anton Kaminsky from the LeanFT R&D Team)

 

LeanFT Functional Testing (LeanFT), is a new functional test automation solution, targeted to advanced automation engineers and dev-testers in agile teams. LeanFT provides comprehensive SDKs for both .NET and Java, as well as plugins for these IDEs, which include several powerful tools like the Object Identification Center and Application Models. LeanFT supports automating applications for a wide range of technologies including Web, Mobile, .NET and Java applications.

 

Using Selenium to automate your applications but would like to start using LeanFT? don’t worry!

In this blog we’ll see how you can use Selenium and LeanFT within the same tests suite (and even within the same test), and by that, migrate your Selenium project to LeanFT s gradually.

 

The blog covers the following scenarios:

  • LeanFT-Selenium Side-by-Side – Create a project having both Selenium and LeanFT tests
  • LeanFT-Selenium in One - Create a project that combines LeanFT and Selenium steps in a single test

 

If you already have tests in Selenium, you can continue using them, add new tests in LeanFT, and even combine LeanFT capabilities in your existing Selenium tests. And then over time, you can re-write your Selenium tests to LeanFT tests to improve your continuous testing process.

 

For the sake of this example, we will create a test using Java in the Eclipse IDE. Similar steps can be done using C# and the Visual Studio IDE.

 Before You Begin

Install LeanFT with the Eclipse plug-in. 
Don’t forget to specify the location of your Eclipse.

 LeanFT-Selenium Side-by-Side

1. Create a Selenium test. 

In the following Selenium test, we launch Chrome, navigate to Wikipedia, search for ‘Star Wars’ and then verify the release date of the new Star Wars: The Force Awakens film. 

a. Start Eclipse and create a new project. Call it LeanFTSeleniumSideBySide.

b. Add a reference to the Selenium JAR to your project.

c.  Add a new JUnitTestCase in your src directory.  Call your package mytests and call the class SeleniumTest.

d. Enter the code shown below in the SeleniumTest class.

e. To run the test, right click on the source file (SeleniumTest.java) in the package explorer and select Run As->JUnit Test.

 

 

2. Add a LeanFT test to the project

The next step is to add a LeanFT test to the existing Selenium project.

  1. Right-click on our package (mytests) and select New > Other
  2. In the New dialog, select LeanFT JUnit Test Case, and press Next.

 

Give the test case the name: LeanFtTest and click Finish.

 

3. Add the LeanFT test content and then run both tests at once

Now we’ll add content to the LeanFT test case.  This test is similar to the Selenium test we created above, only this time we verify the name of the movie director instead of the movie release date.

  1. Enter the code shown below in the LeanFtTest class:
  2. Since we now have a single project with both Selenium and LeanFT tests, just right-click on the project, select Run As > JUnit Test and both test will be executed.

 

LeanFT-Selenium in One

In this section, we create a single test that contains both Selenium and LeanFT steps. This test is a combination of the two tests we wrote in the section above.

As Selenium can’t be attached to open browsers, the browser must be launched using Selenium. In addition, the browser should be launched with the LeanFT extension, to allow LeanFT to attach to this browser instance. This done in the setUp method, where we start the chrome driver with the LeanFT extension, and then use the LeanFT’s BrowserFactory.attach method, to attach to instance launched by Selenium.

From this point on we get all the capabilities of both LeanFT and Selenium on the same browser instance.

  1. Add another LeanFT JUnit Test Case to the project from above, so that we’ll already have the LeanFT template set up for us: Right-click on our existing package and select New > Other… > LeanFT JUnit Test Case.  Call the test case LeanFtAndSelenium.
  2. Insert the code shown below in the LeanFtAndSelenium class.
  3. To run just this test, right click on the class and select Run As-> JUnit Test.  (You can of course run all tests by doing the same on the package or project).

 

A note on the Test Report:

LeanFT automatically generates a rich html run report which enables an easy root-cause analysis of failures that occur while executing LeanFT test steps.

The LeanFT Reporter class also exposes an API that you can leverage to report the Selenium steps as well, and therefore have a single, complete report for the test.

 

Summary:

This blog post shows how you can update your existing Selenium test projects to include LeanFT tests, and even combine both LeanFT and Selenium in a single test.

Thus, a project of Selenium tests can be migrated to LeanFT tests gradually, test-by-test, while your existing tests continue to function as usual.

 

If you would like to try LeanFT for yourself, take a look at the LeanFT Trial web site.

 

Thanks to Anton for providing this article!

 

Try LeanFT for yourself!

 

Feel free to leave a comment in the box below.

About the Author

OriBendet

Functional Architect, FT

Comments
Not applicable

It seems that LeanFT has been specifically targeted at the Selenium user base .Technology trends are extremely dynamic and you prepare today for anticipated changes or risk obsolescence. At this point, it is very nice to see  how simple of  the integration of LeanFT and Selenium is.

Absent Member.

I’m really excited about leanFT. I work on a modern web application but it integrates with thick client application that we can’t automate because Selenium is only for browsers. Now we are going to be able to leverage our existing Selenium/BDD framework with LeanFT with little rework. Well done HP - the only thing I would love to see is a way to add the LeanFT dependance in Maven so I can just add a dependency in our projects pom file.

Not applicable

Thanks for this totorial of bringing LeanFT and Selenium together. Seems really simple.

Not applicable

Great tutorial on LeanFT, Anton. 

Not applicable

This LeanFT-Selenium all in one solution does not appear to work with IE.  Can you please confirm if there is a workaround to attach LeanFT to the browser opened by Selenium?

Visitor.

They seem to be working fine together in terms of test execution, however I have been having some issues with the reporting side of things:

- if I create a project using only LeanFT SDK, the "View Last Run Results" generates the full HTML report, but

- if I try to add the selenium standalone jar to the project in order to run both at the same time, then only an xml version of the report is generated in the project folder and the "View Last Run Results" option is greyed-out.

LeanFT Version 14.0.2816.0 installed as part of UFT 14.00 installation.

The HTML report is available only if there is no selenium standalone jar.

Have any of you encountered the above issue and knows how to resolve it?

Any help will be very much appreciated.