【问题标题】:Is it good to use ROBOT Framework for Restful API Automation使用 ROBOT 框架进行 Restful API 自动化好不好
【发布时间】:2020-07-16 23:19:38
【问题描述】:

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

【问题讨论】:

    标签: python robotframework


    【解决方案1】:

    是的,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 编写的库文件用于测试用例吗?我对 Robot 完全陌生,所以请原谅我这个愚蠢的问题,我仍在权衡选择框架的选择
    • 您是否尝试阅读文档?从这里开始:robotframework.org/robotframework/latest/…
    • 是的,您可以使用 , 通过创建自己的 python 文件作为自定义库到robotframework 并使用这些函数作为robotframework 中的关键字,正如@Jan 建议的那样,请阅读robotframework 的文档
    • 谢谢,我会查看该文档。感谢您的所有建议
    • 我从机器人框架开始,使用我现有的 python 库*** Settings *** Library ../../lib/ServerAPI.py WITH NAME ServerAPI *** Test Cases *** [TC-001]-Registering a device with INVALID SUBSCRIBER name to the server ServerAPI.subscriber None ${resp} register device ${token} ${devid} LOG ${resp} Should Be Equal ${resp} ${True} 它无法识别库的 ServerAPI 关键字名称,谁能帮助我,我在这里缺少什么?
    【解决方案2】:

    如果您只使用 Robot Framework 进行 REST API 自动化,它可以很好地工作。然而,robotframework 有许多映射到文件操作、字符串操作等的外部库。 https://robotframework.org/#libraries

    根据我的经验,将这些库链接到您自己的库和关键字中会导致系统测试环境难以调试。外部库映射到​​ python 库,最好直接在你自己的库中使用 python 库,因为它删除了一个抽象层。

    例如在机器人框架循环语法以及如何定义变量范围。它不像普通的 python 那样可读,而且你没有可用的生成器和 itertools 之类的东西。

    For loop over dictionary in Robot Framework

    【讨论】:

      猜你喜欢
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 2021-11-27
      • 2023-03-15
      • 1970-01-01
      • 2016-05-05
      相关资源
      最近更新 更多