Develop automated business scenarios like a pro with the Rational Functional Tester-TestNG framework
IBM Rational Functional Tester (hereafter referred to as RFT for brevity) is a testing tool by using which you can automate your interactions with any test application, say type some text in a text box, click on a button, hover over an image – with almost zero intervention from you, the user. That definitely sounds useful, but you might still often find yourself in situations where you look for functionality to accomplish more specific goals:
- I want to create a test case from a piece of code.
- I want to combine multiple tests into a test suite.
- I want to produce a detailed report of tests that passed/failed, which is also presentable and eye-candy.
- I want to prioritize test case execution and establish run time dependencies across test cases.
All that sounds familiar, doesn’t it? Here’s introducing the RFT-TestNG framework that will help you develop automated business scenarios like the ones listed above in a jiffy.
RFT – What is it?
RFT is an automated functional testing and regression testing tool that provides automated testing capabilities for functional, regression, GUI and data-driven testing. It supports a range of applications, such as web-based, .Net, Java, Siebel, SAP, terminal emulator-based applications, PowerBuilder, Ajax, Adobe Flex, Dojo Toolkit, GEF, Adobe PDF documents, zSeries, iSeries and pSeries.
TestNG – What’s in it for you?
TestNG is an open source next generation test automation framework that simplifies a wide range of your testing needs, from unit testing to integration and functional testing.
What features does TestNG have to offer?:
The RFT-TestNG framework
With the RFT-TestNG framework, you can:
- Basic knowledge of RFT, TestNG, and the Java programming language, and program execution.
- Basic understanding of software testing processes.
- An internet connection on the computer on which you are setting up the framework.
1. Install RFT. For instructions, see Installing Rational Functional Tester.
2. Install TestNG.
a) Open RFT. Click Help > Install New software.
b) Copy the following URL: http://beust.com/eclipse and paste it into the Work with text box and click Add.
c) In the “Add Repository” dialog, enter a name for the repository and click OK.
d) In the left pane, click TestNG to expand it.
e) Select the TestNG check box.
f) Click Next, and then Finish.
g) Restart RFT.
3. To verify the installation, open Window > Preferences. Verify that TestNG is listed in the left pane.
4. Create an RFT project and record or write test scripts as needed. For details, see RFT Knowledge Center.
5. Update the properties of the new RFT project to include the TestNG libraries:
a) Right-click the project and select Properties.
b) In the Properties window, select Java Build Path.
c) Open the Libraries tab.
d) Click Add Library.
e) In the "Add Library" dialog, select TestNG.
f) Click Next and then click Finish.
OK, with that step, you are done with the setup of the framework. Now let’s see how to put the framework into use.
As mentioned in the beginning of this blog, one of the primary advantages of using the RFT-TestNG framework is the ease with which you can create and run test suites from multiple different RFT script classes by using just a single configuration file (testng.xml).
1. Open the RFT project and create an XML file called testng.xml. This file describes the runtime definition of the test suite. This is also where you will configure your test runs, set test dependencies, include or exclude any tests, methods, classes or packages, set priorities, and so forth.
2. Copy all your RFT test scripts classes into the <classes> tag in testng.xml. By doing this, you ensure that only those tests that are listed in testng.xml are executed.
You are free to name the <suite> tag and the <test> tag based on your preferences, but the name of the <classes> tag must be a combination of the name of the package and name of the RFT test script.
Following is an example of the testng.xml file
3. Update the RFT test scripts with the TestNG annotations:
The RFT-TestNG framework does not execute automation code that’s part of the RFT’s testMain() method. Hence, ensure that all the executable automation code in the RFT test scripts lie outside of the testMain() method, but included in other public java methods. Then, annotate the RFT script class methods with @Test.
Note: TestNG allows execution of only those Java methods in the RFT scripts that are annotated by @Test. To use annotations in TestNG, you must import the org.testng.annotations.* package into the RFT script class. Also ensure that you add all these script classes into the <classes> tag in testing.xml.
4. To execute a test suite in the RFT-TestNG framework, you need a driver script. To create a driver script, copy the following code snippet into the testMain method in an empty RFT script:
When you start the execution, the TestNG classes are initialized and point to testing.xml which will in turn run the test suite.
An example RFT-TestNG project
This blog also presents an example project (RFTProject_inside_TestNG.zip) for your reference. Follow these steps to playback any test suite in the RFT-TestNG framework:
1. Download RFTProject_inside_TestNG.zip and extract it.
2. Open RFT and switch to the Functional Test perspective.
3. Click File > Import > Functional Test > Functional Test Project Items.
4. Click Next.
5. Navigate to the project you extracted in Step 1 (RFTProject_inside_TestNG.rftjdtr) and open it.
6. Click Next and then Finish to finish the import.
7. Verify that TestNg_RFT_Integration_Project is loaded into RFT along with the following RFT script classes:
NAVANIT K SINGH
Software Test Architect
Navanit K Singh is a Software Test Architect who is currently working on Rational Functional Tester and Rational Test Web UI Tester.
He has more than 11 years of experience in the software industry.
Principal Technical Writer
Shivi is a senior technical writer who has more than 13 years of experience in the software industry. She's currently a member of the Integration Tester project team and works out of the HCL office in Bengaluru.