2015-10-20 111 views
1

現在我需要編寫一個腳本有關的類似:Robotframework:如何使用JSONP在robotframework腳本

${result} set variable {} 
create session url http://xxx 
${resp} get request url /
should be equal as strings ${resp.status_code} 200 
Dictionary Should Contain Value ${resp.jsonp(${result})} Success 
log ${resp.jsonp(${result})} 

但隨着JSONP腳本的URL寫。 那麼機器人框架如何與jSonp和jSon腳本一起使用? 和它的錯誤是這樣的:

Invalid variable name `${resp.jsonp({})}`. 

所有這些是: enter image description here

的JSONP來自url.And URL以JSONP腳本編寫。我需要使用RobotFramework獲取url接口script.may是我的腳本是錯誤的。

+0

請花一點時間確保您的問題經過深思熟慮並格式正確。我多次重讀這段文字,而且比較無能。從您輸入的內容中,您是否使用了請求庫?如果你正在使用JSON打我建議你使用http庫 – shicky

+0

yes.all的使用是:*** ***設置圖書館 Selenium2Library 圖書館HttpLibrary 圖書館RequestsLibrary 圖書館館藏 –

+0

如果使用JSON玩,GitHub的有這樣的測試:https://github.com/bulkan/robotframework-requests。但我不知道與JSONP腳本。我們的程序員使用JSONP腳本來接口。 –

回答

0

jsonp從哪裏來?我認爲您希望使用$ {resp.content},因爲您已經從請求庫發送GET請求

0

我假設您正在使用Robotframework-Requests庫,基於您提供的代碼。

返回的響應對象沒有.jsonp()方法。它有一個.json()方法,它沒有參數,並返回一個字典:

Dictionary Should Contain Value ${resp.json()} Success 

你也可以這樣保存到一個變量,如果你要進行多次檢查:

${json}= set variable ${resp.json()} 
Dictionary Should Contain Value ${json} Success 
相關問題