Robotframework:如何使用JSONP在robotframework脚本
问题描述:
现在我需要编写一个脚本有关的类似:Robotframework:如何使用JSONP在robotframework脚本
${result} set variable {}
create session url http://xxx
${resp} get request url /
should be equal as strings ${resp.status_code} 200
Dictionary Should Contain Value ${resp.jsonp(${result})} Success
log ${resp.jsonp(${result})}
但随着JSONP脚本的URL写。 那么机器人框架如何与jSonp和jSon脚本一起使用? 和它的错误是这样的:
Invalid variable name `${resp.jsonp({})}`.
所有这些是: enter image description here
的JSONP来自url.And URL以JSONP脚本编写。我需要使用RobotFramework获取url接口script.may是我的脚本是错误的。
答
jsonp从哪里来?我认为您希望使用$ {resp.content},因为您已经从请求库发送GET请求
答
我假设您正在使用Robotframework-Requests库,基于您提供的代码。
返回的响应对象没有.jsonp()
方法。它有一个.json()
方法,它没有参数,并返回一个字典:
Dictionary Should Contain Value ${resp.json()} Success
你也可以这样保存到一个变量,如果你要进行多次检查:
${json}= set variable ${resp.json()}
Dictionary Should Contain Value ${json} Success
请花一点时间确保您的问题经过深思熟虑并格式正确。我多次重读这段文字,而且比较无能。从您输入的内容中,您是否使用了请求库?如果你正在使用JSON打我建议你使用http库 – shicky
yes.all的使用是:*** ***设置图书馆 Selenium2Library 图书馆HttpLibrary 图书馆RequestsLibrary 图书馆馆藏 –
如果使用JSON玩,GitHub的有这样的测试:https://github.com/bulkan/robotframework-requests。但我不知道与JSONP脚本。我们的程序员使用JSONP脚本来接口。 –