【问题标题】:Robot framework - How do I see the output of a command executed in a shell?机器人框架 - 如何查看在 shell 中执行的命令的输出?
【发布时间】:2020-11-11 19:13:03
【问题描述】:

我想使用 Robot 框架自动执行下一个命令在 cmd 中执行的步骤:

docker-compose logs --no-color --tail=1 the-server

上一条命令的输出将是docker-compose.yml文件中名为the-server的服务器的日志。

我想检查这个命令的响应是否有字符串Started the-server之后,检查服务器是否启动。

我正在使用下一个机器人文件:

*** Settings ***
Library    Process
Library    OperatingSystem
Suite Setup    log    running on ${properties.hostname}    
Suite Teardown    Terminate All Processes    kill=True

Variables    C:/Users/TheUser/Desktop/CheckOutRegression/properties.py

*** Test Cases ***
Check if the-server is up
    ${result}    Wait Until Keyword Succeeds    10x    20s    Check The-Server
*** Keyword ***
Check The-Server
    ${resultOfcmd}    Run Process    docker-compose logs --no-color --tail\=1 the-server   shell=yes    cwd=${properties.pathToDocker}
    Should Contain    ${resultOfcmd}    'Started the-server'    PASS
    Log To Console    ${resultOfcmd}

测试用例总是因错误而失败:

重试 10 次后,关键字“检查服务器”失败。最后一个错误是:TypeError: 'ExecutionResult' object is not iterable

我也不确定变量{resultOfcmd} 是否包含命令docker-compose logs --no-color --tail\=1 the-server 的输出。

谁能帮忙?

【问题讨论】:

    标签: docker process robotframework


    【解决方案1】:

    从 Run Process 关键字查看有关 Result 对象的流程库文档:

    https://robotframework.org/robotframework/latest/libraries/Process.html#Result%20object

    您从${resultOfcmd.stdout} 获得结果。

    您还应该使用 Log To Console before failed 关键字在测试失败之前查看结果。

    【讨论】:

      【解决方案2】:

      登录到控制台 ${resultOfcmd.stdout} console=yes

      【讨论】:

        猜你喜欢
        • 2014-03-02
        • 2017-10-25
        • 1970-01-01
        • 2018-03-22
        • 2018-11-28
        • 1970-01-01
        • 2010-11-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多