#requestLibrary相关使用
#创建一个会话使用别名local
create session local http://localhost:8000
#向别名local的会话发起一个请求,请i去uri为users/1
${addr} get request local users/1
log ${addr}
#判断请求响应是否为200,200就继续执行用例否则失败停止,status_code获取返回状态码
should be equal as strings ${addr.status_code} 200
#输出addr对象的内容
log ${addr.content}
#使用 to json将string转换为json串, 相应数据
${responsedata} to json ${addr.content}
log ${responsedata}
#使用dictionary方法获取对应的值, 需要import Collections库
${keys} get dictionary keys ${responsedata}
${items} get dictionary items ${responsedata}
${values} get dictionary values ${responsedata}
${str} get from dictionary ${responsedata} 1 #通过键名获取对应的value
${addr} get Request local users/5 #访问一个不存在的uri应该返回404
should be equal as strings ${addr.status_code} 404
log ${addr.content}
${res2} To json ${addr.content}
${keys} get dictionary keys ${res2}
${items} get dictionary keys ${res2}
${values} get dictionary values ${res2}
${str} get from dictionary ${res2} message
Delete all sessions #删除当前所有的会话
#接口返回xml格式内容处理
#返回的xml按json的方式是处理
create session local http://localhost:8000
${addr} get request local hello/qitao
should be equal as strings ${addr.status_code} 200
log ${addr.content}
${res} to json ${addr.content}
log ${res}
${keys} get dictionary keys ${res}
${items} get dictionary items ${res}
${values} get dictionary Values ${res}
${str} get from dictionary ${res} hello
#处理为xml 需要导入XML模块
${dic} create dictionary accept=application/xml #创建字典作为访问的header内容,即 accept:aaplication/xml
${addr2} get request local hello/qitao ${dic} #添加header参数请求
should be equal as strings ${addr2.status_code} 200
log ${addr2.content}
${res2} set variable ${addr2.content}
${body} get element text ${res2} hello
${hello} get element ${res2} hello
log ${hello.text}
${res3} add element ${res2} <new id='10'>test</new> #添加元素
${new} XML.get element attribute ${res3} id new #使用xml库中的get element attribute
log ${new}
${a} element to string ${res3}
delete all sessions
#requestLibrary相关使用 #创建一个会话使用别名local create session local http://localhost:8000 #向别名local的会话发起一个请求,请i去uri为users/1 ${addr} get request local users/1 log ${addr}...