setup robot framework environment

Robot Framework is widely used in our company to do webapp automation testing. This post lists the required steps to setup the environment for the robot framework.

 

1. Install pyenv

pyenv is an excellent tool to switch python between multiple versions. It is simple and easy to use. Refer to the below URL to install pyenv:

https://github.com/pyenv/pyenv

If you are in China, please take the below post for reference, because you may encounter a wired issue due to the GFW:

the dns record for git.githubusercontent.com has been polluted

 

2. Install Python

There are various implementations of Python programming language, for example, CPython, Jython, IronPython, PyPy and so on.  pyenv can be used to install any particular version of python implementation. Run the below command to list the available candidates:

pyenv install –list

Choose anyone that you like best. If you don’t have any special taste, CPython is a good choice. Run the below command to install CPython:

env PYTHON_CONFIGURE_OPTS=”–enable-shared” pyenv install 3.8.7

Note: The ‘–enable-shared’ option is required by wxPython. This option will be used when building CPython.

 

3. Create a Python virtual environment

It is really a mess to install python packages in a global environment, because different applications may require different versions of the same python package. It is impossible to meet this requirement without special treatment. However, python virtualenv module provides a good solution to this problem.

A virtual python environment can be created for a specific use case. This environment is an isolated sandbox, which contains a python installation of some version and a number of additional python packages. Any package installation in this virtual environment will not affect other virtual environments. Run the below command to create a virtual environment:

pyenv virtualenv 3.8.7 robot

This creates a Python virtual environment, in which CPython 3.8.7 is installed. Usually this environment also contains some default python packages, for example, pip and setuptools.

 

4. Activate the created Python virtual environment

Run the below command to activate the created Python virtual environment:

pyenv activate robot

After this command execution, all the packages installed by pip will be installed in the virtual environment and CPython 3.8.7 will take effect to run all the Python programs.

 

5. Install wxPython using pip command

wxPython is a cross-platform GUI toolkit for the Python programming language. It can be used to create python programs with graphical user interface. wxPython is used by robotframework-ride to construct IDE GUI for editing test cases.

https://www.wxpython.org/blog/2017-08-17-builds-for-linux-with-pip/index.html

 

I specially list wxPython here, because it is not easy to install wxPython. There are some pitfalls during the wxPython installation.

a) Some dependent packages need to be installed in advance before installing wxPython. They have been listed in the above wxPython blog. Those packages are mainly used during wxPython build. You should install the correct packages for your Linux distribution.

b) At the time of writing this post, the latest version of robotframework-ride is 1.7.4, which requires the version of wxPython be less than or equal to 4.0.7. Although the wxPython blog instructs to update ‘setuptools’ using ‘pip install -U setuptools’ command. using setuptools 5x.x to build wxPython 4.0.7 will fail. The below URL describes the installation failure:

https://github.com/wxWidgets/Phoenix/issues/1769

To avoid the installation failure, I suggest to use setuptools 44.1.1.

 

6. Install robotframework packages using pip command

Run the below command to install robotframework related packages:

pip install robotframework

pip install robotframework-seleniumlibrary

pip install robotframework-ride

pip install robotframework-requests

 

7. Install webdriver for the browsers

Robot framework requires the webdriver for the browser you use for automation. In Ubuntu, I suggest to install the webdrivers using apt command as below:

apt install chromium-chromedriver firefox-geckodriver

In RHEL, I suggest to use webdrivermanager tool, which can be installed by ‘pip install webdrivermanager’. The webdrivers can be installed using webdrivermanager command:

webdrivermanager chrome firefox

However, if you are in China, chrome webdriver installation will fail due to the GFW. You need to manually download one and place it in /usr/bin directory.

 

A few days ago, I setup the development environment for robot framework. I summarize the steps here for further reference in case I forget them.