Selenium, a web application testing system
With Selenium, you can automate the tests of web applications. Actually, I wanted to do something else with it and it turned out that selenium is designed for something else. Anyway, here I sum up what I learned about selenium.
If you want a 2-minute introductory video, watch this.
The download page is here. You’ll have to download the selenium server and launch it. It’s a JAR file. The client scripts that you write to automate tests communicate with this server.
The Selenium IDE is a Firefox add-on for recording (and playing back) interactions with the browser. The add-on can export your interactions in various languages (Java, Python, Ruby, etc.). Strangely, the add-on didn’t support Firefox 4 when I tried it, so I had to force the installation with the Nightly Tester Tools add-on.
Here is a simple Python example to open a web page. The source is generated by the Selenium IDE:
#!/usr/bin/env python from selenium import selenium import unittest, time, re class Untitled(unittest.TestCase): def setUp(self): self.verificationErrors =  self.selenium = selenium("localhost", 4444, "*firefox", "http://www.ncbi.nlm.nih.gov/") self.selenium.start() def test_untitled(self): sel = self.selenium sel.open("/genomes/lproks.cgi") sel.click("link=CP002059.1") sel.wait_for_page_to_load("30000") # my addition: text = sel.get_html_source() f = open('out.txt', 'w') f.write(text.encode("utf-8")) f.close() def tearDown(self): self.selenium.stop() self.assertEqual(, self.verificationErrors) if __name__ == "__main__": unittest.main()
Just for playing a bit with the code, I added some lines to save the HTML source of the page. I was hoping that it would save the post-AJAX version of a page, but no :( If you want the generated HTML source, you will need a different approach.