Python 如何使用 Robot Framework 从测试套件运行特定的测试用例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25005277/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run specific test cases from a test suite using Robot Framework
提问by Mysterio Man
I am new to Robot and am learning to write logic and test cases.
我是机器人的新手,正在学习编写逻辑和测试用例。
I have a test suite, "mytestsuite.robot", which has a lot of test cases. I have a couple of errors in one of my test cases.
我有一个测试套件“mytestsuite.robot”,它有很多测试用例。我的一个测试用例中有几个错误。
How do I run just that specific test case since I don't want to run the whole test suite again?
由于我不想再次运行整个测试套件,我该如何只运行那个特定的测试用例?
File mytestsuite.robot
文件 mytestsuite.robot
testcase1
....
....
testcase2
....
....
testcase3
....
....
testcase4
....
....
Say test case 3 failed, and I want to just rerun test case 3.
假设测试用例 3 失败了,我只想重新运行测试用例 3。
I tried to use:
我尝试使用:
pybot mytestsuite.robot -t testcase3
But I get an error.
但我得到一个错误。
采纳答案by Bryan Oakley
You want to use the option -tor --test, but the option goes beforethe name of the file rather than after. This should work:
您想使用选项-tor --test,但该选项位于文件名之前而不是之后。这应该有效:
robot -t testcase1 mytestsuite.robot
The order of the command line arguments is covered in the user guide under a section titled Starting test execution, and is also available at the command line with the --helpoption (e.g. pybot --help)
命令行参数的顺序在用户指南中标题为开始测试执行的部分中介绍,并且也可以在命令行中使用--help选项(例如pybot --help)
Be aware that the specific file name is optional. You could use only: robot -t testcase1 .
请注意,特定文件名是可选的。您只能使用: robots -t testcase1 。
Where "." means look for all files that contains the specified test. Robot will do the hard work of finding the specific test.
在哪里 ”。” 表示查找包含指定测试的所有文件。机器人将努力寻找特定的测试。
You can use also willcard as * in the begining or finish of the test name, to match easily a test or to run multiple tests.
您也可以在测试名称的开头或结尾使用 willcard 作为 *,以轻松匹配测试或运行多个测试。
robot -t "testcase1*" .
机器人 -t "testcase1*" 。
Will match all tests that begin with "testcase1" in current folder.
将匹配当前文件夹中以“testcase1”开头的所有测试。
The user guide has a section titled Selecting test caseswhich covers this subject.
用户指南有一个标题为“选择测试用例”的部分,其中涵盖了该主题。
回答by Logan M
If you want to run singletest case in Robot Framework, use the below example.
如果要在 Robot Framework 中运行单个测试用例,请使用以下示例。
Syntax: robot -t "Test Case Name" Test Suite Name
Example: robot - t "PON Type Test Case" Aquarium_Project.robot
语法: robot -t "Test Case Name" Test Suite Name
示例:robot - t "PON Type Test Case" Aquarium_Project.robot
If you want to run allthe test cases in Robot Framework, use the below example
如果要在 Robot Framework 中运行所有测试用例,请使用以下示例
Syntax: robot Test Suite Name
Example: robot Aquarium_Project.robot
语法:robot Test Suite Name
示例:robot Aquarium_Project.robot
回答by kzh
If you are using __init__.robotfiles that have setups and teardowns, you cannot directly call a test from a test file if you have nested directory structures like the following:
如果您正在使用__init__.robot具有设置和拆卸的文件,并且具有如下嵌套目录结构,则无法直接从测试文件调用测试:
|-- foo
|-- bar.robot
And the bar.robot file has a test case named baz, in this case, you can do the following:
bar.robot 文件中有一个名为 baz 的测试用例,在这种情况下,您可以执行以下操作:
robot --test 'foo.bar.baz' foo
With deeper nesting:
使用更深的嵌套:
|-- foo
|-- bar
|-- baz.robot
robot --test 'foo.bar.baz.*' foo
You can use *(asterisk) to run all test cases in the foo.bar.baz suite.
您可以使用*(星号)运行 foo.bar.baz 套件中的所有测试用例。

