LeanFT Tutorial - Create Tests in LeanFT

In this post for LeanFT/UFT Pro tutorial series, we will go through steps to create tests in LeanFT and learn about IDE project templates and prerequisites. As mentioned in earlier posts, we are using IntelliJ and Java for this tutorial. Let us know your experiences and issues (if any) with any other tools, in the comments section.

Create Tests in LeanFT

LeanFT works with different IDEs of your choice such as Visual Studio, IntelliJ, Eclipse. LeanFT provides plugins for these IDEs to get along with different options and settings. Refer to our earlier post on Getting Ready with LeanFT for more details on setting up LeanFT for different IDEs. LeanFT plugin comes with built-in project templates to provide initial structure for your project and basic initial references.

Project Template for IntelliJ

You can create a Selenium-based project or a Maven-based project. If you want to create a Selenium-based project, LeanFt provides LeanFT for Selenium, a solution that extends the Selenium API and enables the creation of more robust and easily maintainable Selenium tests.

To start with a Maven-based project, you should install LeanFT JARs to the Maven Repository local or your organization’s repository. You can do this easily by running the commands below

Local

mvn install:install-file

-Dfile=<path-to-file>

-DpomFile=<path-to-pomfile>

Organization’s Repo

mvn deploy:deploy-file

-DpomFile=<path-to-pom>

-Dfile=<path-to-file>

-DrepositoryId=<id-to-map-on-server-section-of-settings.xml>

-Durl=<url-of-the-repository-to-deploy>

Now we need to create the test from IDE, since we are using IntelliJ, goto menu Option “File> New Project”. Follow the wizard

new LeanFT project

Select Testing Framework and SDK, check to create a maven project option if you want to create maven based project.

New Junit Project

Select Selenium if you want to use a Selenium-based project. You will need to select the JAR file from the LeanFT installation folder.

new project

Follow the rest of the wizard and your test will look like below

junit test

For a JUNIT test, it looks something like below

junit test

As you can see, a LeanFT class has been created, which we will use to script and automate our scenarios.

Automate a Web Application

Once you have the basic or initial project template you can start writing your test. Alternatively, you can also have your custom framework and a project template. You can also use Test Recorder to accelerate your test creation.

Since you have the base project created, as described in the previous section. Let’s now write our scripts for the test. The most important method in the LeanFTTest Class created above is the “test” method. Since we have created our project as LeanFT SDK, LeanFT SDK libraries will automatically get included in the project. In the case of Selenium, all the relevant libraries get included.

See also  TestComplete 14.0

external libraries

Since we are going to automate a web application, we will need to import the relevant package to work with web applications. Let’s import the leanFT web Package. Add the statement below to the import section at the top.

import com.hp.lft.sdk.web.*;

import package

Now, will write the code to launch the browser in our test method. You can change the method name to some meaningful name of your choice based on your test.

The first thing you need to do while automating a web application is to decide which browser you are going to use and then launch. It will depend on various factors like application compatibility, feature/behaviour to test etc.

Note that Browser must be configured appropriately to work with LeanFT. Refer to our post on Browser Extensions and Settings

In this example, we are going to use the Chrome browser and will navigate to the new tour’s website. We will use BrowserFactory Method to do this.

public void MyFirstTest() throws GeneralLeanFtException {
Browser browser = BrowserFactory.launch(BrowserType.CHROME);
browser.navigate("http://newtours.demoaut.com/");

}

Extend Test to Include More Tests and Actions

Now we can extend our test to include more tests and operations to AUT. We have already seen Object Identification Center and Application model includes test objects in the test project. Using these we can now perform different operations as required.

When you defined the browser here, it becomes the top-level parent object and now you go down to the hierarchy of objects and create a test object as a child of the relevant parent object. Use OIC to determine a different set of properties to describe your object.

Use Describe method to create the child object.

MyVar = parentObject.describe(TestObjType.class, new TestObjTypeDescription.Builder()

.prop1(value1).prop2(value2).prop3(value3).build());

For example

browser.describe(Link.class, new LinkDescription.Builder()

.tagName("A").innerText("Business Travel @ About.com").build());

 

Run your LeanFT Test

Simply right-click on your test method and select the Run Test Method option

Run LeanFT Tests

run the test using Maven:

To run your tests locally, you need to compile your project and then use either your testing framework’s runner like NUnit or JUnit, to run your compiled .dll or .jar, or any other relevant runner.

Step 1: In your project’s pom.xml file, Create a property for the test source directory:

<properties>

<test.src.dir>src/test/java</test.src.dir>

</properties>

Under the build tag, add:

<testSourceDirectory>${test.src.dir}</testSourceDirectory>

Create a LeanFT profile:

<profiles>

<profile>

<id>leanft-test</id>

<properties>

<test.src.dir>src</test.src.dir>

</properties>

</profile>

</profiles>

Step 2: Run mvn test –P leanft-test.

Run Results

When you run LeanFT tests created from a LeanFT project template, an HTML report is automatically generated. The report includes summary information about the run as well as detailed information about the captured steps.

To view the result, goto menu Option “LenFT> View Last Run Results”

See also  LeanFT Tutorial #2: Browser Extensions and Settings

LeanFT Run Results Menu

run result LeanFT

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.