0

我是机器人框架的新手。我有一个 .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在套件设置和套件拆解中有执行步骤,如何实现

4

2 回答 2

0

套件设置在任何测试开始之前运行一次。不可能让它为每个测试做不同的事情。

如果您想为每个测试执行一些操作,您需要使用测试设置。例如,如果测试有“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-17T15:52:16.683 回答
0

继续布莱恩的回答。您需要了解设置部分中定义的测试设置将适用于所有测试用例。

作为Debugpreprod标签的结果,您将执行相同的测试设置。

简而言之,您需要基于标签的不同测试设置。

要实现这一点,您需要在您打算拥有特定标签的测试用例中使用同名的自定义关键字,即测试设置。

这是一个执行相同操作的示例。

*** 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

于 2020-03-18T06:38:25.180 回答