Selenium Up & Running with Robot Framework

Selenium seems to have become the favourite choice for web browser automation.

Now, how do you get started with it? Here I try to explain the steps involved to get a setup up & running.

I prefer the Robot Framework with Selenium. If you prefer the same, go ahead try out the below simple steps.

What is the setup involved?

Windows or Mac machine. You would need few dependencies which you need to install. More below.

1> Python: Required for Robot Framework. But python is something every automation engineer would have.

Preferable version of python is 2.7
     OSX – Nothing to be done, python is present by default.

Windows – Download the latest python from https://www.python.org/downloads/windows/ & install.

2> pip  – pip is a package management system used to install and manage software packages written in Python.

Pip can be downloaded from https://pip.pypa.io/en/latest/installing.html

python get-pip.py

3> Robot Framework: Robot Framework is a generic test automation framework for writing test cases. This is my preferred method of writing test cases both for mobile app & as well browser(selenium) automation.

 OSX & Windows: With python installed, run the below command to install Robot Framework.

pip install robotframework

For more details for installing Robot Framework, please refer https://github.com/robotframework/robotframework/blob/master/INSTALL.rst

 

4> Selenium2Library: This is a web testing library for Robot Framework

To install the library run the below command

pip installrobotframework-selenium2library

 

More details on this library can be found at http://robotframework.org/Selenium2Library/Selenium2Library.html

5> chromedriver : Install a chromedriver & add it to the path variable.

MAC: Need to copy the driver to /usr/local/bin/ directory.

Windows: Google the steps to include the ENV path variable for the chromedriver.

Download chromedriver from the below location.

https://sites.google.com/a/chromium.org/chromedriver/

6> sshlibrary(optional):  This is a test library for testing SSH & SFTP. Might not be required if the testing involves only browser testing.

To install the library run the below command

pip install robotframework-sshlibrary

 

There would be dependency of Microsoft Visual C++

Download & install it from http://aka.ms/vcpython27

More details available here http://robotframework.org/SSHLibrary/latest/SSHLibrary.html

Quick checks to see if the device is ready for testing. 

i> Check the below command if the Robot Framework is properly installed.
Shivaram:selenium shivaram$ pybot --version
 Robot Framework 3.0 (Python 2.7.10 on darwin)
 
ii> Check if a simple Robot Framework works fine.
Sample test case. Save this as a text file. Eg: test.txt

 

*** Settings ***


*** Testcases ***
Simple Test
     Comment     This is a test run

iii> Check if Selenium test case works fine.
The below test case would open a chrome browser & check the speed of the network in www.fast.com website.
*** Settings ***
Library      Selenium2Library


*** Testcases ***
Check the speed of your broadband
     Open Browser      url=http://www.fast.com       browser=chrome
     Sleep     20
     Capture Page Screenshot
     Close Browser

How to run the test case?

From cli, go to the directory where you have saved your test case file.

Then execute the following command.

pybot test.txt

test.txt is the test case file.

The above 2 examples should pass if the setup is working fine.

Let me know what happened? Did your test case pass? If not let me know what happened.

This is a basic setup. You can build on top of it to include Selenium Grid as well so that you can open a browser in a remote host & run your test case.

More on this in future blogs.

 

Cheers.

Hi there. I'm Shivaram. Security & Network Professional with around 10+ years of experience. Here on this blog to share all my testing related experience. I'm a problem solver & key to that is to come up with the right questions. Of course we then have Google for all the answers.

2 thoughts on “Selenium Up & Running with Robot Framework

  1. It is important to say that you were using python version from the system. This is not recommendable. I didn’t know it and now I had to go through various problems trying to install different python packages, I recommend to install python2 from “brew install python2” command and then make it your default environment. It will avoid a lot of compatibility problems and if you have to do modifications you will not modify system’s python.

Leave a Reply