创建机器人框架关键字模板,然后测试用例模板



如何使用模板化机器人关键字而不是使用[Template]语法的整个测试用例?

需要的是:

资源文件在关键字中创建一个关键字.robot:

*** Keywords ***
Do Something
  [Arguments]    ${arg1}   ${arg2}
  Print args    ${arg1}   ${arg2}

机器人测试用例文件导入此资源并使用上述关键字作为:

Resource keywords.robot
*** Test cases ***
Some test case
   Execute test step 1
   Execute test step 2
   Execute test step 3
   #Now use the Keyword defined in resource file with [Template]
   Do Something
   [Template]
    1   2
    3   4

有没有办法达到上述要求? 因为有些测试步骤需要用参数重复,而不是整个测试用例。谢谢。

一种可能的解决方案是将测试用例分成两部分,第一部分包含步骤 1-3,第二部分包含模板。您可以设定条件是,如果第一部分失败,则第二部分在开始时失败。

您可以通过将"应该相等"更改为通过或失败来测试这两种变体:

*** Variables ***
${Failed}   ${False}
*** Test cases ***
Some test case part 1
  Log   Keyword 1
  Log   Keyword 2
  Should Be Equal   1   1
  [Teardown]  Run Keyword If Test Failed    Set Suite Variable   ${Failed}   ${true}
Some test case part 2
  [Setup]   Run Keyword If   ${Failed}    Fail   Previous part failed
  [Template]   Do Something
    1   2
    3   4
*** Keywords ***
Do Something
  [Arguments]    ${arg1}   ${arg2}
  Log     ${arg1}, ${arg2}

此外,如果更简单的解决方案满足您的需求,您还可以将前 3 个步骤添加到设置中。

最新更新