我是机器人框架的新手。我有一个.robot文件,其中有5个测试用例,其中定义了每个测试用例的标记。也就是说,3个测试用例具有[tags] debug,两个测试用例具有[tags] preprod
现在,我有了一个套件设置和套件拆卸,对于那些具有标记的测试用例,调试将执行某些步骤,而对于标记preprod,不需要执行相同的步骤。
代表:
*** Settings ***
Suite Setup Run Keywords
... Connect To DB AND
... Create An Employee
Suite Teardown Run Keywords
... Delete DB entries AND
... Disconnect From DB
*** Test Cases ***
TC1
[Tags] Debug
log to console Test1
TC2
[Tags] Debug
log to console Test2
TC3
[Tags] Debug
log to console Test3
TC4
[Tags] preprod
log to console Test4
TC5
[Tags] preprod
log to console Test4现在,TC4和TC5不需要在套件设置中执行Create An Employee,在套件拆卸中执行Delete DB entries。
如何实现如果测试用例具有tag=Debug,则在套件设置和套件拆卸中执行步骤
发布于 2020-03-17 15:52:16
在任何测试开始之前,套件设置只运行一次。不可能让它为每个测试做一些不同的事情。
如果要对每个测试执行某些操作,则需要使用测试设置。例如,如果测试有"Debug“或"preprod”标记,则这里有一个关键字将记录不同的字符串:
*** Settings ***
Test Setup Perform logging
*** Keywords ***
Perform logging
run keyword if 'Debug' in $test_tags
... log this test has a debug tag
run keyword if 'preprod' in $test_tags
... log this is preprod WARN发布于 2020-03-18 06:38:25
继续布赖恩的回答。您需要理解,在“设置”部分中定义的测试设置将适用于所有测试用例。
因此,对于Debug和preprod标记,您将执行相同的测试设置。
简而言之,您希望基于标记设置不同的测试。
要实现这一点,您需要使用同名的自定义关键字,即在您希望具有特定标记的测试用例中使用测试设置。
下面是一个同样的例子。
*** Settings ***
Test Setup log to console parent test setup
*** Test Cases ***
TC1
[Tags] Debug
log to console Test1
${success} = Run Keyword and Return Status Submit The Job #Code will not switch to next keyword untill this keyword return the satus as True or False
log ${success}
wait until keyword succeeds 2x 200ms Submit The Job #This Kw will run the KW 2 times if KW fails while waiting 200ms after each result
TC2
[Tags] production
[Setup] Test Setup #this is your custom KW, which will overwrite Test Setup
log to console Test1
${success} = Run Keyword and Return Status Submit The Job #Code will not switch to next keyword untill this keyword return the satus as True or False
log ${success}
wait until keyword succeeds 2x 200ms Submit The Job #This Kw will run the KW 2 times if KW fails while waiting 200ms after each result
*** Keywords ***
Submit The Job
Sleep 10s
Test Setup
log to console child setup现在讲到最后一点,您可以使用-e,即在标记中排除选项来运行特定的测试用例
所以命令是
robot -i "Debug" -e "production" sample_tc.robot这将只执行第一个TC,即TC1
https://stackoverflow.com/questions/60716982
复制相似问题