有没有一种方法可以让robot框架代码多次运行一个失败的测试用例



我想多次运行此程序,以测试当用户多次尝试使用错误凭据登录时会发生什么。问题是它只运行一次,如果我再次尝试复制它,它就不会运行其余的代码。

结果应该是"HTTP错误401未经授权,尝试1"但我希望看到10次尝试我试过了,但失败了"${result}=运行特殊命令-k--url https://${url}auth-login${username}-p${password}''

你很可能在这里提出了同样的问题https://forum.robotframework.org/t/i-want-to-test-many-attempted-failed-login/4781-我已经建议研究Run Keyword And Expect Error

但显然这太麻烦了。

*** Variables ***
${url}    http://localhost
${username}   nobody
${password}   notmypassword
*** Keywords ***
Run special command
[arguments]   ${arg1}   ${arg2}   ${arg3}   ${arg4}   ${arg5}   ${arg6}   ${arg7}
[return]    "Nothing to see here folks"
Log To Console     ${arg1} ${arg2} ${arg3} ${arg4} ${arg5} ${arg6} ${arg7}
Fail    This is the error message for failure

*** Test Cases ***
Doesnt Repeat Failure
Log To Console   nThis does show because its start of the testcase
${result}=    Run special command    -k    --url    https://${url}    auth    login    ${username}    -p${password}
${result}=    Run special command    -k    --url    https://${url}    auth    login    ${username}    -p${password}
${result}=    Run special command    -k    --url    https://${url}    auth    login    ${username}    -p${password}
Log To Console   nThis will not be shown because run special command fails
Does Repeat Failure
Log To Console   nThis does show because its start of the testcase
${result}=    Run Keyword And Expect Error  *
...   Run special command    -k    --url    https://${url}    auth    login    ${username}    -p${password}
${result}=    Run Keyword And Expect Error  *
...   Run special command    -k    --url    https://${url}    auth    login    ${username}    -p${password}
${result}=    Run Keyword And Expect Error  *
...   Run special command    -k    --url    https://${url}    auth    login    ${username}    -p${password}
Log To Console   nThis will be shown because we where expecting the error and last call returned a value: : ${result}
Does Repeat Failure with for loop
Log To Console   nThis does show because its start of the testcase
FOR    ${idx}    IN RANGE    10
Log To Console    nIteration: ${idx}
${result}=    Run Keyword And Expect Error  *
...   Run special command    -k    --url    https://${url}    auth    login    ${username}    -p${password}
END
Log To Console   nThis will be shown because we where expecting the error and last call returned a value: : ${result}

本例有3个测试用例,其中一个测试用例在运行时会失败。。2个其他情况将称为您的";运行特殊命令";它总是失败,但测试本身不会失败,因为测试代码EXPECTS关键字调用将在给定参数下失败。

我会有一个进行登录的关键字,然后是一个多次调用该关键字的单个测试用例。

最新更新