27
Jul

How To Install and Use Selenium Server in Linux

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.

selenium-server

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.

python google_test.py

Conclusions

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.

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:


There's 1 Comment So Far

  • Ryo Eng®
    September 19th, 2015 at 5:13 pm

    Any idea to install selenium-server?
    “`
    [[email protected] ~]# su -c ‘yum install -y selenium-server python-setuptools’
    Loaded plugins: fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    * base: mirror.i3d.net
    * epel: mirrors.coreix.net
    * extras: mirror.i3d.net
    * updates: mirror.i3d.net
    No package selenium-server available.
    Package python-setuptools-0.9.8-3.el7.noarch already installed and latest version
    Nothing to do
    [[email protected] ~]# su -c ‘easy_install selenium’
    Searching for selenium
    Best match: selenium 2.47.1
    Processing selenium-2.47.1-py2.7.egg
    selenium 2.47.1 is already the active version in easy-install.pth

    Using /usr/lib/python2.7/site-packages/selenium-2.47.1-py2.7.egg
    Processing dependencies for selenium
    Finished processing dependencies for selenium
    [[email protected] ~]# selenium-server
    bash: selenium-server: command not found…
    “`

Share your thoughts, leave a comment!