目前我有一个自定义库来读取json文件并输出列表。例如
def get(f):
with open(f) as fd:
data=json.load(fd)
return [ k for k in data['d']['a'] ]
然后在RF中,我称之为
@{items}= get "f.json"
有没有办法在没有自定义功能的情况下在Robotframework中本地执行此操作?我通过HttpLibrary看了一下但是找不到任何相关内容。
答案 0 :(得分:1)
*** Settings ***
# Import Robot Framework Libraries
Library OperatingSystem
# Import Python Library
Library json
*** test cases ***
mytest
# no need for double quote around file name. Variables are string by default
@{item} = get_in_robot f.json
*** Keywords ***
get_in_robot
[Arguments] ${file_path}
${data_as_string} = Get File ${file_path}
${data_as_json} = json.loads ${data_as_string}
# looking into the dict at ["d"]["a"] will return the list
[Return] ${data_as_json["d"]["a"]}
希望这有帮助