【发布时间】: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