Is there a way to get Robot Framework to run test suites in a certain order?

半城伤御伤魂 提交于 2019-12-03 11:16:59

Robot framework can use argument files that can be used to specify order of execution (docs):

This is from older docs (not online anymore):

Another important usage for argument files is specifying input files or directories in certain order. This can be very useful if the alphabetical default execution order is not suitable:

Basically, you create something similar to start up script.

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

There is neat feature that from argument file you can call another argument file that can override previously set parameters. Execution is recursive, so you can nest as many argument files as you need

Another option would be to use start up script. Than you have to deal with other aspects like which operating system you are running test on. You could also use python for starting up script on multiple platforms. There is more in this section of docs

If there are multiple test case files in an RF directory , the execution order can be specified by giving numbers as prefixes to test case names , like this.

01__my_suite.html -> My Suite 02__another_suite.html -> Another Suite

Such prefixes are not included in the generated test suite name if they are separated from the base name of the suite with two underscores:

More details are here.

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

You can use tagging.

Tag the tests as foo and bar so you can run each test separately:

pybot -i foo tests

or

pybot -i bar tests

and decide the order

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

or in a script.

The drawback is that you have to run the setup for each test.

Would something like this be of any use?

pybot tests/test1.txt tests/test2.txt

So, to reverse:

pybot tests/test2.txt tests/test1.txt

I had success using a listener:

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 = self.rearrange(data.suites)

    def rearrange(self, arr=[]):
        #arr is a list of <TestSuite> instances
        arr = str(arr)
        #Do some sorting of arr based on self.priorities
        return arr

Assuming foo.robot and bar.robot are contained in a toplevel suite called 'tests', you can run it like this:

pybot --listener Listener.py tests/

This will rearrange childsuites on the fly. It's possible you can modify it upfront using a prerunmodifier instead.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!