【问题标题】:Robot Framework Test Cases creation via robot API通过机器人 API 创建机器人框架测试用例
【发布时间】:2019-10-25 22:30:12
【问题描述】:

我已经能够通过robot.api.TestSuite 类以编程方式创建一个包含多个测试用例的测试套件。我已经能够成功执行它并生成报告。我缺少的是在 .robot 扩展名中生成实际测试用例文件的选项,而不是在我的程序停止时“丢失它”。有什么选择可以实现这一目标吗?

我查看了官方 (https://robot-framework.readthedocs.io/en/v3.1.1/index.html) 但我没有找到解决问题的方法。我有什么遗漏吗?

【问题讨论】:

    标签: python testing robotframework


    【解决方案1】:

    我认为机器人 API 不支持任何此类事情。您必须创建自己的函数来将内存中的测试套件转换为文件。

    【讨论】:

      【解决方案2】:

      Robot Framework 4 有一个 API 允许创建模型,这是在解析 .robot 文件时获得的:

      from robot.parsing.lexer.tokens import Token
      from robot.parsing.model.blocks import File, TestCase, TestCaseSection
      from robot.parsing.model.statements import SectionHeader, TestCaseName, KeywordCall
      
      test_cases = TestCaseSection(
          header=SectionHeader.from_params(Token.TESTCASE_HEADER),
          body=[
              TestCase(
                  header=TestCaseName.from_params("Testing 1,2,3"),
                  body=[
                      KeywordCall.from_params('Log To Console', args=('Dynamically generated test',)),
                  ]
              )
          ]
      )
      
      sections = [test_cases]
      model = File(sections, 'testsuite.robot')
      

      从模型生成测试套件并执行它很容易:

      from robot.api import TestSuite
      
      suite = TestSuite.from_model(model)
      suite.run()
      

      当然也可以将模型写入 .robot 文件:

      model.save()
      

      【讨论】:

        猜你喜欢
        • 2014-09-05
        • 1970-01-01
        • 2016-03-01
        • 2018-09-16
        • 2018-10-25
        • 1970-01-01
        • 2018-04-01
        • 1970-01-01
        • 2020-01-22
        相关资源
        最近更新 更多