【问题标题】:Variable '${username}' not found while using Robot Framework with DataDriver library使用带有 DataDriver 库的 Robot Framework 时找不到变量“${username}”
【发布时间】:2021-02-21 06:17:00
【问题描述】:

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

我的问题: 有一条消息:“未找到变量 '${username}'。”当我运行机器人脚本时,测试失败了。

这是我的机器人脚本:

*** Settings ***
Library  DataDriver  file=resources/user_password.csv  encoding=utf_8  dialect=unix
Test Template  Test Credential

*** Test Cases ***
Doing Test Credentials for ${username} and ${password}

*** Keywords ***
Test Credential
    [Arguments]     ${username}     ${password}
    Log  ${username}
    Log  ${password}

这是我的 CSV 文件:

*** Test Cases ***, ${username}, ${password}, [Tags], [Documentation]
Valid user, user@mail.com, pass123, Positive, This is valid user credential
Invalid user, invalid@mail.com, pass123, Negative, This user is invalid
Invalid password, user@mail.com, pass, Negative, This password is invalid
Blank user, ${EMPTY}, pass123, Negative, Blank user
Blank password, user@mail.com, ${EMPTY}, Negative, Blank password
Blank user and password, ${EMPTY}, ${EMPTY}, Negative, Blank both user and password

任何帮助将不胜感激。谢谢。

威利

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    我认为问题出在:

    *** Test Cases ***
    Doing Test Credentials for ${username} and ${password}
    

    您没有将任何变量传递给关键字,如 DataDriver 库的文档中所示:https://github.com/Snooz82/robotframework-datadriver#example-test-suite

    解决方案是将一些值传递给关键字:

    *** Test Cases ***
    Doing Test Credentials for ${username} and ${password}    secret-user    secret-pwd
    

    编辑:

    另一个是 csv 文件的格式。如果我删除它们,则在每个逗号后包含空格:

    *** Test Cases ***,${username},${password},[Tags],[Documentation]
    Valid user,user@mail.com,pass123,Positive,This is valid user credential
    

    我可以毫无问题地运行它:

    和报告:

    【讨论】:

    • 我已经在该行添加了这个'secret-user secret-pwd',消息是一样的。
    • @Welly:你是对的。我已经更新了我的答案,现在试试。它应该可以工作,我已经尝试过了。
    • @Welly 请不要忘记将答案标记为已接受。
    • 如何将答案标记为已接受?仅供参考,我是新的 stackoverflow 用户。
    • 好的,我已阅读 stackoverflow 用户指南以标记已接受答案。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2012-06-08
    • 2013-01-01
    • 2021-11-08
    相关资源
    最近更新 更多