将ROBOT Framework用于Restful API Automation是否合适?

rjh*_*jha 1 python robotframework

我的项目有一个自动化存储库,它包含5-6个库文件,一些配置文件,作业文件和大约300个用Python编写的测试用例,使用python的unittest包测试用例.现在我想将所有这些测试用例移植到某个框架,以便它可以为我提供电子邮件,扩展和作业运行的一些基本功能.为此使用Robot Framework会有帮助吗?任何建议将不胜感激.

Sar*_*thi 5

是的,Robot Framework使用` RequestsLibrary支持REST API .

示例程序,您可以查看以下内容:

*** 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}
Run Code Online (Sandbox Code Playgroud)

希望,这会有所帮助