Testing with Selenium
Testing with Selenium
Selenium is primarily for feature testing, user interface and acceptance testing.
Recently OpenACS got support for Selenium RC on CVS HEAD to be released in OpenACS 5.6 sometime in the future.
Forum Posts :
Command Reference :
Interesting Articles :
Selenium Recorder Firefox Extension
Quickstart to Writing Tests:
This quickstart shows you how to start writing selenium tests with selenium and the selenium recorder (aka selenium-ide).
- You need to have the Firefox Browser version 1.5 or higher
- Proceed to http://www.openqa.org/selenium-ide/ and click on the link (Firefox Extension) to install the Selenium IDE firefox extension
- Restart firefox
- Click Tools -> Selenium IDE
- The selenium ide window will open
- It will start recording your actions in the browser.
- You can go ahead and go to a url and click on the links to see how the recorder records your actions.
- To disable recording while the recorder window is open, click the "red" button.
- Selenium verifies that a test or action is successful by checking the title or text in a webpage
- You can verify the title of the current page by right clicking on the webpage you are currently in and click Append Selenium -> verifyTitle
- You can verify the presence of text in a page by highlighting some text and then right click -> Append Selenium Command -> verifyTextPresent
Click here for a video of how to use Selenium IDE.
Selenium IDE allows you to create, save, load and run tests right from firefox without having to install Selenium on the server.
Selenium on the Server
Aside from using the Selenium IDE to test webpages, selenium itself can be installed on the server. This provides a central location for testers and developers to view and execute tests. "Server" here refers to the OpenACS instance where your application is running. If your OpenACS instance is in http://your_openacs_instance, then selenium should be installed in http://your_openacs_instance/selenium
WARNING: We do not recommend installing selenium on the server of a production instance. Only install selenium on a staging or test server. This is because
- When tests fail, they leave a mess of test data that you will not want on production
To instal selenium on the server :
- Download selenium from http://www.openqa.org/selenium-core/download.action
- Choose to download the "Full Release"
- After downloading, decompress the file.
- You will see a folder selenium-x.x where "x.x" is the version of selenium you downloaded.
- Go inside this folder and look for the "selenium" folder.
- Copy this "selenium" folder to the openacsroot/www/ directory
- Launch a browser and go to http://your_openacs_instance/selenium
At this point, selenium is installed. The page that you see when you visit /selenium is the default selenium page. It lists the tests that come with selenium.
To start using selenium on the server :
- Customize the landing page /selenium/index.html
- Create Test Suites for each package. A test suite is just a file in selenium/tests that lists a number of tests for a particular feature or section of an application. For instance, TestSuite-News.html would be a file that lists the tests for the News Package.
- Upload tests to the /selenium/tests folder.
Coming Soon .....
Some Limitations :
- Minor Issue with SSL : Selenium can't switch properly between http and https pages.
- File Input type not supported : You can't tell selenium to upload a file. But there is a work around with firefox. Read it here
- WYSIWYG Editors : Selenium can't write to some WYSIWYG editors like htmlarea but it seems to work with xinha, you just need to get the textearea element name that xinha uses.
Use xpath to find specific html elements
I have scenario where I want to click ona image field with no id or name attribute so there's no easy way to tell selenium to click it. We can either ask the designer to put an id or name attribute or use xpath. Let's say the image button in question looks like this
<input type="image" src="images/long-login-btn.gif" width=166 height=15 />
the xpath syntax will be
and you can use this in conjunction with clickAndWait
and use store to store them to a value for use later in the selenium script.