0

I have a Test Suite

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}

The returned result is Login pass, UpdateLanguageStatus failed. UpdateLanguageStatus return 400. I don't know the reason. Another side, I run this test case on postman, it work wel enter image description here. Do anyone help me?

1 Answer 1

2

It looks like the dictionary content of ${body} is not serialized to json before sending the request. The output looks like this:

{'languageId': '20'}

It should look like this:

{"languageId": "20"}

You can add the following before sending:

${body}  Evaluate  json.dumps(${body})  json

Additional note - if languageId is int then you may need to change the line you already have so the 20 is within ${} e.g.

${body}=    Create Dictionary    languageId=${20}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, It works well. Thanks so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.