Automatic web app testing through Firefox
The Selenium project has some very useful tools for testing your web applications, including an excellent Firefox extension. In this tutorial we get started with Selenium IDE and RC…
06 Executing a script after making changes
Say you have recorded a script and made a few changes to it using either the graphical or the source method to do so. How do you know it works? If you look at the Selenium IDE pane, just below the section that contains the URL of the website being tested you will see a menu containing several icons, along with a Fast/Slow slider and the record button. Here you will find some quite useful options to execute the tests that you have been working on. It allows you to play the entire test suite or the particular test case that you are working on. You can also adjust the speed with which the execution of these steps happens. The controls available are simple, yet we found them quite useful.

07 Introducing the Selenium TestRunner
One of the button options in the Selenium pane is the one that lets you play the test case with TestRunner (Fig 2). The TestRunner is a pretty cool tool. This is like a browser-based representation of the Selenium IDE plug-in for Firefox. It has most of the play features of Selenium IDE – you can play a test script you have written or recorded several times over. As the script is played, you can watch the results below. There’s also a log file to help you monitor the progress.
08 Export
A great feature of the Selenium tools is that you can generate a test in a particular scripting language. You can, at any point in time, request Selenium to export the script in that or another supported language if you like. Say you wanted to export the script in PHP, here’s what you do. After you have recorded a script, go to File>Export Test Case As>PHP – Selenium RC (Fig 3). You can also export the test suite if you like, instead of test cases.

09 The test case
Take a look at the PHP test case script you just exported. Open it in a text editor. You need to make one quick change to it. Change the name of the class in the script. The default value will be ‘Example’. Change it to something more appropriate to your test. Note that you should try to keep the name of the file the same as the name of the class. Now we will take this test case and use it with another Selenium tool – Selenium RC (Remote Control).
10 Introducing Selenium RC
Selenium RC is the solution for tests that need more than simple browser actions and linear execution. We can use Selenium RC whenever our test requires logic which is not supported by Selenium IDE. Selenium RC uses the full power of programming languages to create more complex tests like reading and writing files, querying a database, and emailing test results. Selenium RC comprises two parts: a server and a client. The server launches and kills browsers, and acts as an HTTP proxy for web requests from them, while the client contains the libraries in different computer languages. What we are going to do here is that we will take our PHP and execute the test case using Selenium RC.
11 Installing Selenium RC
To get started with Selenium RC you will need to download and install the Java Runtime Environment (JRE). You can get it from http://java.sun.com/. Once you have Java installed, download Selenium RC from here. Once you have downloaded the latest release of Selenium RC, extract it. You will find the file selenium-server.jar inside the extracted folder. Copy this to another location. We will use this file to execute Selenium RC. Assuming that Java was set up correctly, launching Selenium RC should now be as simple as executing the command ‘# java -jar selenium-server.jar’ from the directory where you copied the Selenium RC JAR file (Fig 4). Selenium should now get launched on the port 4444. Now the server is ready to accept test commands from your PHP script. Make sure you keep this server running till you finish testing.

Continue to page 3
Find out what else featured in issue 93 of the magazine
Return to the homepage















Trackbacks
What's your opinion?