【问题标题】:Data driven test cases on robot framework机器人框架上的数据驱动测试用例
【发布时间】:2018-12-25 09:30:44
【问题描述】:

我发现很多案例都描述了如何执行一些包含数据范围的测试用例,但我需要根据一些数组创建单独的测试用例。

例如,我有一个框范围,我需要检查一些场景:

  • 登录框
  • 执行命令某些命令(例如 echo 'Hello world')

在所有情况下,登录名、密码、测试命令都是相同的。 一个区别 - IP\计算机名。

现在看起来像这样,对我来说,当 VM 计数 > 10 时看起来很奇怪:

*** Settings ***
Library     SSHLibrary
Library     OperatingSystem
Library     String

*** Variable ***
${HOST}
${USERNAME}
${PASSWORD}

*** Test Case ***
Logging-into-VM1
    Open Connection And Log In     ${VM1}
Executing-Commands-on-VM1
    Executing commands

Logging-into-VM2
    Open Connection And Log In     ${VM2}
Executing-Commands-on-VM2
    Executing commands

.....

Logging-into-VMn
    Open Connection And Log In     ${VMn}
Executing-Commands-on-VMn
    Executing commands


*** Keywords ***
Open Connection And Log In
    [Arguments]     ${BOX}
    Open Connection     ${BOX}
    Login               ${USERNAME}     ${PASSWORD}
Executing commands
    ${testcmd}=     Execute Command     echo 'Hello world'

在这种情况下,我会收到正确的输出,但如果超过 10 个,我会使用 Copy\Paste 方法进行测试(例如,如果我需要测试 100 个 VM,我需要编写 400 个字符串,每 4 个字符串有 1 个差异)

如果我尝试执行类似的操作(这对我来说看起来好多了):

*** Settings ***
Library     SSHLibrary
Library     OperatingSystem
Library     String

*** Variable ***
${USERNAME}
${PASSWORD}

*** Test Case ***

Logging and commands executes
    [Template]    Conectivity tests {BOX}
    ${VM1}
    ${VM2}
    ${VM3}
    ....    
    ${VMn}


*** Keywords ***

Conectivity tests
    [Arguments]     ${BOX}
    Open Connection     ${BOX}
    Login               ${USERNAME}     ${PASSWORD}
    ${hostname}=     Execute Command    hostname

我只得到一个非非正式结果的测试用例:

=================================================================
ttestcase12
=================================================================
Logging and commands executes                            | FAIL |
Several failures occurred:

1) timeout: timed out

2) timeout: timed out

3) timeout: timed out

4) timeout: timed out

5) timeout: timed out

6) timeout: timed out

7) timeout: timed out
------------------------------------------------------------------
ttestcase12                                               | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed

我收到了这个“great”的结果,看着我不明白什么通过了,什么没有通过

这个样本看起来好多了:

*** Settings ***
Library          SSHLibrary
Library          OperatingSystem
Library          String
Test Template    Conectivity tests

*** Variable ***
${USERNAME}
${PASSWORD}

*** Test Cases ***          BOX

Conectivity tests VM1       ${VM1}
Conectivity tests VM2       ${VM2}
Conectivity tests VM3       ${VM3}

....

Conectivity tests VMn       ${VMn}

*** Keywords ***

Conectivity tests
    [Arguments]       ${BOX}
    Open Connection   ${BOX}
    Login             ${USERNAME}     ${PASSWORD}
    ${hostname}=      Execute Command     hostname





====================================================================
ttestcase12
====================================================================
Conectivity tests VM1                                       | FAIL |
timeout: timed out
--------------------------------------------------------------------
Conectivity tests VM2                                       | PASS |
--------------------------------------------------------------------
Conectivity tests VM3                                       | FAIL |
timeout: timed out
--------------------------------------------------------------------
Conectivity tests VM4                                       | FAIL |
timeout: timed out

.....

--------------------------------------------------------------------
Conectivity tests VMn                                       | FAIL |
timeout: timed out
--------------------------------------------------------------------
Sanityv8                                                    | FAIL |
99 critical tests, 12 passed, 87 failed
99 tests total, 12 passed, 87 failed

此外,所有这些场景都需要不同的测试套件,例如,如果在某些情况下我需要测试 99 个虚拟机,有时需要测试 100 个(包括之前的 99 个)...

我想再一次强调我需要单独的测试(单独的结果通过\失败)而不是在一个测试用例中循环

类似问题但没有答案的链接: In Robot Framework, how to perform data-driven testing by creating a separate test case for each line of data in a text file?

与存储在一个测试用例中的场景的链接(与我需要的不同): http://www.thinkpalm.com/blogs/data-driven-testing-robot-framework/

【问题讨论】:

  • 您尝试过数据驱动风格吗? robotframework.org/robotframework/latest/…
  • 嗨,Eddy,您能否根据我的示例描述一下它的外观?
  • 我正在尝试玩 3 天,但可能不明白我应该做什么......
  • 嘿,我想我得到了一些你可能想尝试的东西......虽然它会远离机器人的阅读方式:Programatic Test Generation。您可以编写一个脚本来构建您的机器人测试并运行它们。
  • 谢谢@GrantMcCloskey,我会尝试测试你的解决方案:)

标签: robotframework data-driven-tests


【解决方案1】:
Simple solution:

*** Settings ***
Library           SSHLibrary

*** Test Cases ***
loop
    [Template]    loopcall
    VM1    root    pwd1
    VM1    root    pwd2

*** Keywords ***
loopcall
    [Arguments]    ${machine}    ${user}    ${pwd}
    Open Connection    ${machine}    prompt=$
    Login    ${user}    ${pwd}
    ${hostname}=    Execute Command    hostname
    log    ${hostname}
    Close Connection

【讨论】:

  • 实际上,这个变体在我的问题中被描述为非信息性变体,因为控制台输出不包含可以触发完全失败的东西的东西
【解决方案2】:

所以目前在python中找到了解决方案:

  • 我有为数据驱动测试用例创建配置文件的外部脚本
  • 相同的脚本基于 tescase 模板创建带有所需测试的 on-the-go tescase
  • 最后同样的python脚本执行机器人框架:

    call(['python.exe', '-m', 'robot', '-V', "params.py", testfile])

【讨论】:

    【解决方案3】:

    您可以查看 RobotFramework-Examples 库(免责声明:我是作者)。 这允许在套件设置期间从外部源读取数据 - 然后可以将数据用作给定测试序列的示例数据。

    【讨论】:

    • 3 年前这对我很感兴趣 :) 现在我无法访问该测试,甚至不知道这些测试是否仍然存在,如果您可以提供详细信息,我可以尝试找到可以检查我以前团队的人
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-01
    • 2021-06-07
    • 1970-01-01
    • 2019-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多