首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >是否有办法使机器人框架代码多次运行失败的测试用例?

是否有办法使机器人框架代码多次运行失败的测试用例?
EN

Stack Overflow用户
提问于 2022-10-04 14:15:26
回答 2查看 113关注 0票数 -1

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

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

EN

Stack Overflow用户

回答已采纳

发布于 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

但很明显那太麻烦了。

代码语言:javascript
运行
复制
*** 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种情况下,调用您的“运行特殊命令”总是失败,但测试本身不会失败,因为测试代码期望关键字调用将在给定参数下失败。

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73949310

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档