Automating GUI testing for IBM Systems Director using Selenium

IBM Systems Director is a platform management solution used to manage physical and virtual systems in a multi-system environment. It supports various virtualization technologies and multiple operating systems across IBM and non-IBM platforms. This tutorial explains basic steps to automate graphical user interface (GUI) testing for IBM Systems Director using the Selenium tool.

Prashant Pareek (prashant.pareek@in.ibm.com), Staff Software engineer, IBM China

prashantPrashant Pareek is a Staff Software Engineer at IBM currently working on VMControl under IBM Systems Director, a critical product in IBM's product portfolio. He has an overall experience of 7.5 years and holds a bachelor's degree in Information Technology Engineering from VTU, Karnataka, India. You can contact him at prashant.pareek@in.ibm.com



Piyush Jain (piyushjain@in.ibm.com), Staff Software engineer, IBM China

piyushPiyush Jain is a Staff Software Engineer at IBM currently working on VMControl under IBM Systems Director, a critical product in IBM's product portfolio. He has an overall experience of 5 years and holds a bachelor's degree in Information Technology Engineering from IET Alwar, Rajasthan India. You can contact him at piyushjain@in.ibm.com



28 May 2012

Also available in Chinese

Before you start

Learn what to expect from this tutorial, and how to get the most out of it.

About this tutorial

GUI testing is an integral part of testing for any product. IBM Systems Director is a product with hundreds of screens supporting different operations. GUI testing for IBM Systems Director needs to be performed frequently and has to be repeated on various supported platforms. Hence, it is a tedious job to do this testing manually.

There are various tools available to automate GUI testing. Many of these tools can be used to automate GUI testing for IBM Systems Director. But as the IBM Systems Director product evolves, there are frequent changes in the screens, which requires a tool to automate the dynamic screens. Selenium is one such tool and is widely used to automate web application testing. It is also very effective in testing IBM Systems Director. This tutorial covers all the steps required to automate GUI testing for IBM Systems Director using Selenium in a simplified manner.

Objectives

The main objective of this tutorial is to help developers and testers working on IBM Systems Director to automate the GUI testing using the Selenium tool.

Prerequisites

You should have IBM Systems Director V6.x.x installed on your system before proceeding. This tutorial assumes that you are familiar with using IBM Systems Director. It also assumes that you have a reasonable understanding of Java, the Java 2 Platform, Eclipse IDE, JUnit and a basic knowledge of Selenium.

System requirements

You should have following components on your system:

  • Selenium IDE installed as an add-on to Firefox.
  • Selenium-RC
  • JUnit 4.x
  • Configured IBM Systems Director
  • Eclipse

Automated GUI testing for IBM Systems Director using Selenium

Why Selenium?

Selenium is an open source tool that tests web-based applications. This tool works using a record-and-play scheme, and it is lot easier to use when there are frequent screen changes. Thus, Selenium was an obvious choice to automate IBM Systems Director GUI testing where you encounter screen changes frequently during the development phase. Selenium supports the conversion of Selenium scripts generated through recording to a variety of scripts, like JUnit, JavaScript, Perl, Python, Ruby, and more, making it more useful for users who know any of these scripting languages. It also keeps a record-and-play option for those who do not know any of the programming languages or scripts.

About Selenium

There are three different Selenium tools available:

  • Selenium Integrated Development Environment (IDE) is a Firefox add-on. IDE is used to record the steps of the test. It records all the clicks, typing, and other actions to create a test. After the recording, you can play back the recording.
  • Selenium Remote Control (RC) lets you run the tests in different browsers and platforms. You can also tweak the tests in a preferred language.
  • Selenium Grid, not covered in this tutorial, is used to distribute tests across multiple servers to run them in parallel. It reduces the time of running the tests.

A brief introduction to Selenium IDE

Selenium IDE for Selenium scripts comes as a Firefox plug-in and can be downloaded from the SeleniumHQ download web page. It allows you to record, debug, and edit the tests in the actual test environment. It contains the Selenium core, and you can modify the scripts after recording, as well as change the order of scripts as required. It also provides you with a list of Selenium commands to choose from so the you don't have to remember all of the commands.

The following are some basic steps to use Selenium IDE:

  • Download and install Selenium IDE.
  • After you are done with the download of the Selenium IDE plug-in, open Firefox.
  • Open the Selenium IDE by clicking Tools and selecting Selenium IDE as shown in Figure 1.
    Figure 1. Starting Selenium IDE from Firefox
    A screen capture of starting Selenium IDE from Firefox
  • The Selenium IDE tool is shown in Figure 2:
    Figure 2. Selenium IDE tool
    A screen capture of the Selenium IDE tool
  • Observe the rectangular area marked towards left in Figure 2.
    • The first button runs the test suite.
    • The second button runs the single test case.
    • The third button is to pause and resume the execution.
  • Observe the second rectangular area marked towards right in the Figure 2, the second rectangle has one button. This red circle is to start and stop the recoding.

Record the test using IDE

Test scenarios:

  1. Login: Login to the IBM Systems Director as shown in Figure 3.
    Figure 3. IBM Systems Director log-in page
    Sample figure containing an image
    • After you have logged in, follow these steps:
      • The tool automatically takes the base URL of the log-in page. It will always be till the port number of the director server. For example, https://DS machine name or IP address :8422/
      • In the text box for the user ID, enter the IBM Systems Director log-in user ID.
      • In the password text box, enter the IBM Systems Director log-in password.
      • Click Log in.
      • The Selenium IDE tool records all the clicks and text entered by the user as shown in Figure 4.
        Figure 4. Recorded test scripts for IBM Systems Director login
        Sample figure containing an image
    • In Figure 4 we see that the tool has recoded the commands (open, type, click and wait), Target (id of the text box, button) and even the values that we have entered in the text box (userid and password).
    • Save the recorded scripts as shown in Figure 5.
      Figure 5. Save the recorded test scripts
      Sample figure containing an image
  1. System discovery:

Discovery operation requires the user to enter the IP address or host name or range of IP addresses of the hostor hosts to be discovered. You need to log in into IBM Systems Director and navigate to the discovery page and perform the above mentioned tasks. You can record all the actions (including all clicks and text entered) from logging on to IBM Systems Director until the discovery of host using Selenium IDE.

Refer to Figure 6 for all the recorded commands and scripts related to the discovery operation.

Figure 6. Recorded scripts for discovery operation
Sample figure containing an image

When we try to execute these recoded script as-it-is, they may fail. We might need to add some additional commands (such as waitforElementPresent) manually to make it work as shown in the Figure 7.

Figure 7. Fine tuned tests for discovery operation
Sample figure containing an image

In first three rectangles in Figure 7 we are waiting for an element to be present before we start any operation on it and also providing an additional delay of xxx ms(using pause). The additional delay might or might not be needed, depending on network speed.

In Figure 7, the fourth rectangle is important. Here we are waiting for the discovery process to finish (waitForTextNotPresent). We have given some delay and then we are waiting for the "processing" text to disappear, which is shown when we click Discover. As soon as this text disappears, we can assume that discovery is completed.

We can convert the above script to the Junit4 scripts and run it from the command prompt.

  1. Request access (after discovery):

Request Access operation lock the resources discovered using discovery operation. You need to click Request access and provide log-in credentials for the resource. You can record all the actions (including all clicks and text entered) from the discovery operation until the request access operation using Selenium IDE.

Figure 8 shows the recorded commands for request access along with the additional commands added to fine-tune the code to run the tests successfully.

Figure 8. Recorded and fine-tuned test scripts for requesting access
Sample figure containing an image
  1. Logout:

Now log out from the Systems Director console. Refer to Figure 9 for the recorded test scripts. We can record all the actions (including all clicks for the log-out operation using Selenium IDE.

Figure 9. Recorded test scripts for the log-out operation
Sample figure containing an image

Convert the HTML code to desired scripting

Scripts recorded above can be converted to any of the required scripting language as shown in Figure 10.

Figure 10. Converting the Selenium scripts to JUnit4 code
Sample figure containing an image

After the conversion to Junit4 code, the log-in tests look similar to Figure 11.

Figure 11. Converted JUnit scripts in Selenium IDE
Sample figure containing an image

You can change the browser name of your choice as shown in Figure 11 to run it on other browsers, such as:

  • Chrome
  • Firefox
  • Internet Explorer

Now we are good to run an individual test for any scenario using Selenium RC.

Run individual test case through Selenium RC

Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic.

Selenium RC provides an application programming interface (API) and library for each of its supported languages

To run the tests through Selenium RC, we need to follow these steps:

  1. Create a Firefox profile.
  2. Start the Selenium RC server.
  3. Run the Testcase.
  1. Create a Firefox profile
    • Firefox profile creation on Windows
      • Click Start -> Run.
      • Type firefox.exe -ProfileManager and click OK, which opens the Firefox profile manager as shown in Figure 12.
        Figure 12. Command to open Firefox ProfileManager
        Sample figure containing an image
      • Click Create Profile to create a new Firefox profile as shown in Figure 13.
        Figure 13. Firefox Profile Manager on Microsoft Windows
        Sample figure containing an image
    • Firefox profile creation on Linux
      • The Firefox profile on Linux can be created in the same manner as on Windows.
      • Run command "firefox -profilemanager" on Linux terminal. It will open a profile creation wizard same as Windows as shown in Figure 14.
        Figure 14. firefox ProfileManager on Linux
        Sample figure containing an image
  2. Steps to start the Selenium RC
    • On Windows
      • Go to Selenium RC server directory :e.g. cd C:\selenium-remote-control-1.0.3\selenium-server-1.0.3(Directory where you copied your Selenium RC JAR files)
      • Run the following command to start the Selenium RC server: java -jar selenium-server.jar -avoidProxy -browserSessionReuse -firefoxProfileTemplate "c:\Selenium\profile"
    • On Linux
      • Go to Selenium RC server directory, for example, cd /tmp/selenium/selenium-remote-control-1.0.3/selenium-server-1.0.3
      • Run the following command to start the Selenium RC server: java -jar selenium-server.jar -avoidProxy -browserSessionReuse -firefoxProfileTemplate "/tmp/Selenium/profile"
    • We have used following options in the commands above:
      • -browserSessionReuse: Stops re-initialization and spawning of the browser between tests.
      • -firefoxProfileTemplate: Here you need to provide a fully qualified Firefox profile name created through the Firefox ProfileManager as shown in Figure 13 and Figure 14.

After you start the Selenium RC server, you see the following output:

Listing 1. After you start the Selenium RC server, you see the following output:
C:\selenium-remote-control-1.0.3\selenium-server-1.0.3>java -jar selenium-server.jar
-avoidProxy -browserSessionReuse -firefoxProfileTemplate "c:\SeleProfile"
16:24:16.421 INFO - Java: IBM Corporation 2.4
16:24:16.437 INFO - OS: Windows XP 5.1 build 2600 Service Pack 3 x86
16:24:16.453 INFO - v2.0 [a2], with Core v2.0 [a2]
16:24:16.453 INFO - Will recycle browser sessions when possible.
16:24:16.593 INFO - 
RemoteWebDriver instances should connect to: http://127.0.0.1:4444/wd/hub
16:24:16.593 INFO - Version Jetty/5.1.x
16:24:16.593 INFO - Started HttpContext[/selenium-server,/selenium-server]
16:24:19.406 INFO - Started org.openqa.jetty.jetty.servlet.ServletHandler@75827582
16:24:19.406 INFO - Started HttpContext[/wd,/wd]
16:24:19.406 INFO - Started HttpContext[/selenium-server/driver,/selenium-server/driver]
16:24:19.406 INFO - Started HttpContext[/,/]
16:24:19.421 INFO - Started SocketListener on 0.0.0.0:4444
16:24:19.421 INFO - Started org.openqa.jetty.jetty.Server@86b086b

To run the Junit from the Windows command line, run the following command after adding the current directory and two jars to the class path, for example C:\Demo\junit-4.3.1.jar;C:\Demo\selenium-server-1.0.3-standalone.jar;C:\Demo\

  1. Run the TestCase

C:\Demo>java org.junit.runner.JUnitCore IBM System DirectorLogin

Listing 2. After you start the test, you see the following trace at the RC server:
16:24:23.843 INFO - Checking Resource aliases
16:24:23.859 INFO - Command request: getNewBrowserSession
[*firefox, https://9.12.31.207:8422/, ] on session null
16:24:23.859 INFO - grabbing available session...
16:24:23.859 INFO - creating new remote session
16:24:24.250 INFO - Allocated session 6663937b710b4628ae8c637d8414b36b 
for https://9.12.31.207:8422/, launching...
16:24:24.843 INFO - Preparing Firefox profile...
16:24:29.156 INFO - Launching Firefox...
16:24:32.234 INFO - Got result: OK,6663937b710b4628ae8c637d8414b36b 
on session 6663937b710b4628ae8c637d8414b36b
16:24:32.250 INFO - Command request: open[/ibm/console/logon.jsp, ]
on session 6663937b710b4628ae8c637d8414b36b

You can run the tests on Linux in exactly same way

Organize and run test cases as test suites

You can add all test cases to a single test suite and can directly run the suite that in turn runs all the tests. You can run test suite using one of the following ways:

  1. Through Selenium IDE
  2. Through Eclipse (using Selenium RC)
  3. Through the command line( using Selenium RC)
  1. Run a test suite through Selenium IDE

    We have created a test suite named "Director Suite" and added all the tests to the suite as shown in Figure 15. You can launch all the tests as suite, so that they you able to run all the tests back to back.

    Figure 15. Running tests as test suite using Selenium IDE.
    Sample figure containing an image

    From Figure 15, we can see that all the three tests have passed.

  2. Run test suite through Eclipse (using Selenium RC)

    To run all the JUnits test cases, we need create one JUnit TestSuite file. We have created a suite file and added all the three tests to the suite as shown in Figure 16. Before running these tests, we need to start Selenium RC. You can start the execution by running the suite file and it will run all the three test cases. To run the suite, you need to right-click the suite file and select run as Junit.

    From Figure 16, we can see that all the three tests have passed.

    Figure 16. JUnit test suite creation and execution.
    Sample figure containing an image
  3. Run the suite from the command line:

    You can also run the test suite from the command line as shown in Figure 17. Start the execution by running the suite file that in turn runs all the three test cases. Before running these tests, you need to start Selenium RC.

    From Figure 17, we can see that all the three tests have passed.

    Figure 17. Running test suite through the command line.
    Sample figure containing an image

Sample scripts to automate tests using Selenium

We have recorded the test scripts for log-in, discovery, request access and logout operation of IBM Systems Director. You can reuse these scripts if required. There is a downloadable archived files provided with this tutorial. This archived files contain modified JUnit 4 scripts.

Sample code that is recorded through Selenium has hardcoded values for the IBM Systems Director and endpoint information. To make the code more flexible and reusable, we have introduced a properties file where user can enter the director and all endpoint information. Test cases read this properties file at run time to retrieve the Systems Director and the endpoint information. The attached files also contain the above mentioned properties file along with modified code. This code can run on any system by just updating the properties file.


Downloads

DescriptionNameSize
Code sampleDiscovery.java3KB
Code sampleISDLogin.java1KB
Code sampleISDSuite.java1KB
Code sampleLogout.java1KB
Code sampleREADME.txt1KB
Code sampleReadProperties.java1KB

Resources

Learn

Get products and technologies

Discuss

  • Get involved in the My developerWorks community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis.

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


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. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

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.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

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

 


All information submitted is secure.

Dig deeper into AIX and Unix on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=AIX and UNIX
ArticleID=816429
ArticleTitle=Automating GUI testing for IBM Systems Director using Selenium
publish-date=05282012