Robot Framework - Template usage in API automation

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:

  • No need to repeat the keyword multiple times.
  • Easier to test multiple variations in one test.

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}        
Satyam Agnihotri

Senior Test Engineer at GlobalLogic

1 年

Superb ??

回复

要查看或添加评论,请登录

Vivek Sharma的更多文章

  • LLM and Evaluation Methods

    LLM and Evaluation Methods

  • Hallucination In AI Models

    Hallucination In AI Models

    Hallucination in Natural Language Generation: Hallucination occurs when a language model generates text that fits a…

  • Python Cosine Similarity

    Python Cosine Similarity

    Cosine Similarity is used as a metric for measuring distance when the magnitude of vector** does not matter. Example -…

    1 条评论
  • Cypress Best Practices

    Cypress Best Practices

    Use data attribute when selecting the Elements, Automation QA can add data attribute in the code if not available that…

  • Listeners in TestNG

    Listeners in TestNG

    If you want to add logs into your test script you can use listeners. Listeners work on action so have below methods.

社区洞察

其他会员也浏览了