Automate Testing your Web Application with Rational Test Workbench
In this modern times of application development many of the user interfaces are presented through a browser. Testing of an application is often a tedious and repetitive, but necessary, activity. Automation lends a helping hand in the repetitive aspects of testing, but what tool to use?
In my first blog I’d like to talk about browser testing using one of the tools from the Rational Test Workbench (RTW) suite. While RTW offers tools for various testing methods, Selenium is quickly becoming the standard method for testing browser based applications. Selenium is becoming the defacto choice simple because it’s libraries are A) open source (www.seleniumhq.org), and B) those libraries understand many of the current browser models (http://www.seleniumhq.org/projects/webdriver/).
So what tool to talk about here. Well the obvious tool might be RTW Web UI Tester (available here). This tool is actually built upon the Selenium drivers and using it will create “Script-less Tests” to exercise your application. Web UI Tester is fine if you want to create a simple set of tests or your testers don’t have programing knowledge. To create a more in-depth testing framework, or address complex testing issues you will want to turn to Rational Functional Tester (RFT).
So if your familiar with RFT you know it’s a fully support Java development environment, but you may say; “Stop right there – it does not support Selenium, I thought you said that was better!” - and out of the box you would be right.
But Selenium supports Java (along with other languages) and so we’re back in business, as they say.
In this article there are some preconditions that need to be met:
- You already have RTW and/or RFT installed (you will want the tools in the same eclipse shell).
- You know how to work with Java
- You know how to create a project in RFT to get started.
- You have downloaded the Selenium Java files and unzip them.
- You have Firefox installed.
Using Selenium in RFT
First thing you will want to do is from the eclipse menu select: Window → Show View → Navigator
This action will open the Navigator view tab where you can explore the project. From this view, expand the project and under resources create a new folder (be sure not to create a Test Folder as this is a specific type used by RFT). Next open the file system to the unzip Selenium files, drop the selenium-java-x.x.x.jar into the new folder. Now expand the libs folder and drag all jars shown into the new folder.
Doing this will keep a copy of the libraries local to your project, even when you move the project. If you use source control management (which we’ll discuss in another blog) having the files in the resources folder will make the available to others, you share the project with.
Next you want to make these libraries visible to the project. So you need to add them to the Java Build Path. The build path is in the project: Properties → Java Build Path and should look like this (Fig 1):
To add the Selenium libraries from the resources folder, click the button Add JARs… this will present you with a dialog that you can expand the folder you created under resources of the project and select ALL the jars you copied in.
When you have imported the jars your build path will look like this (Fig 2):
Note that the path of each jar will be represented by the Project name as a relative path, rather than the actual path in the file system.
Press Ok to update the path
Now you’re ready to start building selenium tests in RFT. You will have the full power of Java, but you will lose the Record & Object Map features. You can still augment a test with Recorded content, but it means you have to manage the Object Map contents for each browser type you’re testing with.
A simple Selenium Test in RFT
To give you an example of a test, I’ve included code for a simple browser call to log into Gmail.
- Start by creating a Test: File → New → Empty Functional Test Script
- Right above testMain enter the following line: static WebDriver driver;
- Replace the //TODO Insert code here with the following lines:
// Create a new instance of the Firefox driver
driver = new FirefoxDriver();
// Wait For Page To Load
// Put a Implicit wait, this means that any search for elements on the page
// Could take the time the implicit wait is set for before throwing exception
// Navigate to URL
// Maximize the window.
// Enter UserName
// I’ll cover this function in another topic
// Enter Password
// Click on 'Sign In' button
// Click on Compose Mail.
// Close the browser.
- Press ctrl-shift-o to organize the imports for the Selenium calls.
- Save the test and click the Run Functional Test Script from the icon tray.
- So that’s it. You should see Firefox open and navigate to Gmail
Now you may be asking; “Can I run this automated test from Quality Manager?”.
Running this test from Rational Quality Manger
And yes you can BUT, you knew that was coming didn’t you, you must add the selenium libraries to another location on the box that has RFT installed and the RQM Adapter running.
To work from Quality Manger you must copy the Selenium jar files to the customization folder located on Windows 7 (and I believe 10 also) located at <drive>:\ProgramData\IBM\RFT\customization.
When you have the files copied you will see in the Java Build Path dialog the files showing under the built in folder RFT Customization Libraries:
This is a built-in library which points to the above folder location.
In the Java Build Path you will see the same JAR files in the main library and the customization library, this is ok as they will not conflict with each other (Fig 3).
In Blogs to come I’ll cover identifying objects for Selenium calls, using RFT functions like logging, datapools and other built-ins, source control management for project sharing, and finally building a testing framework in RFT using advance java techniques.
Do you need an all in one solution for application testing? Rational Test Workbench allows you to test the performance of your applications across all platforms. Whether it is a cloud, mobile, or traditional app, you can significantly reduce test cycle times, moving integration testing earlier in the development lifecycle by using Rational Test Workbench
RTC provides users with a vast array of features including repository, source code control, integrated bug tracking, a WEB UI and even an Eclipse UI. These interfaces are the real charm of RTC, as they offer an easy way for users to manage their team and collaborate their source control with ease.
In my Talent Acquisition (fancy word for recruiting) endeavors, a potential candidate asked the following question: What is the culture of TechRev? Good question candidate, good question. It was a hard question to answer for 3 reasons…
Launching a new company website is a daunting task on any level. There are so many variables – so many things to consider. Outsource or in-house creation? Who writes the content? What framework to use? Where to host? Do we even need a new site?