Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Extending IBM Rational Functional Tester with Open Source Tools: Part 2: Database test automation

Scripting against SQuirreL SQL

Daniel Gouveia (dgouveia@us.ibm.com), Software Technical Sales Specialist, IBM 
Dan Gouveia is a sales engineer for IBM, primarily focusing is on Rational’s functional and performance testing tools. He works with customers on implementing these tools in the most effective manner, often dealing with topics such as keyword-driven testing, developing automation frameworks, etc.

Summary:  The typical scenario to test the database side of your application is to perform some sort of insert or delete action within your application, and then verify that the database was properly updated. Because IBM® Rational® Functional Tester does not provide a native means to work with databases, SQuirreL SQL is a great tool to satisfy your database testing needs. It is an open-source tool written in Java™, which makes it an ideal candidate for Rational Functional Tester’s record and playback automation capabilities. Part 1 of this series showed you how to set up Rational Functional Tester, and this part will help you create and bundle scripts.

View more content in this series

Date:  26 Dec 2007
Level:  Intermediate
Also available in:   Chinese  Vietnamese

Activity:  4639 views
Comments:  

Database testing

Many testers are interested in testing the database-side of their application. The typical scenario is that you perform some sort of insert or delete action within your application, and then verify that the database was properly updated. As test groups turn towards automation, this database testing becomes a natural desire. Unfortunately, IBM® Rational® Functional Tester does not provide a native means to work with databases.

SQuirreL SQL is a great tool to satisfy your database testing needs. Upon hearing this, you may develop a sudden case of "Yet Another Tool Syndrome". After all, it is in fact another tool that you do need. The good news is that it is an open-source tool. This gives you the ability to download and use this tool for free. Further, it does provide a level of support, in case you run into issues with the tool. Lastly, it is written in Java™. This makes it an ideal candidate for Rational Functional Tester’s record and playback automation capabilities.

This article represents an adaptation of a "getting started" tutorial that has helped customers adopt the use of SQuirreL SQL into their Rational Functional Tester automation. SQuirreL SQL provides a plethora of functionality for the aspiring database-guru. Nonetheless, the intent of this article is to keep things simple while ensuring that it conveys certain key concepts, such as running a query and verifying the result-set. It does not address the numerous remaining capabilities, leaving them for the exploration of inquiring minds like yours.

You should find the following article useful. For added clarity, the scripts that get created in this article are available for your perusal. You can download them from the table at the end of this article.

Please note that you should have Rational Functional Tester experience (at least record and playback) before performing the exercises in this article.

Part 1 of this series showed you how to configure Rational Functional Tester for these scripting functions. This article will show you how to create and bundle scripts. This article assumes that you have completed the steps detailed in Part 1.


First things first: the prerequisites

Before getting started, make sure that you have Rational Functional Tester installed, licensed, and ready to run! This is pretty obvious, but quite critical for you to successfully complete the tasks in this article.


Database test automation: Scripting against SQuirreL SQL

The following steps will take you through creating four scripts. The first three scripts are focused on specific SQuirreL SQL tasks. The last script is the shell script, aggregating the three scripts to execute in sequence.

First script

Record your first script against SQuirreL SQL: the SQuirreL_SQL_Connect script.

  1. Click the Record button.
  2. Provide the name of the script and click the Finish button to begin recording, as shown in Figure 1.

Figure 1. Provide a location and name for the script
window to record a script recording toolbar
  1. Select the Start Application button, select squirrel-sql – executable as your application, and click the OK button, as shown in Figure 2.

Figure 2. Select the application
window to select application
  1. Double-Click the Classics Database alias (in the SQuirreL SQL window), as shown in Figure 3.

Figure 3. Select an alias
window with overlaid sub-windows
  1. Click the Connect button (again, no User name or Password is needed, as shown in Figure 4).

Figure 4. Connect to the database
window to connect to the database
  1. Click Stop Recording button in Rational Functional Tester.

You should now have a script that looks similar to that shown in Listing 1.


Listing 1. Recorded SQL Connect script
                
import resources.SQuirrel_SQL_ConnectHelper;

/**
 *  Description		: XDE Tester Script
 *  @author	IBM Rational
 */
public class SQuirrel_SQL_Connect extends SQuirrel_SQL_ConnectHelper
{
/**
 *  Script Name		: SQuirrel_SQL_Connect
 *  Generated			: Jun 20, 2007 9:51:08 AM
 *  Description		: XDE Tester Script
 *  Original Host		: WinNT Version 5.1 Build 2600 (S)
 *
 *  @since 	2007/06/20
 *  @author	IBM Rational
 */
public void testMain (Object[] args)
{
		startApp(“squirrel-sql”);
	
			// Frame :  SQuirrel SQL Client Version 2.5
		listOfDatabaseAliasesThatCanBe().doubleClick(atText(“Classics Database”));
		connect().click();
}
}

Second script

Record your next script against SQuirreL SQL: the SQuirreL_SQL_Simple_Query script.

  1. Provide the name of the script and click the Finish button to begin recording it, as shown in Figure 5.

Figure 5. Begin recording your script
window to record a script recording toolbar
  1. Select Session > New SQL Worksheet, as shown in Figure 6.

Figure 6. Opening a new SQL worksheet
window showing session menu
  1. Click in the SQL edit field and enter SELECT * FROM ORDERS, as shown in Figure 7.

Figure 7. Entering the SQL command
blank window to enter code

Note: You may need to maximize your window and resize the RESULTS pane.

  1. Click the Run SQL button (also shown in Figure 7).
  2. Initiate the Verification Point and Action wizard, as shown in Figure 8.

Figure 8. Select an object
window with drop-down menu
  1. Use the Object Finder tool to select the result-set in the SQuirreL SQL window, as shown in Figure 9.

Figure 9. Select the result-set
window with table
  1. Select Table Contents for the Data Value, provide VerifyOrdersResultSet for the Verification Point Name, and then click the Next button (as shown in Figure 10).

Figure 10. Insert a verification point
window with verification point details
  1. Select the first 5 columns (for data to test) and click the Finish button, as shown in Figure 11.

Figure 11. Select data to test
window with selected table data

Note: Make sure that you have chosen Column Selection in the drop-down list. You can then select the first column (that is, click the first cell of data) and drag to the right.

  1. Click the Stop Recording button in Rational Functional Tester.

You should now have a script that looks similar to that shown in Listing 2.


Listing 2. Recorded Simple Query script
                
public class SQuirrel_SQL_Simple_Query extends SQuirrel_SQL_Simple_QueryHelper
{
/**
 *  Script Name		: SQuirrel_SQL_Simple_Query
 *  Generated			: Jun 20, 2007 9:54:46 AM
 *  Description		: XDE Tester Script
 *  Original Host		: WinNT Version 5.1 Build 2600 (S)
 *
 *  @since 	2007/06/20
 *  @author	IBM Rational
 */
public void testMain (Object[] args)
{

			// Frame :  SQuirrel SQL Client Version 2.5
		mainFrameMenuBar().click(atPath(“Session”));
		mainFrameMenuBar().click(atPath(“Session->New SQL Worksheet”));
		justToMakeGetToolTiptextToBeCa().click(atPoint(30,9));
		mainFrame().inputKeys(“{CAPSLOCK}SELECT * FROM ORDERS”);
		runSQLControlENTER().click();
		VerifyOrdersResultSetVP().performTest();

}
}

Note: Depending on the version of Rational Functional Tester that you are using, your verification point line may look like the following:
dataSetViewerTablePanelMyJTabl().performTest(VerifyOrderResultSetVP());

Third script

Record your final script against SQuirreL SQL: the SQuirreL_SQL_Closescript.

  1. Provide the location and name of the script, then click the Finish button to begin recording, as shown in Figure 12.

Figure 12. Start recording
window to record a script recording toolbar
  1. In SQuirreL SQL, select File > Exit, as shown in Figure 13.

Figure 13. Exiting SQuirreL SQL
window showing file menu
  1. Click the Yes button in the confirmation dialog, as shown in Figure 14.

Figure 14. Confirm that you want to close the session
window to close the session
  1. If you receive the "unsaved changes" dialog shown in Figure 15, just click No.

Figure 15. Do not save changes
window to confirm save changes
  1. Click the Stop Recording button in Rational Functional Tester.

You should now have a script that looks similar to that in Listing 3.


Listing 3. Recorded SQL Close script
                
public class SQuirrel_SQL_Close extends SQuirrel_SQL_CloseHelper
{
/**
 *  Script Name		: SQuirrel_SQL_Close
 *  Generated			: Jun 20, 2007 10:01:03 AM
 *  Description		: XDE Tester Script
 *  Original Host		: WinNT Version 5.1 Build 2600 (S)
 *
 *  @since 	2007/06/20
 *  @author	IBM Rational
 */
public void testMain (Object[] args)
{

			// Frame :  SQuirrel SQL Client Version 2.5
		mainFrameMenuBar().click(atPath(“File”));
		mainFrameMenuBar().click(atPath(“File->Exit”));
		
		
			//
		yes().click();

			//
		no().click();

}
}

Fourth script

Tying it all together, create the shell script: SQuirreL_SQL_Shell.

  1. Right-Click your project in the Functional Test Project view in Rational Functional Tester, and then select Add Empty Script as shown in Figure 16.

Figure 16. Adding an empty script
menu to add script
  1. Provide a location and name for the script, and then click Finish, as shown in Figure 17.

Figure 17. Start recording an empty test script
window to provide empty script details
  1. Create a new line after // TODO Insert code here // and click the empty line to place the cursor there.
  2. Right-Click each of your SQuirreL SQL scripts in turn and choose Insert As callScript to add them to your new shell script, as shown in Figure 18.

Note: Be careful to add the scripts in the desired order.


Figure 18. Inserting scripts into your shell
window with tabbed frames

Note: Be careful to add the scripts in the desired order.

You should now have a shell script that looks similar to that shown in Listing 4.


Listing 4. Completed SQL shell script
                
import resources.SQuirrel_SQL_ShellHelper;

/**
 *  Description		: XDE Tester Script
 *  @author	IBM Rational
 */
public class SQuirrel_SQL_Shell extends SQuirrel_SQL_ShellHelper
{
/**
 *  Script Name		: SQuirrel_SQL_Shell
 *  Generated			: Jun 20, 2007 10:09:19 AM
 *  Description		: XDE Tester Script
 *  Original Host		: WinNT Version 5.1 Build 2600 (S)
 *
 *  @since 	2007/06/20
 *  @author	IBM Rational
 */
public void testMain (Object[] args)
{
		callScript(“SQuirrel_SQL_Connect”);
		callScript(“SQuirrel_SQL_Simple_Query”);
		callScript(“SQuirrel_SQL_Close”);
	
}
}


Showtime! Playing back the scripts

Now that you have created your SQuirreL Scripts, it is simply a matter of playing them back. A couple of things to note:

  • When playing back scripts, you may notice some timing issues. Simply get around these by adding waitForExistence() method calls to certain objects. For instance, in the first script, add it to the database alias object. The line of code that I use looks like the following:

    listOfDatabaseAliasesThatCanBe().waitForExistence();
  • You may need to add synchronization into your other two scripts. Basically, you want to make sure that if the first script leaves SQuirreL SQL processing data, the second script will wait until it is finished.

Closing Thoughts: Where To Go From Here

It will benefit you to explore the extensive capabilities that SQuirreL SQL offers you. If the simple functionality you looked at today will suffice for you, all the better. However, you will probably find that there are some great things that you can do with this tool. What makes things nicer is that you will be able to automate the things you find using Rational Functional Tester.

As an automation engineer, you do not create test projects focused solely on database testing (unless, of course, that is all that you are doing). Instead, you wrap this kind of automation into your application scripting. There are a few ways that you can do this.

  • One way is to make these scripts generic methods, meaning that they can pass in a variety parameters (such as SQL query strings) and dynamically verify the result set. You can then create custom Super Helper Classes and put these generic methods in them. This allows you to simply call the necessary method (for example to query on a table) from your test scripts.
  • Another, perhaps easier, way is to simply keep these as scripts. You should still make them generic (for instance, accepting different parameters, and so on), but they are called from shell scripts (similar to the shell script you created in this exercise).

How you do these things is entirely up to you. The end result in any case is that you now know how to successfully automate your database testing with Rational Functional Tester and SQuirreL SQL.



Download

DescriptionNameSizeDownload method
Scripts to accompany the articlesquirrel-sql-scripts.zip15KBHTTP

Information about download methods


Resources

Learn

Get products and technologies

Discuss

About the author

Dan Gouveia is a sales engineer for IBM, primarily focusing is on Rational’s functional and performance testing tools. He works with customers on implementing these tools in the most effective manner, often dealing with topics such as keyword-driven testing, developing automation frameworks, etc.

Report abuse help

Report abuse

Thank you. This entry has been flagged for moderator attention.


Report abuse help

Report abuse

Report abuse submission failed. Please try again later.


developerWorks: Sign in


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

Choose your display name

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


Rate this article

Comments

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=278362
ArticleTitle=Extending IBM Rational Functional Tester with Open Source Tools: Part 2: Database test automation
publish-date=12262007
author1-email=dgouveia@us.ibm.com
author1-email-cc=rjbence@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

For articles in technology zones (such as Java technology, Linux, Open source, XML), Popular tags shows the top tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), Popular tags shows the top tags for just that product zone.

For articles in technology zones (such as Java technology, Linux, Open source, XML), My tags shows your tags for all technology zones. For articles in product zones (such as Info Mgmt, Rational, WebSphere), My tags shows your tags for just that product zone.

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.

Special offers