机器人框架上的数据驱动测试用例
Data driven test cases on robot framework
我发现很多案例描述了如何执行一些内部数据范围的测试用例,但我需要基于一些数组创建单独的测试用例。
例如我有一个盒子范围,我需要检查一些场景:
- 登录框
- 执行一些命令(例如 echo 'Hello world')
在所有情况下,登录名、密码、测试命令都是相同的。
一个区别 - IP\Computername.
现在看起来像这样,对我来说,当 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 个虚拟机,我需要写 400 个字符串,每个字符串有 1 个差异4串)
如果我尝试执行类似的操作(这对我来说看起来好多了):
*** 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
我收到这个“很棒”的结果,看着它我不明白什么通过了,什么没有通过
这个样本看起来好多了:
*** 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 个)...
我想再一次知道我需要单独的测试(有单独的结果PASS\FAIL)而不是在一个测试用例中循环
Link 类似问题但没有答案:
In Robot Framework, how to perform data-driven testing by creating a separate test case for each line of data in a text file?
Links,场景存储在一个测试用例中(与我需要的不一样):
http://www.thinkpalm.com/blogs/data-driven-testing-robot-framework/
所以目前在 python 中找到了解决方案:
- 我有为数据驱动的测试用例创建配置文件的外部脚本
- 同一脚本根据 tescase 模板创建带有所需测试的移动 tescase
最后同样的python脚本执行机器人框架:
call(['python.exe', '-m', 'robot', '-V', "params.py", testfile])
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
你可以看看 RobotFramework-Examples 库(免责声明:我是作者)。
这允许在套件设置期间从外部源读取数据 - 然后可以将数据用作给定测试序列的示例数据。
我发现很多案例描述了如何执行一些内部数据范围的测试用例,但我需要基于一些数组创建单独的测试用例。
例如我有一个盒子范围,我需要检查一些场景:
- 登录框
- 执行一些命令(例如 echo 'Hello world')
在所有情况下,登录名、密码、测试命令都是相同的。 一个区别 - IP\Computername.
现在看起来像这样,对我来说,当 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 个虚拟机,我需要写 400 个字符串,每个字符串有 1 个差异4串)
如果我尝试执行类似的操作(这对我来说看起来好多了):
*** 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
我收到这个“很棒”的结果,看着它我不明白什么通过了,什么没有通过
这个样本看起来好多了:
*** 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 个)...
我想再一次知道我需要单独的测试(有单独的结果PASS\FAIL)而不是在一个测试用例中循环
Link 类似问题但没有答案: In Robot Framework, how to perform data-driven testing by creating a separate test case for each line of data in a text file?
Links,场景存储在一个测试用例中(与我需要的不一样): http://www.thinkpalm.com/blogs/data-driven-testing-robot-framework/
所以目前在 python 中找到了解决方案:
- 我有为数据驱动的测试用例创建配置文件的外部脚本
- 同一脚本根据 tescase 模板创建带有所需测试的移动 tescase
最后同样的python脚本执行机器人框架:
call(['python.exe', '-m', 'robot', '-V', "params.py", testfile])
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
你可以看看 RobotFramework-Examples 库(免责声明:我是作者)。 这允许在套件设置期间从外部源读取数据 - 然后可以将数据用作给定测试序列的示例数据。