python - Restful API Automation 使用 ROBOT Framework 好不好

标签 python robotframework

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

最佳答案

是的,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}

希望对你有帮助

关于python - Restful API Automation 使用 ROBOT Framework 好不好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42359311/

相关文章:

python - 用偏斜高斯拟合直方图

selenium-webdriver - Robot Framework 如果元素可见,则执行关键字

python - Robot Framework导入库实例不包含定义的方法

python - 如何在 python 字典中保持循环以搜索值?

python - 在 Keras 中使用 imagedatagenerator 添加更多训练数据集

python - 如何以高质量录制屏幕

python - 如何使用 pop 函数删除二维数组中的所有元素

python - Robot Framework f中的文件上传

python - 如果屏幕在 60 秒内没有出现,如何在 python-pyautoit 中引发异常?

python - Robot Framework 上是否有 conftest.py pytest 等价物