Friday, January 6, 2012

Automate tasks in Selenium using Python: Setting Up the Environment

This post demonstrates setting up the environment to use Selenium as automation tool via python. I will be demonstrating the whole process on Windows 7.

Steps:

  1. Install JDK: We would need to install jdk as a prerequisite to the eclipse IDE which we would be using to write the python code. You can find jdk here
  2. Install Eclipse: I would prefer to use the Eclipse Helios. You can find the installer here.
  3. Install Python: We would be using python-2.7 for this tutorial. However you are free to use any version. You can find the python installer here.
  4. Install SetupTools: This will provide you with EasyInstall which would be useful later on. You can find SetupTools corresponding to your python version at this location
  5. Create a new Environment Variable in your system with Name "EASY_INSTALL" and value "<install_path_for_python>\Scripts".  You can find out how to create an environment variable here CREATING ENVIRONMENT VARIABLES.
  6. Add this newly created environment variable to your PATH environment variable by appending "%EASY_INSTALL%" (without inverted commas :) ) to it.
  7. Open Command Prompt and type the command

                       C:\> easy_install pip
  8. Then run the command below at command prompt:

                      C:\> pip install selenium
  9. Setup Eclipse for Python: Now we need to setup our eclipse so that we can use it to code in python. You can set up your eclipse as shown in this blog post Setting Up Eclipse.

    WARNING: In the blog post  Setting Up Eclipse  mentioned above. You would need to slightly modify the instructions in STEP-2(c) . The modification will be:

    In the field "Work with:" you should use the URL:  http://update-production-pydev.s3.amazonaws.com/pydev/updates/site.xml instead of the URL shown ( http://pydev.org/updates/)
  10. Download Selenium Server:  You can download the selenium server form the official website here.
  11. Run the Selenium Server: You can run the selenium server jar at command prompt using the command:

                     C:\> java -jar <path_to_jar_file>
AND YOU ARE GOOD TO GO..................!!!!!! Now you have the environment to automate your tasks in selenium using python. Enjoy!! :)