Robot Framework - Template usage in API automation
Vivek Sharma
Senior Consultant QA - Experience in API and UI Automation Testing, Python behave, Java, rest Assured & AI/ML Testing
In Robot Framework the Test templates convert normal keyword driven test cases into data driven tests.
Use Case : In API automation we often needs to update the json value dynamically. using template we can update the json body as dictionary dynamically. the test template functionality can be used in selenium as well where we want to send multiple values to same keywords.
It is recommended to use test Template for below reasons:
Code Example :
*** Test Cases ***
Create Body and Send the request
[Template] Create Body and Send the request
#json_key #json_value
id 1
name Ramesh
*** Keywords ***
Create Body and Send the request
[Arguments] ${json_key} ${jsonvalue}
""" Load the static json and create the dictionary """
${jsonfile}= Get File Resources/Data/login.json
${jsonfile1}= Evaluate json.loads('''${jsonfile}''')
""" Update the dictionary as per the template id and name is the key with corresponding value"""
${BODY}= Set To Dictionary ${jsonfile1} ${json_key} ${jsonvalue}
Log To Console ${BODY}
Senior Test Engineer at GlobalLogic
1 年Superb ??