我发现很多情况下都描述了如何在内部具有数据范围的情况下执行某些测试用例,但是我需要基于某个数组创建单独的测试用例。
例如,我有一个需要检查某些情况的框范围:
在所有情况下,登录名,密码,测试命令均相同。 区别之一-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'
在这种情况下,我会收到正确的输出,但是对我来说,使用Copy \ Paste方法进行测试是否超过10个是很奇怪的(例如,如果我需要测试100个VM,我需要以每4个字符串1个差异的方式写400个字符串)< / p>
如果我尝试执行类似的操作(对我来说看起来更好):
*** 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个VM,有时需要测试100个VM(包括以前的99个)...
我想再次提醒我,我需要单独的测试(具有单独的结果PASS \ FAIL),而不是在一个测试用例中循环
链接到存储在一个测试用例中的场景(与我需要的不一样): http://www.thinkpalm.com/blogs/data-driven-testing-robot-framework/
答案 0 :(得分:0)
因此,目前在python中找到了解决方案:
最后,相同的python脚本执行了机器人框架:
call(['python.exe','-m','机器人','-V',“ params.py”,测试文件])
答案 1 :(得分:0)
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