How to load a json data file into a variable in robot framework?

后端 未结 5 1611
庸人自扰
庸人自扰 2021-01-02 18:16

I Am trying to load a json data file into a variable directly in Robot Framework. Can anyone please elaborate with an e.g. giving the exact syntax as to how to do it? Thanks

5条回答
  •  隐瞒了意图╮
    2021-01-02 19:09

    I had similar issue and this work fine with me:
    ${json} Get Binary File ${json_path}nameOfJsonFile.json

    It works for me on API testing, to read .json and POST, like here

    *** Settings ***
    Library    Collections
    Library    ExtendedRequestsLibrary 
    Library    OperatingSystem
    *** Variables ***  
    ${uri}    https://blabla.com/service/
    ${json_path}    C:/home/user/project/src/json/
    *** Test Cases ***
    Name of Robot Test Case  
        Create Session    alias    ${uri}    
        &{headers}  Create Dictionary  Content-Type=application/json; charset=utf-8
        ${json}  Get Binary File  ${json_path}nameOfJsonFile.json
        ${resp}    Post Request    alias    data=${shiftB}    headers=${headers}
        Should Be Equal As Strings    ${resp.status_code}    200
    

    There are also cases when you will need to transform read binary file (in my case ${json} to a dictionary but first try this simple solution.

提交回复
热议问题