2016-11-23 101 views
2

我創建一個煙霧測試套件進行了一系列使用RobotFramework和RobotRequestsLibrary的API。這是我第一次使用RobotFramework。在試圖清理代碼並使其更易維護時,我決定嘗試使用關鍵字刪除所有附帶的細節。RobotFramework關鍵字變量未設置

例如,這裏是我要清理兩次測試:

*** Variables *** 
${sint} http://int.somecoolwebsite.com 

*** Test Cases *** 
Retrieve Store Info By Code Should Return Successful 
    [Tags] get 
    Create Session data-int ${sint} 
    ${resp}=  Get Request int /store/1234 
    Should Be Equal As Strings ${resp.status_code} 200 

Retrieve All Store Info Should Return Successful 
    [Tags] get 
    Create Session data-int ${sint} 
    ${resp}=  Get Request int /stores 
    Should Be Equal As Strings ${resp.status_code} 200 

而且我在使用關鍵詞的嘗試:

*** Variables *** 
${sint} http://int.somecoolwebsite.com 

*** Keywords *** 
Make ${call} Call To ${end_point} 
    Create Session ${sint} ${sint} 
    ${resp} = Get Request ${sint} ${end_point} 
    ${status} = ${resp.status_code} 
    Set Test Variable ${status} 

Status Should Be ${required_status} 
    Should Be Equal ${status} ${required_status} 

*** Test Cases *** 
Retrieve Store Info By Code Should Return Successful 
    [Tags] get 
    Make Get Call To /store/1234 
    Status Should Be 200 

Retrieve All Store Info Should Return Successful 
    [Tags] get 
    Make Get Call To /stores 
    Status Should Be 200 

當我運行測試用例的關鍵詞,我得到以下錯誤:

Keyword name cannot be empty.

我試着調試問題並在關鍵字分配中放置一個斷點,我注意到${resp}被分配,${resp.status_code}也可以使用。但是,當我嘗試分配{$status}= ${resp.status_code}時,會引發錯誤。

我嘗試不同的方式重新分配使用內置設置變量,但沒有任何運氣的變量。你能否以這種方式在關鍵字中分配變量?任何見解都會有所幫助。謝謝!!

+0

對不起,我沒有時間深入研究,但從簡短的閱讀,數據驅動的風格可能會更好地爲你想要的東西做 - http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#data-driven-style – shicky

+0

你的問題中的代碼不會給你說錯誤的錯誤。該代碼適用於我。 –

+0

@BryanOakley你是對的。在代碼中寫入時,我添加了「設置變量」聲明。沒有這個,它確實會給出錯誤。但在測試案例中,我不需要使用該聲明。 – Ptrkcon

回答

1

即使在問題中的代碼仍然不給你說,它因爲有防止它運行在所有其他錯誤的錯誤,問題是這一行:

${status} = ${resp.status_code} 

也就是說不是分配變量的正確方法。您必須使用Set Variable關鍵字(或一些其他的「設置」關鍵字),像這樣:

${status}= Set Variable ${resp.status_code} 

你得到你做的錯誤是,每一個測試或關鍵字步驟都要有一個關鍵字的原因。你只有變量名和沒有關鍵字,所以你得到錯誤Keyword name cannot be empty.