After having discovered that PHP sucks less than JavaScript reading the feedback of the last WebTuesday (I’ll need to go there one day, a Tuesday maybe). Harry mentioned in his presentation Selenium a powerful tool for doing Web Application Unit Testing. Sounds great! Let’s dive!
-
Download it: Selenium Remote Control
-
Unzip it and go in.
-
Run the server (Java is required).
cd server/ java -jar selenium-server.jar -interactive
-
We’ll try it with Python but Selenium support lots of cool languages like Ruby, Perl, Java and .Net (try Mono).
In an other shell go into the selenium directory and then into the
python
dir.Simply run:
python test_google.py
Rocks? Fails? For myself, it fails with firefox but I manage to run it with Opera.
-
Too Fast? Let’s try it into the Python shell. From the
python
directory run:python
Woo! I hope you already done that before, you may love it.
from selenium import selenium sel = selenium('localhost', 4444, '*opera', 'http://www.google.ch') sel.start()
Wait a second, it runs Opera for you.
sel.open('http://www.google.ch') sel.type('q', 'Yoan Blanc') sel.click('btnG') print sel.get_title()
It normally displays: “
u'Yoan Blanc - Recherche Google'
”. Now you can quit.sel.stop()
Hit Ctrl+D to quit the Python shell
Selenium will become your next new friend (after Firebug of course) for testing your web application.