我有一個測驗套件
Library RequestsLibrary
Library JSONLibrary
Library OperatingSystem
*** Variable ***
${base_url} https://api.sportpartnerxxx.vn/v1
${identity_URL} https://identity.sportpartnerxxx.vn
${Profile} https://api.sportpartnerxxx.vn/v1/profile
*** Test Cases ***
Login
${body}= Create Dictionary client_id=sportpartner-mobile-app client_secret=ifd-sportpartner-secret-2021-mobile-app grant_type=password [email protected] password=123456
${header}= create dictionary content_type=application/x-www-form-urlencoded
${response}= Post ${identity_URL}/connect/token headers=${header} data=${body}
Set Suite Variable ${token} Bearer ${response.json()["access_token"]}
Set Suite Variable ${refresh_token} ${response.json()["refresh_token"]}
Status Should Be 200
Log To Console ${token}
UpdateLanguageStatus
${body}= Create Dictionary languageId=20
${header}= create dictionary Content-Type=application/json Authorization=${token}
${response}= PUT ${Profile}/me/settings data=${body} headers=${header}
Log To Console ${response.status_code}
Log To Console ${response.content}
回傳結果為 Login pass,UpdateLanguageStatus failed。UpdateLanguageStatus 回傳 400。我不知道原因。另一方面,我在郵遞員上運行這個測驗用例,它可以 在此處輸入影像描述。有人幫我嗎?
uj5u.com熱心網友回復:
看起來 ${body} 的字典內容在發送請求之前沒有序列化為 json。輸出如下所示:
{'languageId': '20'}
它應該是這樣的:
{"languageId": "20"}
您可以在發送前添加以下內容:
${body} Evaluate json.dumps(${body}) json
附加說明 - 如果 languageId 是 int 那么您可能需要更改您已有的行,以便 20 在 ${} 內,例如
${body}= Create Dictionary languageId=${20}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/369284.html
