如何在Robot Framework中运行特定的测试用例。

huangapple go评论70阅读模式
英文:

how to run specific test cases in robot framework

问题

我想运行一些机器人文件的测试用例。我有测试用例的名称存储在列表中,并且只想运行那些测试用例。

示例:

${my_data_as_list}=    创建列表

${my_data_as_list}= ['打开浏览器','点击链接']

*** 测试用例 ***

打开浏览器

-----打开浏览器    https://demo.nopcommerce.com/   Chrome

点击链接

-----点击链接  xpath:/html/body/div[6]/div[1]/div[1]/div[2]/div[1]/ul/li[2]/a

输入文本

-----输入文本  id:Email     shivani

关闭浏览器 
   
-----关闭浏览器

在这里,我只想调用2个测试用例,即'打开浏览器'和'点击链接',这可以是通用的,就像列表数据可以更改一样,因此应该调用特定的测试用例。

由于我正在自动化处理事物,上面的步骤列表是随机的,可以是任何东西,有时是前两个测试用例,有时是最后两个或全部,因此我想要相应地执行。只需考虑在Python文件中有一个包含未知名称的列表,您已经创建了同名的一些函数,因此可以使用for循环来迭代列表,列表中存在的函数名称将按顺序调用。我想在机器人文件中做同样的事情。

列表=[login, register, close]

对于x在列表中:

调用x

//现在调用登录,然后注册,然后关闭,直到循环结束。

def login():
....

def register ():
....

def calculate ():
....
.
.

还有10-20个其他函数

英文:

I want to run some test cases of robot file. I have names of test cases stored in list and want to run only those.

Example:

${my_data_as_list}=    Create List

${my_data_as_list}= ['open browser','click link']

*** Test Cases ***

open browser

-----Open Browser    https://demo.nopcommerce.com/   Chrome

click link

-----click link  xpath:/html/body/div[6]/div[1]/div[1]/div[2]/div[1]/ul/li[2]/a

input text

-----input text  id:Email     shivani

Close Browser 
   
-----Close Browser

Here I want to call only 2 test cases i.e. 'open browser' and 'click link' which can be generic like list data can be change so particular test case should get called.

As I am automating the things, above list of steps are random that can be anything sometimes 1st two test cases sometimes last two or all, anything so accordingly I want to execute. Just consider the case in python file you have a list of unknown names in it and you have created some functions of the same name so using for loop you can iterate the list and whatever the function name is present in the list that gets called sequentially. Same I want to do in robot file

List=[login, register,close]

For x in List:

Call x

//Now login gets called then register and then close upto the loop ends.

def login():
....

def register ():
....

def calculate ():
....
.
.

More 10-20 functions

答案1

得分: 3

如果这只是暂时的,并且您不想更改文件,您可以在机器人命令的参数中指定测试:

--test '打开浏览器' --test '点击链接' --test '输入文本'。

来源:
http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#test-execution

英文:

If this is a temporary thing and you don't want to change the files you can specify the tests in the arguments of your robot command:

--test 'open browser' --test 'click link' --test 'input text'

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

答案2

得分: 1

为什么不使用RobotFramework的标签功能,并在执行命令行中使用排除选项。

${my_data_as_list}= 创建列表

${my_data_as_list}= ['打开浏览器', '点击链接']

*** 测试用例 ***

打开浏览器

-----打开浏览器 https://demo.nopcommerce.com/ Chrome

点击链接

-----点击链接 xpath:/html/body/div[6]/div[1]/div[1]/div[2]/div[1]/ul/li[2]/a

输入文本

-----输入文本 id:Email shivani

关闭浏览器
[标签] noExec
-----关闭浏览器

命令行: robot --exclude noExec <tests.robot>

在这里查看官方解释: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#by-tag-names

英文:

Why don't you use the tag capabilities of RobotFramework and use the exclude option in the execution command line.

${my_data_as_list}=    Create List

${my_data_as_list}= [&#39;open browser&#39;,&#39;click link&#39;]

*** Test Cases ***

open browser

-----Open Browser    https://demo.nopcommerce.com/   Chrome

click link

-----click link  xpath:/html/body/div[6]/div[1]/div[1]/div[2]/div[1]/ul/li[2]/a

input text

-----input text  id:Email     shivani

Close Browser 
[Tags]     noExec
-----Close Browser

Command line: robot --exclude noExec <tests.robot>

See official explanation here: https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#by-tag-names

huangapple
  • 本文由 发表于 2020年1月6日 20:17:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611977.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定