Selenium and LeanFT: Easily integrating LeanFT into your Selenium-based projects
(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.
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.
- Right-click on our package (mytests) and select New > Other…
- 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.
- Enter the code shown below in the LeanFtTest class:
- 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.
- 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.
- Insert the code shown below in the LeanFtAndSelenium class.
- 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.
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!
Feel free to leave a comment in the box below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.