【问题标题】:Use common Suite setup and Suite teardown for several test suites in a nested folder structure robot framewrok对嵌套文件夹结构机器人框架中的多个测试套件使用通用套件设置和套件拆解
【发布时间】:2020-01-27 05:35:10
【问题描述】:

我是 Robot 框架的新手,并试图在测试文件夹时更好地理解 Suite SetupSuite Teardown 中的概念和用法结构不是“扁平的”。在网上搜索了很长时间,Robot framework user guide - executing tests sectionthis question 与我的情况相似但不完全一样,我仍然没有找到任何解决方案,所以我们开始吧。

我的项目现在包含以下文件:

_init__.robot 包含Suite Setup & Suite Teardown“定义”,如下:

*** Settings ***
Library   /path/to/some/python/file.py
Suite Setup  myCustomSuiteSetup
Suite Teardown  myCustomSuiteTeardown

*** Keywords ***
myCustomSuiteSetup
    ${ret_code} =  run keyword MySuiteSetupKeyword
    should be eqaul as integers ${ret_code} 0

myCustomSuiteTeardown
    ${ret_code} =  run keyword MySuiteTeardownKeyword
    should be eqaul as integers ${ret_code} 0

其中myCustomSuiteTeardownMySuiteTeardownKeyword 是“链接”到文件/path/to/some/python/file.py 中的某些Python 函数的关键字。

我项目中的 4 个套件文件当前排列如下:

|--tests
|----suite_1.robot
|----suite_2.robot 
|----suite_3.robot
|----suite_4.robot
|----__init__.robot

现在,Suite SetupSuite Teardown 的用途(和用法)是Suite Setup 将在整个tests 文件夹的运行开始时运行,即- 之前 first 套件的 first 测试用例,在本例中为 suite_1.robotSuite Teardown 将在 之后运行 last 套件的strong>last 测试用例,在本例中为suite_4.robot

为此,我只需按如下方式调用所有套件(从tests 文件夹“上方”的一个文件夹中):

robot tests

到目前为止一切顺利。

现在我的问题如下:实际上我希望“重新排列”测试文件的文件夹结构,如下所示:

|--tests
|----testGroup1
|--------suite_1.robot
|--------suite_2.robot 
|----testGroup2
|--------suite_3.robot
|--------suite_4.robot
|--__init__.robot    <----- Where the __init__.robot file should be placed now ?

意思是,将测试套件“收集”到子文件夹,不过,我仍然希望像以前一样保持Suite SetupSuite Teardown 的使用,即在调用测试套件的每个可能子集时“根”文件夹testsSuite SetupSuite Teardown 必须是要执行的第一个和最后一个(分别)“步骤”,例如,假设我希望运行suite_3.robotsuite_4.robot ,那么现在,应该在suite_3.robot 中的第一个测试用例之前调用Suite Setup,并且应该在suite_4.robot 中的最后一个测试用例之后调用Suite Teardown。另外,当然,我希望只保留__init__.robot 文件的单个 副本-即-不要在每个子文件夹testGroup1testGroup2 中保留__init__.robot 的两个相似副本.当我这样做时,它起作用了,但这不是我希望这样做的(正确)方式。

所以我的问题是:

  1. 我需要将__init__.robot 文件放在哪里?

  2. 如果我希望只运行testGroup2 中的两个测试套件(即-suite_3.robotsuite_4.robot),我需要使用什么命令?

当然,如果这不是实现我的目标的“正确”方式(方法)(每个测试套件子集的单一和统一的 Suite SetupSuite Teardown) - 请建议应该如何完成。

注意:我使用的是 Robot framework 3.1.2(Linux 上的 Python 3.5.2)

【问题讨论】:

标签: python python-3.x automation automated-tests robotframework


【解决方案1】:

您在包含testGroup1testGroup2tests 文件夹中放置的初始化文件是正确的。这样,如果您至少运行一个位于 tests 或其子文件夹中的测试,套件安装程序将在所有此类测试之前运行,然后套件拆解。

要强制运行 Suite Setup 和 Suite Teardown,您必须将父文件夹 (tests) 保留为您运行的文件夹。最好始终运行包含所有测试的文件夹。这样一来,您就不会错误地错过任何套件设置或拆解。

要运行选择测试,请使用选项--include--exclude 作为标签,或--suite--test

在您的示例中,您将运行以下命令:

robot --suite suite_3 --suite suite_4 tests,仅运行 suite_3 和 suite_4

或者,您可以使用完全限定的套件名称:

robot --suite tests.testGroup2.suite_3 --suite tests.testGroup2.suite_4 tests

【讨论】:

  • Hudecek - 请再问一个问题:如果我想使用参数文件来调用,例如,只有suite_3 "wrapped" 像往常一样使用SuiteSetup & SuiteTeardown 我该如何撰写是吗?
  • @GuyAvraham 您可以将--suite 放在第一行,suite_3 在第二行,tests 在第三行:Robot 将换行符视为参数文件中的参数分隔符。
猜你喜欢
  • 2020-06-14
  • 2017-07-31
  • 2017-07-14
  • 2020-08-06
  • 2016-02-20
  • 1970-01-01
  • 2017-12-25
  • 2018-11-20
  • 2017-04-25
相关资源
最近更新 更多