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.
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.
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.
You should have following components on your system:
- Selenium IDE installed as an add-on to Firefox.
- JUnit 4.x
- Configured IBM Systems Director
Automated GUI testing for IBM Systems Director using 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
- The Selenium IDE tool is shown in Figure 2:
Figure 2. 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
- Login: Login to the IBM Systems Director as shown
in Figure 3.
Figure 3. IBM Systems Director log-in page
- 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
- 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
- After you have logged in, follow these steps:
- 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
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
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.
- 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
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
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
After the conversion to Junit4 code, the log-in tests look similar to Figure 11.
Figure 11. Converted JUnit scripts in Selenium IDE
You can change the browser name of your choice as shown in Figure 11 to run it on other browsers, such as:
- 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:
- Create a Firefox profile.
- Start the Selenium RC server.
- Run the Testcase.
- Create a Firefox profile
- Firefox profile creation on Windows
- Click Start -> Run.
firefox.exe -ProfileManagerand click OK, which opens the Firefox profile manager as shown in Figure 12.
Figure 12. Command to open Firefox ProfileManager
- Click Create Profile to create a new
Firefox profile as shown in Figure 13.
Figure 13. Firefox Profile Manager on Microsoft Windows
- 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
- Firefox profile creation on Windows
- 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.
- On Windows
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\
- 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://22.214.171.124: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://126.96.36.199: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:
- Through Selenium IDE
- Through Eclipse (using Selenium RC)
- Through the command line( using Selenium RC)
- 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.
From Figure 15, we can see that all the three tests have passed.
- 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.
- 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 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.
- "Eclipse.org " For information about Eclipse development.
- IBM Systems Director For information about IBM Systems Director product.
Get products and technologies
- Get involved in the My developerWorks community. Connect with other developerWorks users while exploring the developer-driven blogs, forums, groups, and wikis.