Dependencies with TestNG

‘TestNG’ is a framework that built with different set of APIs that facilitates many testing needs. It has variety of features that makes ‘TestNG’ more convenient than ‘JUnit’ framework. Among all the features, TestNG has ‘dependencies’ feature that gives the facility to determine the @Test annotation methods order. For the dependencies, TestNG uses ‘dependsOnMethods’ option for @Test annotation.

Hold on, should not confuse with ‘order’ word. I do not have meant that with this feature you could create your own order to run the Test methods.

TestNG dependency feature does not give guarantee on the order on which the methods depended upon will be run, however it guaranteed that TestNG will run all the @Test methods before the method which contains the ‘dependsOnMethods’ option.

In TestNG, we can achieve dependencies in two ways-

  • With Annotation.
  • With XML

It has two types also-

  • Hard Dependency
  • Soft Dependency

Hard dependency says that if depended upon @Test method fails then TestNG will skip the depended @Test method.

Soft dependency says that TestNG will run the depended @Test method if depended upon @Test methods fails also, however depended @Test method should have ‘alwaysRun=true’ option.

Hard Dependency Instance:

import org.testng.annotations.Test;

public class dependsOnMethods {

@Test

public void sub (){

int a = 7-3;

System.out.println(“sub “+a);

}

@Test (dependsOnMethods={“sub”})

public void div (){

int a = 10/2;

System.out.println(“div “+a);

}

@Test

public void add (){

int a = 7+3;

System.out.println(“add “+a);

}

}

[TestNG] Running:

C:\Users\testng-eclipse-224652221\testng-customsuite.xml

add 10

sub 4

div 5

PASSED: add

PASSED: sub

PASSED: div

TestNG runs all the @Test methods before the ‘div’ method.

Soft Dependency Instance:

import org.testng.annotations.Test;

public class dependsOnMethods {

@Test

public void sub (){

int a = 7-3;

System.out.println(“sub “+a);

}

@Test (alwaysRun= true, dependsOnMethods={“sub”})

public void div (){

int a = 10/2;

System.out.println(“div “+a);

}

@Test

public void add (){

int a = 7+3;

System.out.println(“add “+a);

}

}

TestNG will run the ‘div’ method if ‘sub’ methods fails also.

With Annotation Instance:

import org.testng.annotations.Test;

public class dependsOnMethods {

@Test

public void sub (){

int a = 7-3;

System.out.println(“sub “+a);

}

@Test (dependsOnMethods={“sub”})

public void div (){

int a = 10/2;

System.out.println(“div “+a);

}

@Test

public void add (){

int a = 7+3;

System.out.println(“add “+a);

}

}

‘div’ method is depended upon the ‘sub’ method. So whenever TestNG runs this class, all methods will run before the ‘div’ method.

[TestNG] Running:

C:\Users\testng-eclipse-224652221\testng-customsuite.xml

add 10

sub 4

div 5

PASSED: add

PASSED: sub

PASSED: div

With XML Instance:

To achieve dependency with XML, we should have testing.xml file. In testing xml file we can specify our group dependency with tag.

<test name=”regression suite”>

<groups>

<dependencies>

<group name=”sanity”/>

<group name=”functional” depends-on=”Sanity” />

<group name=”integration” depends-on=”Sanity  functional” />

</dependencies>

</groups>

</test>

The <depends-on> attribute contains a space-separated list of groups.

How to configure Selenium WebDriver

To configure the selenium on your system, follow the below given steps-

  • Java should be installed on your system.

Java

Eclipse

Eclipse1

  • Create a java project.

JavaEE

  • Select Java Project > Click on Next button > Enter Gmail in Project Name edit field. > Click on Next button > Click on Finish button.

Eclipse2

  • Now configure the Selenium WebDriver API with your Gmail project.
  • Select the Gmail project and right click > Select Build Path > Click on Configure Build Path…>Click on Add External JARs… button > Browse the extracted Selenium folder and include all Executable Jar file > Click on OK button.

Project

  • Now selenium is configured with your java project.
  • Create a Login class.

Class

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Login {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

WebDriver browser;

browser = new InternetExplorerDriver ();

browser.get(“http://www.gmail.com&#8221;);

}

}

Script

  • Press ctrl+f11.
  • Now you are ready to write your own code to automate your web application.

How to Launch IE browser with Selenium WebDriver on Windows 7

Steps:

 SEL

  • Add the path of downloaded zip file in Environment Variable.
  • Sub Steps: Start > Computer (Right Click on it) > Click on ‘Properties’ > Click on Advanced system settings > Click on ‘Environment Variable’ button > Click on ‘New’ button which displays under ‘System variables’ > Give Variable name: webdriver.ie.driver > Give full path of downloaded IE Driver Server folder in ‘Variable value’ > Click OK > Click OK > Click OK.

EV

  • Open IE Browser > Tools > Internet Options > Security > Check the Enable Protected Mode (require restarting Internet Explorer) check box.

Now we can open IE browser with the help of Selenium WebDriver.

QTP Virtual Objects

Most of QTP users are very familiar with Virtual Objects because it solves unrecognized application objects problem. Sometime we work with those applications that have different types of objects but tool does not recognize and support those objects as object. So for this kind of problem every successful tool provides the facility to recognize those objects as Virtual Object.

QTP tool is also providing same and easy steps to define the Virtual Object. Basically we used Virtual object functionality when tool does not support any application object as object.

As we discussing Virtual Object in respect to QTP tool, there some important points which should get the notice by every QTP users.

Point 1: Define the Virtual Object size and position in the web page by using the crosshairs pointer.

Point 2: During a run session make sure that application window should come in same size and same location. May be it effect the coordinates of virtual object.

Point 3: We can not insert any checkpoints for virtual object.

Point 4: We can not use Object Spy for virtual Object.

Point 5: We can use Virtual Object only in recording and running session.

Point 6: Virtual objects store in the computer, not only for current test.

Point 7: We can define the virtual object only for those object in which, we can click or double click.

We can see the all defined virtual objects with the help of Virtual Object Manager window. Basically it list out the all created virtual objects. We can delete or disable the objects with the help of Virtual Object Manager and Options windows. Virtual Object Manager window provide the facility to delete the objects after selecting them and if you want tool should keep the objects but don’t recognize, for that you have to check the option “Disable recognition of virtual objects while recording” in Tool > Options window.

I think these are the basic and important points for those who want to use Virtual Object feature in QTP and if I’m missing something please update with your valuable comments

QTP Test Object Model

To understand Test Object Model we can break it in three different terms, that are-

Object

Test Object

Test Object Model

Object, one of the units of your application.

Test Object, If QTP performs any operation on application Object and stores it for testing then we called it Test Object.

Test Object Model, QTP contains large set of Object types that it uses to recognize the application object.

I think now we can discuss about it in details. QTP uses this concept to tell the QTP engine that how tool will record the Object and Object Operation of the application. As I said that Test Object Model is large set of Objects which it uses to understand the objects but how QTP recognize the Object as Test Object and how it know that what type of operation tool has performed over the Object. For that QTP have different types of Class that represent the each and every Test Object of QTP. We can describe the Class mean like Four Wheeler is the class but different Cars are the object of the “Four Wheeler”. So classes are having different type of Properties and Methods that Test Objects uses to simulate the application objects.

Basically Properties use to recognize the type of Objects and Methods use to recognize the performed operation over the Object. So with the help of Properties and Methods QTP understand the application objects and performed action which are done by Tester and recorded by QTP.

So in simple word QTP uses Test Object Model to recognize the objects of the application.

QTP Shortcut Keys

My first CTO says that if you want to be smart user of the system, use shortcut keys to handle your system. So I thought that why should not post the list of QTP shortcut keys for QTP users

May be in these most of shortcut keys are common for most of guys but here most of guys are still newbie in QTP.

Ctrl + N- Creates a New Test

Ctrl+Shift+N- Creates a New Business Test

Ctrl+Alt+N- Creates a New Application Area

Shift+Alt+N- Creates a New Function Library

Ctrl+O- Opens an Existing Test

Ctrl+Shift+O- Opens an existing business component

Ctrl+Alt+O- Opens an existing Application Area

Shift+F2- Rename the Action name

Ctrl+M- Make the comment on current row

Ctrl+Shift+M- Remove the comment

Ctrl+Space- Completes the word if you are typing any VBScript method or object in Expert View

F12- For Standard Checkpoint

Ctrl+F12- For Standard Output Values

F7- Step Generator

F8- New Step in Keyword View

Shift+F8- New Step after block of statement

F3- Recording

F4- Stop the Recording

F5- Run the Script

Ctrl+F5- Run the selected step in the script

Ctrl+R- Open the object repository

Shift+Alt+F3- Analog Recording

Ctrl+Shift+F3- Low Level Recording

F11- Step Into

F10- Step Over

Shift+11- Step out

Ctrl+F10- Run to Step

Ctrl+T- Adds the selected item in the Watch tab

Ctrl+F7- Check the Syntax error in the script.

Ctrl+Page Up or Page Down- Toggles between the Keyword and Expert View.

You can add more if I’m missing some shortcut keys.

QTP Testing Framework

To start the testing with QTP, there is an important concept to understand i.e. framework. Frameworks basically define the way to handle the different operations in different methods.

As we all known we can create the test in two ways in QTP i.e. by recording and by scripting. We should also know that how we can improve the quality of test by using Framework concept. Basically QTP supports three kind of framework i.e. Linear, Modular, and Keyword Driven Framework.

In all three frameworks, Linear Framework is very easy and catchy by all newbie and beginner of QTP. Basically Linear Framework deals with individual script which is recorded under one Action and running individual. I think we all done this thing in very first when we get the QTP but I’m very sure, not all one know that we created and executed the test under Linear Framework. Anyway this is not big deal. I was also not aware when I get the QTP first time. So this is very simple and easy way to create the test by navigating through the application. But by using this method there are some limitations which we can not cross. Sometime when we test some business processes in one application, we may feel that some operations we repeat in all Linear Framework Script. To handle this situation we go with Modular Framework which solves this kind of problem by dividing the single test in multiple part or module.

In modular framework, tester basically divides the test in different parts which give the facility to use the different part of scripts in any tests. That solves the many problem of repeataion of test and gives the facility to make the script reusable? So in one sentence, Division of Linear Framework script in different parts called Modular Framework.

To understand the keyword driven framework, tester should know the basic of programming because it deals with function. In programming, Function is an important part of programming as they allow you to create chunks of code that performs a specific task. Basically we create the functions in the one test and calling these functions as keyword in other tests therefore we are calling keyword driven framework. This is very important and useful framework to deal and handle many critical tasks in testing through QTP.

To know these frameworks in more details you can choose any QTP testing materials.