Changes challenge automated testing
The Internet and World Wide Web have become integral parts everyday life and business. Of course, most Web pages and Web applications that we see today are dynamic. Those changing pages make automating the testing of Web interfaces quite challenging. IBM® Rational® Functional Tester can help you automate tests even while the applications under test and the pages they link to continue to change.
Including actions on objects without adding to the object repository
Your test might include selecting random dates in a date-selection window. For the test to pass, the specific date chosen at random must be recognized. The date selection object shown in Figure 1 and the typical strategy of adding the links to the object repository poses problems:
- To click a date link, the date links must be added to the object repository; otherwise, no dates can be selected during the test run.
- If the chosen dates are random, then you need to add to the repository all 365 days as date links.
Adding all these dates would require that you spend your test-development time adding the links and filling with the object repository with hundreds of date links.
Figure 1. Date-selection window
A smarter solution for objects
Rather than relying on so many links, you can you create the objects dynamically and use them to include this date-selection window, plus include the possibility of using any date in a year. This also makes your script resilient enough to permit using different dates. This method does not require that you add any date objects to the object repository.
Important:
Unregister the dynamically created objects after you have used it and no longer need the object. Rational Functional Tester unregisters bound references when the entire playback ends, not when the script ends. When a bound reference to the object exists, Rational Functional Tester prevents the object in the application from being entirely free. If the object continues as unregistered, the garbage collector does not collect the object because Rational Functional Tester refers to it. This reference prevents the release of memory, which can lead to unpredictable behavior
To create the date-selection object dynamically, you need to see the properties of the object first:
- To add the object so that you can see the properties of the object, select 19 for 19 July 2009.
- Open the object repository of the script where you added the link. The properties are shown in Figure 2. The date link is shown as
javascript:dateHandler(%2019,7,2009%20);
Figure 2. The object map editor with the test object hierarchy and the object properties
You can use a regular expression for the date link, and determine the object at run time. In the Value column, type this value for the object: javascript:dateHandler(%20\\d+,\\d+,\\d+%20);The regular expression includes the 35 possible date links that are available in Figure 1. However, you need to add all possible dates in a year.
Note:
See the Rational Functional Tester Information Center for details about using regular expressions.
- Expand the regular expression to include all possible dates in a year (see Listing 1). By writing the regular expression this way, the test can accommodate any specific date.
Listing 1. Sample code for clicking the date link
public void clickReqDate(String date, String month, String year)
throws Exception{
RegularExpression dateHrefReProp = new
RegularExpression("javascript:dateHandler\\
(%20"+date+","+month+",\\d+%20\\);",true);
//Finding the object from the dialog which has properties of
//class as Html.A and href as dateHrefProp
TestObject [] dateObjs = find(atDescendant
(".class","Html.A", ".href", dateHrefReProp));
System.out.println(dateObjs.length);
//converting the testObject to GuiTestObject
GuiTestObject dateObj = (GuiTestObject)dateObjs[0];
dateObj.waitForExistence();
//getting the text property of the date at runtime.
String runtimeDate= (String) dateObj.getProperty(".text");
System.out.println("Date: "+runtimeDate);
//Comparing the String that is passed through the method with that of the
//date String that we got at runtime.
if(runtimeDate.equalsIgnoreCase(date)){
dateObj.click();
}
//unregistering of the object.
dateObj.unregister();
}
|
- Delete the object that you used to select the single date of 19 July 2009.
- For selecting the date of 19 July 2009, call the method with these parameters specified:
clickReqDate("19","7","2009"); - Unregister the object that you create dynamically, which is also good coding practice. See the final section of Listing 1 for the command to unregister the object.
Navigating to pages without filling scripts with links
Specifying navigation clicks can clutter a test script and waste your valuable time. For example, navigating to the page shown in Figure 3, requires that you click four to five links: Rational > Downloads > Plug-ins > Ready for Rational Plug-in Central. Your test would include the code in Listing 2. That code represents the navigation to one page. Consider how many pages users go to in applications under test.
Figure 3. Sample site showing the navigation
Listing 2. Links in a test script
link_rational().click(); link_downloads().click(); link_plugins().click(); link_rationalPluginCentre(); |
After selecting the final link, a tester might need to navigate to a similar link in WebSphere. The test requires clicking four to five additional links. Most of the script contains link coding.
A smarter solution for navigation
In a storage domain product that I currently work on, we spend most of the time navigating to different pages. If we follow the typical procedure of recording clicks in the test script, clicking the links would constitute 70% of the script code.
However, you can reduce the links in the script and create a resilient script that can function even as various sites are chosen. We created XML code that maintains the parent-child structure of the links and tabs. Furthermore, we developed a method to click the required link by getting the parent-child information for the link from the developed XML code.
The XML code for clicking the Ready for IBM Rational Plug-in Central link, as shown earlier in Figure 3, has the hierarchy shown in Listing 3.
Listing 3. XML code that shows the link hierarchy of a Rational Web page
<link_IBM_HomePage>
<link_rational>
<link_downloads>
<link_trialDownloads></link_trialDownloads>
<link_onlineTrials></link_onlineTrials>
<link_supportDownloads></link_supportDownloads>
<link_plugins>
<link_ibmPlugins></link_ibmPlugins>
<link_rationalPluginCentral></link_rationalPluginCentral>
<link_webspherePluginCentral></link_webspherePluginCentral>
</link_plugins>
</link_downloads>
</link_rational>
</link_IBM_HomePage>
|
In your test, suppose that you want to navigate to the Ready for IBM Rational Plug-in Central page. You would follow these steps:
- Create XML code that captures the hierarchy of links. (See Listing 3.)
- In your test script, use this method:
gotoPage("link_rationalPluginCentral");
Adding this single-line method replaces five link lines similar to those lines in Listing 2
The gotoPage(String) method first checks whether link_rationalPluginCentral is available on the current Web page. If the link is available, the method clicks the link. If the link is not available, the method checks for the parent of the object, link_plugins. If that page is not available, then the method checks for its parent, link_downloads, and so on up the hierarchy.
You do not need to include all of these links in your script, and you can reuse the XML hierarchy code and methods to further enhance efficiency.
- After you perform the required operation on the Plug-in Central page, to move to a similar page for WebSphere, we can just call this method:
gotoPage("link_webspherePluginCentral");
Tip:
To open the Plug-in Central page for WebSphere page, you must specify the navigation in the XML hierarchy similar to the one shown in Listing 3.
You can build clean, lean, and resilient scripts by incorporating these practices:
- Add only the required objects to the object repository to keep the repository clean. Creating dynamic objects and acting upon them as required reduces test dependency on the object repository, which enhances object recognition and reduces maintenance significantly.
- Make your scripts resilient when applications change by including regular expressions and XML link hierarchies. The tests can tolerate constantly changing objects and navigation.
- Increase flexibility and reduce the package maintenance that dynamic Web applications demand by rethinking the way that you include objects and navigation.
Spend more time testing and less time adjusting scripts to the inevitable changes in Web applications.
Learn
-
Explore the Rational Functional Tester Information Center, where you can also take a short video tour.
-
Investigate Rational
Functional Tester Plus, which is a software application testing bundle.
-
Visit the Rational
Functional Tester area on developerWorks for introductory to in-depth information.
-
Visit the Rational software area on developerWorks for technical resources and best practices for Rational Software Delivery Platform products.
-
Learn about other applications in the IBM Rational Software Delivery Platform, including collaboration tools for parallel development and geographically dispersed teams, plus specialized software for architecture management, asset management, change and release management, integrated requirements management, process and portfolio management, and quality management. You can find product manuals, installation guides, and other documentation in the IBM
Rational Online Documentation Center.
-
Explore Rational computer-based, Web-based, and instructor-led online courses. Hone your skills and learn more about Rational tools with these courses, which range from introductory to advanced. The courses on this catalog are available for purchase through computer-based training or Web-based training. Additionally, some "Getting Started" courses are available free of charge.
-
Subscribe to the Rational Edge newsletter for articles on the concepts behind effective software development.
-
Subscribe to the IBM developerWorks newsletter, a weekly update on the best of developerWorks tutorials, articles, downloads, community activities, webcasts and events.
-
Browse the technology bookstore for books on these and other technical topics.
-
Get an Introduction to IBM Rational Functional Tester 7.0. IBM® RationalFunctional Tester automates testing Java™, .NET, and Web-based applications. Starting with version 7.0, Rational Functional Tester includes support extensions for both Siebel and SAP, integration with IBM® Rational® ClearQuest®, support for the Eclipse Test and Performance Tools Platform (TPTP) logs, and support for testing HTML applications with Mozilla Firefox. This introduction explains these new features and capabilities.
-
Visit the Rational Functional Tester zone on developerWorks for technical resources and best practices information for RationalFunctional Tester, including articles and tutorials.
Get products and technologies
-
Try Rational Functional Tester. The trial download is free but requires registration.
-
Download trial versions of IBM Rational software.
- Download these
IBM product evaluation versions
and get your hands on application development tools and middleware products from
DB2®, Lotus®, Tivoli®, and WebSphere®.
Discuss
- Check out
developerWorks blogs and get involved in the developerWorks community.
-
Get involved in the developerworks Functional and GUI Testing discussion forum where you can discuss and ask questions about Rational Functional Tester and general testing topics.

Naveen Bysani is a senior quality assurance engineer who started his career with IBM India Software Lab. He began with the IBM WebSphere team and moved to the IBM Rational team as a systems software engineer for the automation development of IBM Rational Application Developer, using IBM Rational Functional Tester. He then went to IVY, a party gaming company, as a senior software engineer, where he was involved in the automation framework development, using Rational Functional Tester. He currently works as a senior automation engineer for a storage domain product of Quantum India Development Centre. Mr. Naveen is certified by IBM for Rational Functional Tester and Rational Performance Tester, and is a Sun certified Java professional.




