RobotFramework,为“运行”创建多个实例

时间:2019-06-07 14:09:41

标签: python robotframework

我大约有50个“机器人”文件,我想并行运行4个机器人文件(使用多线程)。如果一个文件通过,则应继续选择。我在这里使用以下类型的代码。

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)

我面临的问题是: 1.全部输出仅写入一个文件 2.它没有生成日志和结果 3.并且未正确生成output.xml。

由于run命令在内部仅创建一个引用,因此类似情况正在发生。有没有一种创建多个实例的方法。

类似 instance = robot.run()

2 个答案:

答案 0 :(得分:1)

无需重新发明轮子,已经有一种解决方案可以并行执行机器人框架测试套件,请查看PaBot。该解决方案还允许您并行运行测试用例而不是测试套件,只需要使用适当的运行时选项即可。

还值得一提的是,它甚至具有一个库(PaBotLib),该库可让您在测试中实现“锁”,以防万一您的操作不是“线程安全的”

答案 1 :(得分:0)

我还没有测试,但是下面的方法可以工作。基本上创建西服名称的输出目录并将结果写入其中。

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()