Python Environment for Automation

As part of our company training efforts, I have just completed teaching a mobile test automation course. Beside the pure fun of teaching, it’s always make you remember things that you have forgot.

One of the things that we wanted to to during the course was running mobile Web tests on Android device using Selenium. I have chosen to use the Python Selenium API to make things simple. The only thing that was left is to bring up the Python environment on each class room machine. Being a Mac user for a while, I forgot that not everything comes built in… So here is a reminder of how Selenium/Python environment should be configured from scratch.

Step 1: Install Python – I suggest using Python version 2.7 (the later 3.x versions not yet supported by other convenient tools and some test automation frameworks). You can download a version of Python from here.

Step 2: Configure PATH – Add <python_install_path> and <python_install_path>/Scripts to the PATH environment variable. For example: C:\Python27;C:\Python27\Scripts. Once the PATH is configured you can make sure that Python is accessable from any command line by running: Start -> Run -> cmd -> python. This should get you into the Python console.

Step 3: Install “setuptools” – There tools will be required for “pip” installation. You can download these tools from here. For 32bit machines just run the installer and for 64bit machine download “ez_setup.py” and run “python ez_setup.py”.

Step 4: Install “pip” – This is a great tool that allows you to install Python packages. This tool should be familiar to you from Linux/Mac. You can download this tool from here. Once you download the “pip.x.tar.gz” file, extract its content and run “python setup.py install”. The “setup.py” should be located in the main extracted folder.

Step 5: Install Selenium – Once you have the “pip” install, you just need to run “pip install selenium” and the rest will be done for you.

Step 6 (Verify): Let’s make sure that everything works fine. Open Python console and paste the following lines:

from selenium import webdriver

browser = webdriver.Firefox()

browser.get(“http://www.top-q.co.il/python-environment-for-automation/”)

This should open a new Firefox browser session and get you to this post.

Michael Oziransky