使用带有 DataDriver 库的机器人框架未找到变量“${username1}”变量

Variable '${username1}' not found Variable using Robot Framework with DataDriver library

我是 Robot Framework 的新手,现在在我的机器人脚本中使用 DataDriver 库时卡住了。

我的问题:有一条消息:“未找到变量‘${username1}’。”而我 运行 机器人脚本和测试失败了。

我的脚本:

*** Test Cases ***
Login with user ${username} and password ${password}        xyc     123456



*** Keywords ***
Validate Unsuccessful Login
    [Arguments]     ${username1}        ${password1}
    open the browser with the Mortgage payment url
    Fill the login Form     ${username1}        ${password1}
    wait until it checks and display error message
    verify error message is correct
Fill the login Form
    [Arguments]         ${username1}        ${password1}
    input text          id:username          ${username1}
    input password      id:password          ${password1}
    select checkbox     id:terms
    click button        signInBtn

错误:

testDemo5 :: To validate the login form                                       
==============================================================================
Invalidusername,nina,learning                                         | FAIL |
Variable '${username1}' not found.
------------------------------------------------------------------------------
Invalidpassword,rahulshetty,nina                                      | FAIL |
Variable '${username1}' not found.
------------------------------------------------------------------------------
Specialcharacter,@#$##,uqyuyw                                         | FAIL |

如有任何帮助,我们将不胜感激。谢谢

错误Variable '${username1}' not found.可能是由以下一种或多种原因引起的:

  1. CSV 文件在 header 中使用逗号而不是分号
  2. CSV 中有空格 headers
  3. 模板关键字中的参数与测试用例中的嵌入变量不匹配。

看起来问题 3 肯定是您的代码中的情况,因此您需要将 Validate Unsuccessful Login 更改为以下内容:

Validate Unsuccessful Login
    [Arguments]     ${username}        ${password}
    open the browser with the Mortgage payment url
    Fill the login Form     ${username}        ${password}
    wait until it checks and display error message
    verify error message is correct

然后检查您的 csv 文件

此样式有效:

*** Test Cases ***;${username};${password};[Tags];[Documentation]

此样式导致错误:

*** Test Cases ***,${username},${password},[Tags],[Documentation]

这也会导致错误:

*** Test Cases ***; ${username}; ${password}; [Tags]; [Documentation]