0

作为其中的一部分,我正在尝试使用 Robot Framework 进行 API 测试,但我遇到了错误

找不到名称为“createsession mysession”的关键字。任何人都可以帮助解决此错误。

我已经安装了下面的库。机器人框架,请求,机器人框架请求,机器人框架 json 库

下面是相同的代码

===============================================================================================
*** Settings ***
Library   RequestLibrary

*** Variables ***
${baseurl}   http://demoqa.com/utilities/
${endpoint}  weather/city/

*** Keywords ***

*** Test Cases ***
TestCaseone

  createsession mysession  ${baseurl}
  ${response}=  Get Request  mysession  ${endpoint}/bangalore
  log to console  ${response.status.code}
  log to console  ${response.status.body]
  log to console  ${response.header}
4

2 回答 2

1

如果你的代码真的是这样格式化的:

createsession mysession  ${baseurl}

那么RequestsLibrary中不存在这样的关键字。

您需要正确使用空格,这很重要。

这应该有效:

Create Session mysession ${baseurl}

请记住在关键字及其参数之间以及参数之间至少键入两个空格。

于 2021-02-01T12:12:24.753 回答
0

这是我修改或编辑的代码您的问题只是空间,因此 ${baseurl} 未被识别。请记住在机器人框架中使用 TAB 而不是空格,并检查 API 以使用作为 API 响应一部分的实际单词。

  *** Settings ***
  Library   RequestsLibrary

  *** Variables ***
  ${baseurl}   http://demoqa.com/utilities/
  ${endpoint}  weather/city/

  *** Keywords ***

  *** Test Cases ***
  TestCaseone
      createsession    mysession  ${baseurl}
      ${response}=     Get On Session  mysession  ${endpoint}/bangalore
      log to console   ${response.text}
      log to console   ${response.content}
      log to console   ${response.headers}
于 2021-05-19T10:56:25.853 回答