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:

  1. You already have RTW and/or RFT installed (you will want the tools in the same eclipse shell).
  2. You know how to work with Java
  3. You know how to create a project in RFT to get started.
  4. You have downloaded the Selenium Java files and unzip them.
  5. 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):

javabuild-1

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):

javabuildpath1

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
    • driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  • // Navigate to URL
  • // Maximize the window.
    • driver.manage().window().maximize();
  • // Enter UserName
    • driver.findElement(By.id("Email")).sendKeys("<your email>");
  • // I’ll cover this function in another topic
  • // takeScreenShot("loginScr.png");
    • driver.findElement(By.id("next")).click();
  • // Enter Password
    • driver.findElement(By.id("Passwd")).sendKeys("<email password>");
  • // Click on 'Sign In' button
    • driver.findElement(By.id("signIn")).click();
  • // Click on Compose Mail.
    • driver.findElement(By.xpath("//div[@class='z0']/div")).click();
  • // Close the browser.
    • driver.close();
  • Press ctrl-shift-o to organize the imports for the Selenium calls.
  • Save the test and click the   arrow    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).

javabuildpath

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.

UrbanCode Deploy Server as a Service

When installing the UrbanCode Server and Agent software in a Linux environment, by default they will be installed as processes that need to be started and stopped manually (for the Windows environment, the installer gives the option of installing as a service during the installation process). There are quite a few reasons that you may want to then go ahead and set them up as services instead. The main one is so that they will automatically start up as your operating system is restarted.

Launching TechRev Tutorials

The goal behind TechRev Tutorials is to provide concise and accessible walk-through tutorials in a video format. As we expand our content library, you’ll be able to find useful and digestible video tutorials on some of the IBM software products that we support such as UrbanCode, Rational Team Concert, and Rational DOORS Next Gen.

Use A DNG Template to Create or Copy a Project

Have you ever had a DNG project, and you just had to have that project on different Server? Maybe you like the way a project in DNG is laid out, you know folder structure, or attributes on artifacts, but you don’t want to recreate all that from scratch. What’s an Analysts to do? Well if you’re in that need, and not heard of Project Templates in DNG you might want to read on. While Project Templates won’t be an exact copy of your project it can help with structure or content.

s2Member®
Skip to toolbar