0

I have around 50 "robot" files and I want to run 4 robot files in parallel (using multithreading). If one file gets over, it should pick next. I am using the following code here.

from robot import run
myarray= [file1, file2, file3....file50]

for f in myarry: 
       SOME LOGIC WHICH HOLDS THE LOOP TILL FILE COUNT IS 4
       func1(f)

def func1(file)
     outputlogFile = open(fname , 'w')
     run(file, outputdir=reportdir, stdout=outputlogFile)

The problems I am facing are:

  1. All outout is written in only one file
  2. It is not generating log and result
  3. And output.xml is not properly generated.

Looks like this is happening as run command is internally creating only one reference. Is there a way to create multiple instances.

something like

instance= robot.run()
1
  • Are you aware of Pabot which does what you describe. Commented Jun 7, 2019 at 17:45

2 Answers 2

2

No need to reinvent the wheel, there's already a solution to execute robot framework test suites in parallel, take a look at PaBot. The solution also allows you to run test cases in parallel instead of test suites, just gotta use the proper runtime options.

Also worth mentioning it even has a library (PaBotLib) that allows you to implement "locks" in your tests, for cases where you have actions that aren't "thread safe"

Sign up to request clarification or add additional context in comments.

2 Comments

Hi @Verv, I had already explored pabot few years back. There are few limitation pabot has, that is why I had to write my own runner. (Some problems, i.e. 1.I have different directories for suites and not all of them need to be executed but selective, 2. Not sure if I can pass 500 suite name with full path in pabot 3. I want a different report for each case and not a merged one. 4. I have different variable passed for each suite and there are few more)
To select which tests/suites to execute, given that you don't want to execute all of them, you should use tags. This is a builtin feature of robot framework. Also keep in mind you could launch multiple pabot instances, the general idea is just to not write your own version of pabot when it's already available. For your requirements pertaining to reports, I'm sure you can tweak something from the available options, the reports are pretty customizable, I remember I did some really funky stuff a few years ago with robot framework's built-in options and rebot
1

I have not tested but something like below can work. Basically creating output directory of suit name and writing results into it.

import collections
from robot import run
import os
import threading


def runConcurrent(dq):
    suit = dq.pop()
    if len(dq) != 0:
        os.mkdir(suit)
        run(suit,
            outputdir=suit
        )
        runConcurrent(dq)
    else:
        return 0

if __name__ == "__main__":
    all_suits = collections.deque(["file1.robot", "file2.robot", "file3.robot", "file4.robot"])
    t1 = threading.Thread(target=runConcurrent, args=(all_suits,))
    t2 = threading.Thread(target=runConcurrent, args=(all_suits,))
    t3 = threading.Thread(target=runConcurrent, args=(all_suits,))
    t4 = threading.Thread(target=runConcurrent, args=(all_suits,))
    t1.start()
    t2.start()
    t3.start()
    t4.start()
    t1.join()
    t2.join()
    t3.join()
    t4.join()

1 Comment

I have very much identical solution. But "run" is not creating a different instance but taking the latest one which is overwriting output dir, lots and so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.