2017-03-16 72 views
-4

這是一個機器人腳本。關鍵字'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. 
+0

通常很好創建儘可能最小的代碼示例,允許其他人重新創建問題。上面的問題包含太多代碼,無法運行以重新創建問題。此外,該代碼沒有解釋它應該做什麼。請縮短這個例子,並解釋什麼不工作以及你已經嘗試了什麼。 –

回答

-1

這是測試用例。

*** Test Cases *** 
    Msg 
     Log ${con} 
     Run Keyword If ${con}==1 Zerocon Onecon 
      ELSE If ${con}==2 Zerocon Onecon Twocon 
      ELSE Log 'Error' 
+1

這似乎不是問題的答案。 –

1

第一個問題是ELSE If必須是ELSE IF。從文檔中(重點添加):

從Robot 2.7.4版開始,此關鍵字還支持可選的ELSE和ELSE IF分支。上述這些問題都在* ARGS定義和必須使用完全相同的格式ELSE或ELSE IF

你有一樣的錯誤說,另一個問題是,Zerocon好好嘗試一下帶任何參數,但你傳遞參數到它。你傳遞的是看起來是關鍵字名稱的東西,但我不知道你期望會發生什麼。我不知道你是否想要運行這些關鍵字,或將它們作爲參數傳遞給Zerocon

+0

我只是想在關於$ {con}的條件下運行關鍵字, – Kion

相關問題