Running Robot Test Cases in Parallel – pabot

Does your UI automation takes lot of time to complete its full run?
Were you wondering if there was a way to speed this up & also utilize all the CPU & resources of the automation system?

Sounds familiar? pabot seems to be the answer to these problems if you are using Robot Framework.

Most of the test cases in your script would be independent of each other which could be run in parallel.
For e.g, logging into gmail & clicking on various buttons, searching a keyword & composing a mail could be different task. But this need not be done sequentially, all these can be done in parallel, thus saving lots of time.
Unless you want to send a mail & check your ‘Sent Mail’ Folder for the same mail which would be a sequential operation.

Got the idea.

So, to make your UI automation faster use the pabot library for robot.

 

How to setup pabot:

  1. Please refer the section What is the setup involved? of blog Selenium Up & Running with Robot Framework for initial setup.
  2. After initial setup you need to install robotframework-pabot library.  use  pip install robotframework-pabot . This will install both  robotframework-pabot and robotremoteserver.
  3. verify robotframework-pabot is installed successfully
  4. pip show robotframework-pabot
    ---
    Name: robotframework-pabot
    Version: 0.31
    Location: c:\python27\lib\site-packages
    Requires: robotframework, robotremoteserver

 

pabot command line options:

Along with below options it also supports regular pybot options like –include ,–exclude, –outputdir

root@desktop:/home/xyz# pabot --help
A parallel executor for Robot Framework test cases.
Version 0.31.

Supports all Robot Framework command line options and also following
options (these must be before normal RF options):

--verbose
 more output

--command [ACTUAL COMMANDS TO START ROBOT EXECUTOR] --end-command
 RF script for situations where pybot is not used directly

--processes [NUMBER OF PROCESSES]
 How many parallel executors to use (default max of 2 and cpu count)

--resourcefile [FILEPATH]
 Indicator for a file that can contain shared variables for
 distributing resources.

--pabotlib
 Start PabotLib remote server. This enables locking and resource
 distribution between parallel test executions.

--pabotlibhost [HOSTNAME]
 Host name of the PabotLib remote server (default is 127.0.0.1)

--pabotlibport [PORT]
 Port number of the PabotLib remote server (default is 8270)

--suitesfrom [FILEPATH TO OUTPUTXML]
 Optionally read suites from output.xml file. Failed suites will run
 first and longer running ones will be executed before shorter ones.

--argumentfile[INTEGER] [FILEPATH]
 Run same suite with multiple argumentfile options.
 For example "--argumentfile1 arg1.txt --argumentfile2 arg2.txt".

I will be using –processor and –outputdir options in my example test case.

How to run testcases with pabot:

I am using fast.com as web application to demonstrate on how to use Pabot library.

Test Scenario includes 3 test suites which are independent of each other. That means they are eligible for parallel run using pabot.
  1. suite 1: open web application and see it open successfully
*** Settings ***
Library Selenium2Library


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

2. suite 2: check your broadband speed.  –> This test case clicks on the check button and shows speed as output

*** Settings ***
Library Selenium2Library


*** Testcases ***
Check the speed of your broadband
 Open Browser     url=http://www.fast.com
 Sleep     20
 click element     id=speed-progress-indicator-icon
 Sleep     20
 ${speed}=     Get Text id=speed-value
 Close Browser

3. suite 3 : Verify static text on web page.  –> This will verify faq’s texts on the webpage

*** Settings ***
Library Selenium2Library


*** Testcases ***
Verify static data on web page
 Open Browser     url=http://www.fast.com
 Sleep      5
 click element      xpath=//div[3]/div/div/div
 page should contain       What is Fast.com
 page should contain       Why does Fast.com only report on download speed
 Close Browser

 

Create these test suite files and save it in one folder/directory.

suites in folder

Go to the directory where the test cases are saved and run below command

pabot --processes 3   --outputdir c:\pabot-demo\reports\    *.txt

 

Below is the output of the run you can clearly see that 3 processes are spawned and each processes is working one suite in parallel and once the test case is completed processes is killed to free up the cpu.  Also see that the reports are saved under output directory specified in the command.

C:\pabot-demo>pabot --processes 3 --outputdir c:\pabot-demo\reports\ *.txt
[PID:13512] EXECUTING Suites.Suite2 Check Broadband Speed Test
[PID:13996] EXECUTING Suites.Suite1 Open Web Page Successfully
[PID:10456] EXECUTING Suites.Suite3 Verify Static Txt On Web Page
[PID:13996] still running Suites.Suite1 Open Web Page Successfully after 15.0 seconds (next ping in 20.0 seconds)
[PID:10456] still running Suites.Suite3 Verify Static Txt On Web Page after 15.0 seconds (next ping in 20.0 seconds)
[PID:13512] still running Suites.Suite2 Check Broadband Speed Test after 15.0 seconds (next ping in 20.0 seconds)
PASSED Suites.Suite3 Verify Static Txt On Web Page
PASSED Suites.Suite1 Open Web Page Successfully
[PID:13512] still running Suites.Suite2 Check Broadband Speed Test after 35.0 seconds (next ping in 25.0 seconds)
PASSED Suites.Suite2 Check Broadband Speed Test
Output: c:\pabot-demo\reports\output.xml
Log: c:\pabot-demo\reports\log.html
Report: c:\pabot-demo\reports\report.html
Elapsed time: 0 minutes 51.488 seconds

 

Observe that in the Robot report page time taken to execute all three test case using pabot command is less than the total time take to execute all suites if run individually using conventional pybot command.

report-run-time

 

Attaching entire test suite folder for you to try out:

Download-pabot-demo-test-suite

 

Please let me know if you have any questions .

Enjoy…

-Raghavendra Balgi

Like to come up with simple solutions to complex issues encountered during testing security products/applications and to share my knowledge thru blogs. Working as Technical leader in network security domain.

24 thoughts on “Running Robot Test Cases in Parallel – pabot

  1. Hey!
    I do what you say but get these message:

    E:\pabot>pabot –processes 2 –outputdir E:\pabot\results *.txt
    2017-03-23 17:17:38.451000 [PID:4740] [0] EXECUTING Suites.Suite1
    2017-03-23 17:17:38.451000 [PID:10636] [1] EXECUTING Suites.Suite2
    2017-03-23 17:17:38.899000 [PID:10636] [1] FAILED Suites.Suite2
    2017-03-23 17:17:38.899000 [PID:4740] [0] FAILED Suites.Suite1
    WARN: No output files in “E:\pabot\results\pabot_results”
    Output:
    [ ERROR ] Reading XML source ” failed: invalid mode (‘rb’) or filename

    Try –help for usage information.
    Elapsed time: 0 minutes 0.604 seconds

    can you help me with it? Thanks!

          1. Looking at the output tells me that the test cases are run correctly but while creating pabot report it is throwing error.

            1. Please make sure to install “pywin32” python package(A set of extension modules that provides access to many of the Windows API functions)

            use below command
            ————————————–

            pip install pywin32.

            2. If the package is already installed try reinstalling it.

            Let me know if it works for you..

            -Raghavendra.

  2. I am using ubuntu system and I am getting this error get_suite_names: output_file=’./pabot_results/suite_names.xml/pabot_results/suite_names.xml’ does not exist
    No tests to execute
    Elapsed time: 0 minutes 0.7 seconds

    1. Hi Sameer,
      Looks like pabot is not able to find the test case files, please point to the directory where your test cases are placed. I am able to reproduce this issue on windows system as well when there are no test cases in the folder you are pointing to.

      Let me know if it works for you.

      -Raghavendra

  3. Hey Raghavendra,
    Can you help me with the actual flow that goes on between robot framework and pabot?

    Thanks in advance

  4. Hey Raghavendra,
    Can you help me with the actual flow that goes on between robot framework and pabot?

    Thanks in advance

    1. Hi Kashika,
      pabot is a tool which has all pybot robotframework command option + parallel executor module(pabot). So its an extension/plugin on top of robotframework . If you run pabot command it first identifies all the robot framework test cases present in the directory and depending on the number of executors it spawns those number of executors to execute the test cases.

      Please let me know if this clarifies you doubt.

  5. Hi I have my library in Java. will pabot be able to identify custom keywords. I tried to run testcase.txt files parallel but custom keywords are not recognized. what can be the solution?

  6. Hi Raghavendra, thanks a lot for your blog. I am getting same error as Sameer. My testsuite and test cases are in different directories since it is how the framework is set up. Can you pabot example for that? I am giving pabot command from test suite directory.

    1. This cannot be handled through pabot, it can be done through selenium framework level >> hub –> node (selenium grid framework) . pabot will help you execute your test suites in parallel.

  7. Hi Sir
    I am pretty impresed to see this blog
    I have one query, that My all test cases are in one suite Can I run those in parallel?
    please reply

Leave a Reply