简体   繁体   中英

Robot Framework API testing - Create Session keyword not found

I am trying to do API testing with Robot Framework as part of that,i am getting below error

No keyword with name 'createsession mysession' found.Can any body please help how to resolve this error.

I have installed below libraries. robotframework,request,robotframework-request,robotframework-jsonlibrary

Below is the code for the same

===============================================================================================
*** 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}

If your code really is formated like this:

createsession mysession  ${baseurl}

then no such keyword exists in RequestsLibrary .

You need to properly use whitespace, it does matter.

This should work:

Create Session mysession ${baseurl}

remember to type at least two spaces between the keyword and its arguments, and between arguments.

Here's your code which I revised or edited Your issue was just space hence ${baseurl} was not being recognised. Just remember to use TAB instead of space with the robotframework and inspect API to use actual words that are part of the API response.

  *** 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}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM