Amir Marezloo
Amir Marezloo

Reputation: 1

Store Variable Of Response in RobotFramework

I want to Store a Value Of ActivationCode That I see it in response. This is my response in Pycharm terminal. Notice that I convert it to JSON with

${Data}=    Evaluate    json.loads("""${Response.content}""")    json

Now This is my response after convert it to JSON

{'status': 'created', 'statusCode': '0001', 'message': {'type': 'success', 'text': 'ثبتâ\x80\x8cÙ\x86اÙ\x85 Ù\x85Ù\x88Ù\x81Ù\x82Û\x8cت Ø¢Ù\x85Û\x8cز بÙ\x88د'}, 'error': [], '
data': {'user': {'uuid': 'c6b65427-bbfa-4d25-ac3e-aa190d45f5d9', 'username': 'dropp45', 'phoneNumber': '09203947700', 'activationCode': '88261'}}}

How do I store activationCode in a variable for next step what is keyword to show 88261

Upvotes: 0

Views: 91

Answers (2)

LaurencevdWel
LaurencevdWel

Reputation: 108

You can just go to the Json Response like this:

${activationCode}=  Set Variable  ${Data}[data][user][activationCode]  #You access activationCode
Log  ${activationCode}  # This will Log 88261

Upvotes: 1

Todor Minakov
Todor Minakov

Reputation: 20077

Once the value is a normal dictionary, you access it with the keys' names:

${value}=    Set Variable    ${Data['data']['user']['activationCode']}
Log     ${value}    # will print 88261

Upvotes: 2

Related Questions