rjha
rjha

Reputation: 148

Is it good to use ROBOT Framework for Restful API Automation

I have an Automation Repository for my project, which contains 5-6 Library files, some config files, job files and around 300 testcases all written in Python, testcases using unittest package of python. Now i want to port all these testcases to some framework, so that it can give me some basic functionalities for emailing , scaling and Job running. Will it be helpful to use Robot Framework for this? Any suggestion will be appreciated.

Upvotes: 1

Views: 4737

Answers (2)

Sarada Akurathi
Sarada Akurathi

Reputation: 1188

Yes, Robot Framework supports REST APIs using RequestsLibrary.

Sample program, you can check below:

*** Settings ***
Documentation     REST API Testcase
Library           RequestsLibrary
Library           String
Library           Collections

*** Variables ***
${headers}        ${Empty}
${AliasName}      CLM

*** Test Cases ***
GetRequestAPI
    [Tags]    Sanity
    Create the Session    ${AliasName}    ${GetReqURL}
    ${headers}=    Create the Header    ${contentType}    ${authorizationFlag}
    ${resp}=    Get the Request    ${AliasName}    ${GetReqURI}    ${headers}
    Verify the Response    ${Resp}    ${GetReqStatusCode}

PostRequestAPI
    Create the Session    ${AliasName}    ${PostReqURL}
    ${headers}=    Create the Header    ${contentType}    ${authorizationFlag}
    ${resp}=    Post the Request    ${AliasName}    ${PostReqURI}    ${PostReqData}    ${headers}
    Verify the Response    ${Resp}    ${PostReqStatusCode}

*** Keywords ***
Verify the Response
    [Arguments]    ${response}    ${resp_status}
    Log    Response code is : ${response.status_code}
    Should Be Equal As Strings    ${response.status_code}    ${resp_status}
    Log    Response body is : ${response.text}

Hope, this will be helpful

Upvotes: 7

Dave
Dave

Reputation: 4328

If you only use Robot Framework for REST API automation it can work well. However robotframework has many external libraries which map to file operations, string manipulation and more. https://robotframework.org/#libraries

In my experience chaining together these libs into your own libs and keywords results in system test environment which is difficult to debug. The external libraries map to python libraries and it is better to use the python libs directly in your own libs because it removes a layer of abstraction.

For example at robotframework loop syntax and how you define variable scope. It is not as readable as normal python and you do not have things such as generators and itertools available.

For loop over dictionary in Robot Framework

Upvotes: 1

Related Questions