Enhance IBM Rational Functional Tester (RFT) with U.I Java Classes
5 comments Published by adel on Saturday, February 23, 2008 at 2:27 PMDisclaimer: This post is related to IBM Rational Functional Tester With Java. It needs some slight modifications to work with other tools.
Sometimes, your automated test script needs to do some strange stuff. Like accessing the database, extracting some value and using this value in subsequent U.I steps in your script.
Suppose that you have hundreds of scripts that needs the following block to access the DB and read a certain value:
try{What if the username and password is changed after a period of time for a certain reason. This means that you need to modify all your scripts and change the credentials. And this could be a pain and very time consuming.
Connection db_connection = DriverManager.getConnection("jdbc:odbc:DBNAME",
"username","password");
Statement stm2 = db_connection.createStatement();
stm2.executeQuery("select * from TableName");
}
catch( SQLException x ){
JOptionPane.showMessageDialog(null,
x.getLocalizedMessage().toString(),"Error",
JOptionPane.ERROR_MESSAGE);
}
A good practice is creating a class that will prompt the user to enter the credentials and validates them before running the script. This will save time and headache in subsequent releases.
The following is the code for the class with the proprietary information removed:
import javax.swing.JOptionPane;
import resources.SendValidUNandPWHelper;
import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
/**
* Description : Functional Test Script
* @author Ashehadeh
*/
class SendValidUNandPW extends SendValidUNandPWHelper
{
/**
* Script Name : CheckDBDialog
* Generated : Feb 19, 2008 8:31:06 AM
* Description : Functional Test Script
* Original Host : WinNT Version 5.1 Build 2600 (S)
*
* @since 2008/02/19
* @author Ashehadeh
*/
/**
* @param args
*/
public String[] sendValidCredentials(){
String[] result=null;
String[] k =validateInput();
while (k==null){
k= validateInput();
}
return k;
}
//check if the provided credential can access the DB
public static String[] validateInput(){
String[] result=null;
String[] k =isDBonline();
if (k==null){
result =null;
System.exit(0);
}
else {
try{
Connection db_connection = DriverManager.getConnection("jdbc:odbc:DBNAME",k[0],k[1]);
Statement stm2 = db_connection.createStatement();
stm2.executeQuery("select * from TABLEName");
result =k;
}
catch( SQLException x ){
JOptionPane.showMessageDialog(null,
"Please Enter correct Uasername/Password!","Error",
JOptionPane.ERROR_MESSAGE);
/* JOptionPane.showMessageDialog(null,
x.getLocalizedMessage().toString(),"Error",
JOptionPane.ERROR_MESSAGE);*/
result=null;
}
}
return result;
}
//check if the db is online from the first place
public static String[] isDBonline(){
String[] result=null;
String[] k =isOneEmpty();
if (k==null){
result =null;
System.exit(0);
}
//now check for DB connectivity
else {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
result =k;
}
catch(ClassNotFoundException c){
JOptionPane.showMessageDialog(null,
"DB Unavailable!","Error",
JOptionPane.ERROR_MESSAGE);
result=null;
System.exit(0);
}
}
return result;
}
//is one of the fields empty? if so, exit
public static String[] isOneEmpty(){
String[] k=showDialog();
String[] result;
// if one of the username or passwords are empty, exit.
if (k[0]==null || k[1].equals("") ||
k[1].equals("") || k[1]==null){
JOptionPane.showMessageDialog(null,
"Error. Fill the two fields. Click ok to exit!","Error",
JOptionPane.ERROR_MESSAGE);
result=null;
System.exit(0);
}
//if both of them are not empty continue
else{
result=k;
}
return result;
}
//prompt the user for username and password
public static String[] showDialog() {
String DBUsername=JOptionPane.showInputDialog(null,
"Enter DB username:", "Input", JOptionPane.QUESTION_MESSAGE);
String DBpassword=JOptionPane.showInputDialog(null,
"Enter DB password:", "Input", JOptionPane.QUESTION_MESSAGE);
String[] UPArray={DBUsername,DBpassword};
return UPArray;
}
}
Test 842: Rational Functional Tester for Java
1 comments Published by adel on Monday, December 31, 2007 at 12:22 PMToday i passed IBM Test 842 for RFT. The exam was not easy. You have to be very familiar with the tool. The questions difficulty varies very much from a question to another. And a knowledge in regular expressions helps a lot.
I cant' really say more since you have to sign on non-disclosure agreement prior to the exam. However, you can study the online course, which you have to buy of course or take the instructor led course.
What i really didn't like is that the online course does not guarantee you to answer all exam questions, since it's explicitly mentioned in some chapters that you have to take the instructor led course if you want to know a certain procedure. I think this is not fare :(
There's an easier way if you want to pass the exam. It's by looking at some virtual exams engines like pass4sure. You may achieve a 99% score, but you'll guarantee your failure in the first job interview.
Just for the record: I personally think that certifications are ridiculous. :)
A regular expression to verify the date format mm/dd/yy
0 comments Published by adel on Sunday, October 21, 2007 at 2:42 PM([1-9]|1[012])/([1-9]|[12][0-9]|3[01])/0[0-9]$
This will verify if the date is mM/dd/yy, where m is optional. Example: 9/21/07 or 11/21/07
(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d
This will verify if the date is mm/dd/yyyy. Example: 12/12/2007
getProperty and getPropertyFromMap methods in RFT
0 comments Published by adel on Thursday, October 18, 2007 at 3:04 PMI have encountered a problem while using RFT. I needed the script to capture a value of an object and stores it in a string. It turned out that getPropertyFromMap and getProperty work not exactly the same.
getProperty will capture the most recent property value of the specified object. While
getPropertyFromMap will capture the property value at the time the object was added to the map.
Connect Quantum DB to RFT for IBM Iseries
1 comments Published by Abu Gaby on Tuesday, August 28, 2007 at 10:35 AMWe are using RFT to test a terminal based application running on an IBM Iseries
machine.For certain testing scenarios we need to access the database from within then script.Here's how you do it (Note that we are running RFT version 6 and eclipse 3.0 ) :
1- Activate RFT
2- Go To “Help” in the menu bar choose “Software Updates” then choose “find and install”.
3- Then choose “Search for new features to install and press next”.
4- Press on “New Remote Site” in the name type “Eclipse Update” and in the URL put this URL http://update.eclipse.org/updates/3.0/.
5- Do step 4 again and in the name type “Quantum” and in the URL put http://quantum.sourceforge.net/update-site.
6- Check them both and press the next button.
7- Install all the “GEF” and “Graphical Editing Framework” and the “Graphical Editing Framework SDK” that doesn’t produce dependencies error.
8- Install All the Quantum features
9- After you have completed the above steps open windows control panel à administrative tools à Data Sources (ODBC) .
10- In the System DSN tab, press on the add button, choose the iSeries Access ODBC Driver press finish.
11- In the Data Source Name type DB Name, then in the Server tab change the SQL Default Library to SLSQADATA and in the Packages Tab change the Package Library to SLSQADATA then press ok.
12- In the RFT go to the Windows menu in the menu bar à open perspective à others and choose Quantum DB.
13- When the Quantum Browser Loads press on the Add Bookmark.
14- Choose JDBC-ODBC Bridge press next and fill in the user id and password you use for your DB connection and in the Data Source field enter db name.
15- Press next and enter a name for the bookmark then press next leave the default choice of schema then click finish.
Now the connection is established between RFT and the Database Using a JDBC-ODBC bridge between the DB2 layer using the iSeries Navigator Driver and the RFT thus establishing the full connection.
How To Test for an Empty Database Table in RFT
0 comments Published by adel on Sunday, August 19, 2007 at 5:09 PMI used this script to test if a table in the database is empty or not. I am using IBM RFT
boolean found;
ResultSet result;
try{
Connection db_connection = DriverManager.getConnection("jdbc:odbc:DBNAME","USERNAME","PWD");
Statement stm2 = db_connection.createStatement();
result=stm2.executeQuery("your query");
found = result.next();
if (!(found))
logTestResult("Test Failed",false);
else
logTestResult("Test Passed",true);
}
catch( SQLException x ){
logError(x.getLocalizedMessage().toString());
}
Reference: http://www.rgagnon.com/javadetails/java-0116.html






