我想多次运行这个程序,测试当用户多次尝试使用错误的凭据登录时会发生什么。问题是,它只运行一次,如果我再次尝试复制它,它就不会运行其余的代码。
结果应该是‘’HTTP 401未经授权,尝试1‘’,但我希望看到10次尝试--我尝试了10次,但失败了‘${ result }=运行特殊命令-k --url https://${url} auth登录${username} -p${password}’“
发布于 2022-10-05 13:08:26
从您最有可能在这里提出的相同问题中,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种情况下,调用您的“运行特殊命令”总是失败,但测试本身不会失败,因为测试代码期望关键字调用将在给定参数下失败。
https://stackoverflow.com/questions/73949310
复制相似问题