如何在两个不同的设备上并行运行机器人框架测试用例

时间:2015-05-10 18:19:00

标签: robotframework

遵循机器人框架测试用例:

步骤1:Telnet到HOST1并进行映像升级

第2步:Telnet到HOST2并进行映像升级

***Settings***

Library  Telnet

*** Variables ***

${HOST1}                1.1.1.1
${HOST2}                1.1.1.2
${USERNAME}             admin
${PASSWORD}             test

***Test Cases***

testcase1

    Open Connection         ${HOST1}
    Login   ${USERNAME}     ${PASSWORD}
    Write                   enable
    Write                   upgrade tftp://10.1.1.1/image.img
    ${data1}                Read Until Regexp       .*#
    Open Connection         ${HOST2}
    Login   ${USERNAME}     ${PASSWORD}
    Write                   enable
    Write                   upgrade tftp://10.1.1.1/image.img
    ${data1}                Read Until Regexp       .*#

这很好用。但问题是,只有在HOST1升级完成后,我才能将映像升级到HOST2。但我想在两台机器上并行进行图像升级。

有没有办法在后台运行HOST1映像升级并启动HOST2映像升级?

请指导我。

2 个答案:

答案 0 :(得分:1)

一个简单的技巧是使用轮询。

*** Test Cases ***
testcase1
    Set Default Configuration               prompt=$
    Open Connection                         ${HOST1}       alias=${HOST1}
    Login                                   ${USERNAME}    ${PASSWORD}
    Log                                     start downloading ${HOST1}
    Write                                   wget http://huge_file
    Open Connection                         ${HOST2}       alias=${HOST2}
    Login                                   ${USERNAME}    ${PASSWORD}
    Log    start downloading ${HOST2}
    Write                                   wget http://small_file
    # start polling for 2 min every 10 sec
    Wait Until Keyword Succeeds             120 sec        10 sec    isPrompt
    File Should Exist                       huge_file
    File Should Exist                       small file  
    Close All Connections

*** Keywords ***
isPrompt
    Switch Connection    ${HOST1}
    ${passed1}           Run Keyword And Return Status    Read Until Prompt
    Switch Connection    ${HOST2}
    ${passed2}           Run Keyword And Return Status    Read Until Prompt
    ${return}            Set Variable If                  ${passed1}==${True} and    {passed2}==${True}    ${True}    ${False}
    # keyword only succeeds if both connections have prompt again
    Should Be True       ${return}

也应该可以使用 Read Until Regexp 而不是 Read Until Prompt

答案 1 :(得分:1)

一个选择是: 实现shell或bat脚本以同时执行测试用例。这意味着几个机器人框架进程同时运行。然后合并输出并生成日志。

对于每个连接,您可以为每个连接定义两个变量文件。

***Settings***

Library    Telnet

*** Variables ***
${HOST}                1.1.1.1
${USERNAME}             admin
${PASSWORD}             test

***Test Cases***
testcase1

    Open Connection         ${HOST}
    Login   ${USERNAME}     ${PASSWORD}
    Write                   enable
    Write                   upgrade tftp://${HOST}/image.img
    ${data1}                Read Until Regexp    .*#

还有一个可以并行执行机器人测试用例的工具。 https://github.com/mkorpela/pabot