get
*** Settings ***
Library Collections
Library RequestsLibrary
*** Variable ***
*** Test Cases ***
one
${passwd} Create List admin admin
Create Session dce http://192.168.124.4 auth=${passwd}
${resp}= Get Request dce /apis/extensions/v1beta1/namespaces/default/deployments
Log ${resp.content}
Should Be Equal As Strings ${resp.status_code} 200
- 如果参数提示dictionary或者list,需要使用内置的create
creat
*** Settings ***
Library Collections
Library RequestsLibrary
Library OperatingSystem
Library HttpLibrary.HTTP
*** Variable ***
*** Test Cases ***
one
${json} Get File apitestsuite/k8s.json
${appname} Set Variable "app3"
${json1} Set Json Value ${json} /metadata/name ${appname}
${abc} Get Json Value ${json1} /metadata
log ${abc}
${passwd} Create List admin admin
Create Session dce http://192.168.124.4 auth=${passwd}
${resp}= Post Request dce /apis/extensions/v1beta1/namespaces/default/deployments ${json1}
Log ${resp.content}
Should Be Equal As Strings ${resp.status_code} 201
loop creat
*** Settings ***
Library Collections
Library RequestsLibrary
Library OperatingSystem
Library HttpLibrary.HTTP
*** Variable ***
*** Test Cases ***
one
${json} Get File apitestsuite/k8s.json
:FOR ${i} IN RANGE 2
\ ${appname} Set Variable "app${i}"
\ ${json1} Set Json Value ${json} /metadata/name ${appname}
\ ${abc} Get Json Value ${json1} /metadata
\ log ${abc}
\ ${passwd} Create List admin admin
\ Create Session dce http://192.168.124.4 auth=${passwd}
\ ${resp}= Post Request dce /apis/extensions/v1beta1/namespaces/default/deployments ${json1}
\ Log ${resp.content}
\ Should Be Equal As Strings ${resp.status_code} 201
\ Sleep 2
json
{
"apiVersion": "extensions/v1beta1",
"kind": "Deployment",
"metadata": {
"name": "abc-2049",
"labels": {
"app": "abc-2049"
}
},
"spec": {
"template": {
"metadata": {
"name": "abc-2049",
"labels": {
"app": "abc-2049"
}
},
"spec": {
"containers": [
{
"name": "abc-2049",
"image": "daocloud.io/daocloud/dao-2048:latest",
"ports": [
{
"containerPort": 80
}
]
}
]
}
}
}
}
全局变量
在文件夹创建resource(robot),在其中添加全局变量
然后在执行用例中引用