有没有办法让Robot Framework按特定顺序运行测试套件?

时间:2013-05-01 17:03:36

标签: testing robotframework

假设我在本地目录foo和bar中有2个测试套件,我想按照foo然后bar的顺序运行测试套件。

我试图运行pybot -s foo -s bar .,但它只是运行bar然后foo(即按字母顺序排列)。

有没有办法让pybot运行机器人框架套件以我定义的顺序执行?

5 个答案:

答案 0 :(得分:13)

机器人框架可以使用参数文件,可用于指定执行顺序(docs):

这是来自较旧的文档(不再在线):

  

参数文件的另一个重要用法是按特定顺序指定输入文件或目录。如果字母默认执行顺序不合适,这可能非常有用:

基本上,你创建类似于启动脚本的东西。

--name My Example Tests
tests/some_tests.html
tests/second.html
tests/more/tests.html
tests/more/another.html
tests/even_more_tests.html

有一个很好的功能,从参数文件你可以调用另一个参数文件,它可以覆盖以前设置的参数。执行是递归的,因此您可以根据需要嵌套任意数量的参数文件

另一种选择是使用启动脚本。您必须处理其他方面,例如您正在运行测试的操作系统。您还可以使用python在多个平台上启动脚本。 docs

的这一部分还有更多内容

答案 1 :(得分:10)

如果RF目录中有多个测试用例文件,则可以通过将数字作为测试用例名称的前缀来指定执行顺序,如下所示。

01__my_suite.html - >我的套房 02__another_suite.html - >另一个套房

如果这些前缀与具有两个下划线的套件的基本名称分开,则这些前缀不包含在生成的测试套件名称中:

更多细节在这里。

http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#execution-order

答案 2 :(得分:4)

您可以使用tagging

将测试标记为 foo bar ,以便您可以单独运行每个测试:

pybot -i foo tests

pybot -i bar tests

并决定订单

pybot -i bar tests || pybot -i foo tests

或在剧本中。

缺点是您必须为每个测试运行设置。

答案 3 :(得分:1)

这样的事情会有用吗?

pybot tests/test1.txt tests/test2.txt

所以,反过来说:

pybot tests/test2.txt tests/test1.txt

答案 4 :(得分:0)

我成功使用了监听器

Listener.py

class Listener(object):
    ROBOT_LISTENER_API_VERSION = 3

    def __init__(self):
        self.priorities = ['foo', 'bar']

    def start_suite(self, data, suite):
        #data.suites is a list of <TestSuite> instances
        data.suites = self.rearrange(data.suites)

    def rearrange(self, suites=[]):
        #Do some sorting of suites based on self.priorities e.g. using bubblesort
        n = len(suites)
        if n > 1:
            for i in range(0, n):
                for j in range(0, n-i-1):
                    #Initialize the compared suites with lowest priority
                    priorityA = 0
                    priorityB = 0
                    #If suite[j] is prioritized, get the priority of it
                    if str(suites[j]) in self.priorities:
                        priorityA = len(self.priorities)-self.priorities.index(str(suites[j]))
                    #If suite[j+1] is prioritized, get the priority of it
                    if str(suites[j+1]) in self.priorities:
                        priorityB = len(self.priorities)-self.priorities.index(str(suites[j+1]))
                    #Compare and swap if suite[j] is of lower priority than suite[j+1]
                    if priorityA < priorityB:
                        suites[j], suites[j+1] = suites[j+1], suites[j]             
        return arr

假设foo.robot和bar.robot包含在称为“测试”的顶级套件中,则可以这样运行它:

pybot --listener Listener.py tests/

这会即时重新安排儿童套房。您有可能可以使用prerunmodifier预先对其进行修改。

相关问题