Friday, 4 July 2014

Configuring Jenkins Agent to run Robot Framework Tests

This covers the instructions to setup the client machine (the Jenkins Agent) on which the robot framework test cases will run) and the instructions to create a jenkins job to run the robot test cases.

On the Client Machine:
Pre-Conditions:
Install the mandatory softwares (if missing) in the agent machine as shown below:
yum install firefox
yum install vim
yum install dbus
dbus-uuidgen > /var/lib/dbus/machine-id
yum install gcc
yum list installed | grep ssl
yum install openssl openssl-devel
yum install zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel


On CentOS, you need the postgres dev packages (in case you are running Postgres related tests):
sudo yum install postgresql-devel

Below are the steps to be done on the client machine (CentOS) which will run the Robot framework test case:
1. Log in to the Agent Machine:
   ssh root@<ip>

2. To run the browser in headless mode execute the below:
           yum install Xvfb - check
which Xvfb (It is be located in /usr/bin)
cd /usr/bin

Create a file called "Xvfb.sh"
vim Xvfb.sh

Add the below script in the ‘Xvfb.sh’ file:

#!/bin/sh
mode=$1
case "$mode" in
'start')
if [ -f /usr/bin/Xvfb ]; then
    echo "***Starting up the Virtual Frame Buffer on Screen 1***"
    /usr/bin/Xvfb :99 -screen 0 1152x900x8 &
fi
;;
*)
echo " Usage: "
echo " $0 start (start XVFB)"
echo " $0 stop (stop XVFB - not supported)"
exit 1
;;
esac
dbus-uuidgen > /var/lib/dbus/machine-id
exit 0

(For more details please refer http://sahi.co.in/w/configuring-sahi-with-xvbf )

Run the script using the below command:
sh Xvfb.sh start


3. Install pyenv to switch between Python versions:

mkdir /localdisk
cd /localdisk
git clone git://github.com/yyuu/pyenv.git pyenv

Find the path where pyenv is installed and add the below in ~/.bashrc file
   export PYENV_ROOT=/localdisk/pyenv
   export PATH=$PYENV_ROOT/bin:$PATH

Reload the env variables:
   source ~/.bashrc


4. Installing Python 2.7.5 :
    Install Python 2.7.5 using the below command:   
           pyenv install 2.7.5


(In case of build failure please refer https://github.com/yyuu/pyenv/wiki/Common-build-problems)


5. Installing Virtual Env:
Go upto the bin directory of Python installed via pyenv and install virtualenv:
  cd /localdisk/pyenv/versions/2.7.5/bin
   ./pip install virtualenv



1. Open the Jenkins webpage.
2. Create a new job.
3. Do the mandatory things like adding the gitlab/svn URL (To checkout the Robot framework test cases), agent machine's label (The slave machine should be created)  and Build Parameters (If needed)


4. Add the below shell script which will run the Robot framework test:

echo "Start the UI tests...................."

PYENV_HOME=$WORKSPACE/.pyenv

# Delete previously built virtualenv
if [ -d $PYENV_HOME ]; then
  rm -rf $PYENV_HOME
fi

# Create virtualenv and install necessary packages
/localdisk/pyenv/versions/2.7.5/bin/virtualenv $PYENV_HOME
. $PYENV_HOME/bin/activate

# You could also run "sudo pip install --quiet $WORKSPACE/" where your setup.py file lives

pip install --quiet robotframework
pip install --quiet robotframework-httplibrary
pip install --quiet robotframework-selenium2library
pip install --quiet robotframework-randomlibrary
pip install --quiet robotframework-DatabaseLibrary

#Specify the display here since we're using Xvfb (Xvfb :99 -ac -screen 0 1280x1024x24 +extension RANDR)
export DISPLAY=:99

#Execute our tests!
pybot -L TRACE /my/robot/test/cases

5. In Post-build actions, add ‘Publish Robot Framework Test Report” (The robot Framework plugin should be installed in the Jenkins server)
.
Directory of Robot output = $WORKSPACE
Thresholds for build result = 75 to 90 ( As desired)





6 comments:

  1. i am entering pybot xyz.txt as exceute shell command but it says pybot is not recoginized command

    ReplyDelete
    Replies
    1. you need to install libraries, perhaps from your requirements file.
      pip install -r requirement.txt

      Delete
  2. i am entering pybot xyz.txt as exceute shell command but it says pybot is not recoginized command

    ReplyDelete
  3. Try referring giving the full path.
    E.g., /pyenv/versions/2.7.6/bin/pybot

    ReplyDelete
  4. @Disha you have to set Shell executable for that purpose you have to follow below steps
    Go to Jenkins Configuration > Shell executable
    Enter your cmd.exe path in my case it is 'C:\Windows\system32\cmd.exe'
    Save the changes it will work for you

    ReplyDelete
  5. You have to set the following paths in system env variables under PATH variable.

    C:\Python27\;C:\Python27\Scripts;C:\Python27\Tools;C:\Python27\Lib\site-packages;

    ReplyDelete