LeanFT Java Tutorial Part 1 – Introduction

If you are looking for a basic overview of LeanFT, You can check out my post here.

This tutorial will basically get you started with the tool and further things will be covered after that. You will notice that LeanFT uses more or less the same concepts that UFT does but with a better IDE and a cleaner approach.

In case you don’t have LeanFT installed on your machine, you can follow the instructions mentioned in my post here.

Once the installation is sorted, when you launch Eclipse, you will notice that the LeanFT Runtime Engine will start running. The engine needs to be running whenever we want to use LeanFT as all communication goes through it.

Before jumping onto Test script creation, you need to be familiar with a unit testing framework called JUnit. In case you’re not, you can refer to this link. Once you’re done, you can create your first script.

For creating a new Project, go to File->New->Other, you should see a folder for LeanFT. Inside the folder, following types of projects available to you:-

  1. LeanFT Application Model Item – An application model is LeanFT’s way of saying Object Repository(referring to UFT concept here). You should create this project if you want to create a collection of objects of your AUT (read Application under test). You need to choose this whenever you have an existing project and you want to add just a Model class to it.
  2. LeanFT Application Model Project – Contrary to Application Model Item, the Project needs to be created if we want multiple LeanFT projects to share an Application Model. This is on the same lines of Shared Object Repository in UFT whereas Application Model Item is like a Local Object Repository in UFT.
  3. LeanFT JUnit Data Driven Test Case – This will create a new class which uses the Data Driving feature of JUnit. You can use this if you want to fetch your data set from Excel/ALM and then want to run a method iteratively on the set of Data.
  4. LeanFT JUnit Project – This is a JUnit Test project which can have multiple test methods. We’ll be using this as part of this tutorial.
  5. LeanFT JUnit Test Case – If you want to create just a Test case rather than Project, then use this option.

Once you create a new JUnit project, it should look something like :-


package l2a;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import com.hp.lft.sdk.*;
import com.hp.lft.verifications.*;
import unittesting.*;

public class LeanFtTest extends UnitTestClassBase {

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

 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
 instance = new LeanFtTest();
 globalSetup(LeanFtTest.class);
 }

 @AfterClass
 public static void tearDownAfterClass() throws Exception {
 globalTearDown();
 }

 @Before
 public void setUp() throws Exception {
 }

 @After
 public void tearDown() throws Exception {
 }

 @Test
 public void test() throws GeneralLeanFtException {
 
 }

}
 

Lets look at the code line by line and understand it. Firstly, we are giving the name of the package(“l2a”) which states that the class that we are about to declare belongs to this package. After that, we are importing some classes and packages that will help us work with LeanFT and JUnit.

Then comes the definition of our class – “LeanFtTest”. This class is extending a class called “UnitTestClassBase” which is provided by HP. Please note that since this is a template provided by HP, a lot of things are already setup for you. So basically this class would help you in getting your LeanFT SDK initialized(and some other operations at the backend) which you don’t need to handle yourself.

Then comes the constructor for our class which is left for us to implement in case we need it. As of now, we can just leave it as it is.

After that, we have the @BeforeClass annotation which denotes that the method succeeding this annotation will be run once before  any of the test methods execute. In the method that follows, HP has done some activities that will setup your LeanFT SDK and initialize your LeanFT Report.

Similar to @BeforeClass, the @AfterClass annotation denotes that the method following it will execute once after all the test methods have executed. Here, the SDK is cleaned up and the Report is generated inside the current working directory within a folder called RunResults.

@Before annotation is used to declare a method that will run each time before a Test Method is executed and similarly goes the @After annotation which runs each time after a Test Method is executed.

@Test annotation denotes that the following method is a Test Method(you can also think of it as a Test Case). This will contain your test logic.

Note that we can use this template to automate any types of application that LeanFT supports – Web, Java,.NET, Windows and many more.

Now since we are familiar with the structure of the JUnit project template, we are in a position to write our first Web automation script which we’ll be covering in the next post.

LeanFT Java Tutorial Part 2 – Create First Test

Happy Automating !

Harshit Kohli

Advertisements

Eat, Sleep, Automate. REPEAT !

Tagged with: , , , , , ,
Posted in LeanFT
3 comments on “LeanFT Java Tutorial Part 1 – Introduction
  1. […] In case you missed on part 1, check it out here. […]

  2. […] Check out my LeanFT Java Tutorial ! […]

  3. […] If you are searching for the Java Tutorial and landed on this page, please click this link. […]

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 )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog Stats
  • 168,130 hits
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 796 other followers

%d bloggers like this: