英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论