Selenium is a suite of tools to automate web browsers across many platforms in which you can write your tests in your preferred language. This guide intends on showing you how to install and run a Selenium test on a Linux box. Specifically, this guide was written using a default Fedora 15 installation and using Python as the preferred language. It can easily be applied to other distributions or other preferred languages. Now, open a terminal window and let’s get to it!
Step 1: Install the Selenium Server Package and Python Setup Tools
First, we need to install the selenium-server and python-setuptools packages. The first is obvious: we need the server. The second is for easy_install so we can install the Selenium Python package. Open the terminal and paste the following command.
su -c 'yum install -y selenium-server python-setuptools'
Step 2: Install the Selenium Server Package
Now, we need to install the Python selenium package.
su -c 'easy_install selenium'
Step 3: Startup Selenium Server
Next is starting the selenium server. This is done simply by running the following command as a normal user. I suggest opening in a new terminal window or add “&” to the end to push it to the background so you can continue working in the current terminal.
Step 4: Create a Selenium Test
You can then create a test from scratch or by using the Selenium IDE via Firefox plugin that you can download here: http://seleniumhq.org/download/. Read more about it here: http://seleniumhq.org/projects/ide/.
A note about using the Firefox plugin while running Linux (at the time of this writing). You must enable the experimental features before you can export the created test to Python (or any) code. To do this, open the preferences of the plugin and then make the following changes:
Options -> Options.... -> Enable Experimental Features Options -> Format -> Python 2
Now, you should be able to copy/paste the output into your favorite editor and save it as a python script.
To get you going, here’s a working script that you can copy/paste into your favorite text editor:
from selenium import selenium import unittest, time, re class Google(unittest.TestCase): def setUp(self): self.verificationErrors =  self.selenium = selenium("localhost", 4444, "*chrome", "http://www.google.com/") self.selenium.start() def test_google(self): sel = self.selenium sel.open("/#hl=en&xhr=t&q=Selenium+IDE+Download&cp=14&pf=p&sclient=psy&biw=1920&bih=866&source=hp&aq=0&aqi=&aql=&oq=Selenium+IDE+D&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=fce33a84b0764b22") sel.type("lst-ib", "Selenium IDE Download") # Uncomment to close the server when finished with test. # def tearDown(self): # self.selenium.stop() # self.assertEqual(, self.verificationErrors) if __name__ == "__main__": unittest.main()
Step 5: Run a Selenium Test
Now, we’ll run the test. After running the following command, you should see Firefox open, navigate to http://www.google.com, and perform a search.
If you’re wondering where to go next or looking for other useful tools, check out the following page from the NetBeans webpage: http://netbeans.org/kb/docs/php/phpunit.html.