recent posts

How to setup Jenkins and Robot Framework with Git

This is a quick and dirty guide to setting up Robot Framework in Jenkins. Since we store all of our robot test cases in git, we will utilize Source Control to ensure we are running our latest tests. This guide also assumes you have a remote selenium grid setup to run tests against. For more detailed steps on how some of the steps are done, please review the reference links. And as always, please ensure you have a backup of Jenkins or whatever you are modifying before you start! 

Required Installations on Jenkins 
     - git
     - python 2.7+
     - robotframework
     
Required Plugins for Jenkins
     - Jenkins GIT plugin              
     - Robot Framework plugin        

SSH onto the Jenkins machine itself.
1) Verify python is installed (check using which python)
     - If not installed, please look for a more detailed python installation guide. 
          - Detailed Python Install Guide 2        
     - Important Note, you can stick with the default version of python, but I opted for version 2.7 and since Jenkins is installed on a CentOS box, version 2.6 should automatically be installed by default. I decided to install a separate 2.7 python package to prevent deprecated command warnings.

     Example warnings from 2.6 that are not present in 2.7
          /usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py:548: DeprecationWarning: use driver.switch_to.alert instead
  warnings.warn("use driver.switch_to.alert instead", DeprecationWarning)

     /usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py:542: DeprecationWarning: use driver.switch_to.default_content instead
  warnings.warn("use driver.switch_to.default_content instead", DeprecationWarning)
     /usr/lib/python2.6/site-packages/selenium/webdriver/remote/webdriver.py:536: DeprecationWarning: use driver.switch_to.frame instead
  warnings.warn("use driver.switch_to.frame instead", DeprecationWarning)
    
      Below is a simple guide for version 2.7:
          Retrieve and untar python package
          wget https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
          xz -d Python-2.7.10.tar.xz
          tar -xvf Python-2.7.10.tar
          
          Build and Install package
          cd Python-2.7.10
          ./configure --prefix=/usr/local
          make && make altinstall
     
          Install pip
          wget https://bootstrap.pypa.io/get-pip.py
          python2.7 get-pip.py

          Install Virtualenv
          pip2.7 install virtualenv
          If you are having pathing issues, you can always try loading the source of 2.7
          sudo /usr/local/bin/pip install virtualenv

2) Verify git is installed (if not installed, a simple yum install git should do the trick)
3) Install robotframework and selenium libraries
           pip2.7 install robotframework
           pip2.7 install robotframework-selenium2library
4) Setup an SSH key pairing (no passphrase) between Jenkins and bitbucket (or wherever your code is hosted)
     - Good reference material https://help.github.com/articles/generating-ssh-keys/ 
     - If you are having trouble after setting up the pairing, make sure to run the command that jenkins gives out on the box itself. There is a first time setup message that prompts the user whether or not to trust the source.

5) Create a new jenkins job (Check the jenkins robot plugin guide)
     Example:
          a) Build free-style > Add build step > Execute Shell
              pybot --variable browser:firefox --output my_robot_results my_test_suite
          b) Add Post-build Actions > Publish Robot Framework Test Results
               Directory of Robot Output  > my_robot_results
          c) Select Advanced ... Options if you want to save screen shots in your reports
               Output xml name > output.xml
               Report html name > report.html
               Log html name > log.html
               Other files to copy > *.png
     - The plugin guide mentions that you should have all results return as Exit 0 to let the plugin decide on whether it is a success/failure, but I opted to just have a Build Failure whenever there is a failed test.
     - Post-Build Actions > Publish Robot Framework Test Results
     - Disable thresholds, you should only be writing critical tests

5a) PROTIP: If you want to run multiple browsers with the same jenkins job, instead of using a free-style project, use a multi-configuration project and define your matrix variables for the browser.
     Configuration Matrix > User-defined Axis
          Name > BROWSER
          Values > chrome firefox safari
     Once you define your matrix, calling robot only requires a small change.
          pybot --outputdir my_robot_results --variable BROWSER:$BROWSER my_test_suite

6) You should now be able to run your tests! Results will be displayed under "Robot Results" in the vertical menu options.

Sample Screenshots




Good luck and have fun with Robot Framework and Jenkins!

P.S. If you are running on CentOS and pybot is still running python 2.6, you can force robot to use version 2.7.
vim /usr/bin/pybot
Change the first line from 
#!/usr/bin/python to #!/usr/local/bin/python2.7
How to setup Jenkins and Robot Framework with Git How to setup Jenkins and Robot Framework with Git Reviewed by JJ The Engineer on 12:49 PM Rating: 5

2 comments:

  1. getting this issue ..please help..i am struck to fetch results..

    Robot results
    No robot results available yet!
    Run a build with robot plugin enabled to see results here



    TestLink Results
    No TestLink results available yet!
    Run a build with TestLink plugin enabled to see results here

    ReplyDelete
  2. Is it possible to setup robotframework with Jenkin only without GIT? So, we just provide the directory of robot test cases only.

    ReplyDelete

Powered by Blogger.