关键字'Zerocon'预计有0个参数,得到6个
问题描述:
这是一个机器人脚本。关键字'Zerocon'预计有0个参数,得到6个
这是设置。
*** Settings ***
Suite Setup GetUrl
Test Setup Create HTTP Context ${conturl[0]["Host"]}
Library JsonLibb.py
Library RequestsLibrary
Library HttpLibrary.HTTP
这是测试用例。
*** Test Cases ***
Msg
Log ${con}
Run Keyword If ${con}==1 Zerocon Onecon
ELSE If ${con}==2 Zerocon Onecon Twocon
ELSE Log 'Error'
这是关键字。
*** Keywords ***
GetUrl
${conturl} Get URL Json
Set Global Variable ${conturl}
${conturl_lenth}= Get Length ${conturl}
Set Global Variable ${conturl_lenth}
:FOR ${url_lenth} IN RANGE ${conturl_lenth}
\ Set Global Variable ${url_lenth}
\ Log ${url_lenth}
${content} Get HEADER Json
Set Global Variable ${content}
${content_lenth}= Get Length ${content}
Set Global Variable ${content_lenth}
:FOR ${con} IN RANGE ${content_lenth}
\ Set Global Variable ${con}
${contbody} Get BODY Json
Set Global Variable ${contbody}
${contbody_lenth}= Get Length ${contbody}
Set Global Variable ${contbody_lenth}
:FOR ${body_lenth} IN RANGE ${contbody_lenth}
\ Set Global Variable ${body_lenth}
Zerocon
Set Request Header Cookie ${content[${0}]["COOKIE"]}
Set Request Header X-Requested-With ${content[${0}]["X-Requested-With"]}
Run Keyword If '${content[0]["method"]}'=='POST' POSTRequest
ELSE If '${content[0]["method"]}'=='GET' GETRequest
ELSE Log 'ErrorZero'
Onecon
Set Request Header Cookie ${content[${1}]["COOKIE"]}
Set Request Header X-Requested-With ${content[${1}]["X-Requested-With"]}
Run Keyword If '${content[1]["method"]}'=='POST' POSTRequest
ELSE If '${content[1]["method"]}'=='GET' GETRequest
ELSE Log 'ErrorOne'
Twocon
Set Request Header Cookie ${content[${2}]["COOKIE"]}
Set Request Header X-Requested-With ${content[${2}]["X-Requested-With"]}
Run Keyword If '${content[2]["method"]}'=='POST' POSTRequest
ELSE If '${content[2]["method"]}'=='GET' GETRequest
ELSE Log 'ErrorTwo'
POSTRequest
Run Keyword If '${url_lenth}'=='1' HttpLibrary.HTTP.POST ${conturl[0]["Uri"]}
Set Request Body ${contbody[0]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
HttpLibrary.HTTP.POST ${conturl[1]["Uri"]}
Set Request Body ${contbody[1]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
ElSE If '${url_lenth}'=='2' HttpLibrary.HTTP.POST ${conturl[0]["Uri"]}
Set Request Body ${contbody[0]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
HttpLibrary.HTTP.POST ${conturl[1]["Uri"]}
Set Request Body ${contbody[1]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
HttpLibrary.HTTP.POST ${conturl[2]["Uri"]}
Set Request Body ${contbody[2]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
ELSE Log "Error"
GETRequest
Run Keyword If '${url_lenth}'=='1' HttpLibrary.HTTP.GET ${conturl[0]["Uri"]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
HttpLibrary.HTTP.GET ${conturl[1]["Uri"]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
ElSE If '${url_lenth}'=='2' HttpLibrary.HTTP.GET ${conturl[0]["Uri"]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
HttpLibrary.HTTP.GET ${conturl[1]["Uri"]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
HttpLibrary.HTTP.GET ${conturl[2]["Uri"]}
Response Status Code Should Equal 200
Response Body Should Contain "code":0,"msg":"","data":[]
Log Response Body
ELSE Log "Error"
这就是错误。
===========Output============
Documentation:
Runs the given keyword with the given arguments, if condition is true.
Start/End/Elapsed: 20170317 00:42:03.544/20170317 00:42:03.545/00:00:00.001
00:00:00.001KEYWORD Zerocon Onecon, ELSE If, ${con}==2, Zerocon, Onecon, Twocon
Start/End/Elapsed: 20170317 00:42:03.544/20170317 00:42:03.545/00:00:00.001
00:42:03.545 FAIL Keyword 'Zerocon' expected 0 arguments, got 6.
答
这是测试用例。
*** Test Cases ***
Msg
Log ${con}
Run Keyword If ${con}==1 Zerocon Onecon
ELSE If ${con}==2 Zerocon Onecon Twocon
ELSE Log 'Error'
+1
这似乎不是问题的答案。 –
答
第一个问题是ELSE If
必须是ELSE IF
。从文档中(重点添加):
从Robot 2.7.4版开始,此关键字还支持可选的ELSE和ELSE IF分支。上述这些问题都在* ARGS定义和必须使用完全相同的格式ELSE或ELSE IF
你有一样的错误说,另一个问题是,Zerocon
好好尝试一下带任何参数,但你传递参数到它。你传递的是看起来是关键字名称的东西,但我不知道你期望会发生什么。我不知道你是否想要运行这些关键字,或将它们作为参数传递给Zerocon
。
+0
我只是想在关于$ {con}的条件下运行关键字, – Kion
通常很好创建尽可能最小的代码示例,允许其他人重新创建问题。上面的问题包含太多代码,无法运行以重新创建问题。此外,该代码没有解释它应该做什么。请缩短这个例子,并解释什么不工作以及你已经尝试了什么。 –