【问题标题】:No keyword with name &{headers}= Create Dictionary found in robot在机器人中找不到名称为 &{headers}= 创建字典的关键字
【发布时间】:2019-06-20 01:56:43
【问题描述】:

当我运行此测试时(即测试网站中的登录页面,我得到“No keyword with name &{headers}= Create Dictionary found”。如何使此测试正确运行?

我之前已经安装了所有导入的库,并且在其他测试中使用过它们,所以我知道它们已正确安装。

*** Settings ***
Library     Collections
Library     RequestsLibrary
Library     OperatingSystem
*** Variables ***
${authToken}   
${username} example.user@email.com
${password} password
*** Test Cases ***
Log in Dashboard
    &{data}=    Create Dictionary   email=${username}   password=${password}
    &{headers}= Create Dictionary   Accept=application/json, text/plain, */*    Content-Type=application/json   Origin=http://examplesite.com   Referer=http://examplesite.com/angular/
    Create session  example   http://examplesite.com
    ${response}=    Post Request    example   /admin/login data=${data}    headers=${headers}
    log ${response}
    log ${response.json()}
    ${allocation_response}= To Json ${response.content}
    Set Global  Variable

【问题讨论】:

    标签: automated-tests robotframework


    【解决方案1】:

    可能你的 IDE 太“聪明”了,即使你点击了 TAB,它也只在此处插入了一个空格:

    &{headers}= Create Dictionary   Accept=application/json, text/plain, */*    Content-Type=application/json   Origin=http://examplesite.com   Referer=http://examplesite.com/angular/
    

    变量和关键字之间似乎只有一个空格,因此它被视为一个关键字。在那里添加更多空间来修复它。

    &{headers}=    Create Dictionary   Accept=application/json, text/plain, */*    Content-Type=application/json   Origin=http://examplesite.com   Referer=http://examplesite.com/angular/
    

    可能你在这一行也会遇到同样的问题:

    ${allocation_response}= To Json ${response.content}
    

    【讨论】:

      猜你喜欢
      • 2015-01-10
      • 2021-01-08
      • 1970-01-01
      • 2019-05-14
      • 2019-12-21
      • 2019-01-01
      • 2017-09-18
      • 2015-03-06
      相关资源
      最近更新 更多