Robot Framework – 我如何查看在shell中执行的命令的输出?

huangapple go评论91阅读模式
英文:

Robot framework - How do I see the output of a command executed in a shell?

问题

以下是您要翻译的内容:

"I would like to use the Robot framework to automate a step where the next command is executed in a cmd:

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

The output of the previous command will be the log of the server named the-server in the docker-compose.yml file.

After I would like to check if the response of this command has the string Started the-server, to check if the server is up.

I'm using the next robot file:

*** 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}

The test-case is always failing with the error:

> Keyword 'Check The-Server' failed after retrying 10 times. The last error was: TypeError: 'ExecutionResult' object is not iterable

also I'm not sure if the variable {resultOfcmd} contains the output of the command docker-compose logs --no-color --tail\=1 the-server.

Can anyone help?"

希望这可以帮助您解决问题。

英文:

I would like to use the Robot framework to automate a step where the next command is executed in a cmd:

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

The output of the previous command will be the log of the server named the-server in the docker-compose.yml file.

After I would like to check if the response of this command has the string Started the-server, to check if the server is up.

I'm using the next robot file:

*** 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}

The test-case is always failing with the error:

> Keyword 'Check The-Server' failed after retrying 10 times. The last error was: TypeError: 'ExecutionResult' object is not iterable

also I'm not sure if the variable {resultOfcmd} contains the output of the command docker-compose logs --no-color --tail\=1 the-server.

Can anyone help?

答案1

得分: 3

查看有关“Run Process”关键字的“Process”库文档中关于“Result”对象的信息:

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

你可以从${resultOfcmd.stdout}获取你的结果。

在测试失败之前,你还应该使用“Log To Console”关键字查看结果。

英文:

Check Process library documentation about Result object from Run Process keyword:

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

You get your results from ${resultOfcmd.stdout}.

You should also use Log To Console before failing keyword to see result before test fails.

答案2

得分: 0

Log To Console ${resultOfcmd.stdout} console=yes

英文:

Log To Console ${resultOfcmd.stdout} console=yes

huangapple
  • 本文由 发表于 2020年1月6日 19:50:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/59611615.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定