I am having trouble output/saving the results from my terminal commands.
*** Settings ***
Library Process
Suite Teardown Terminate All Processes kill=True
*** Test Cases ***
Example
Run Process adb devices -l
Current Output
Expected Output
However, if i just run adb devices -l, it will provide me with a list of android devices id.
E.g. List of devices attached
0429329319 device usb: xxxx
My attempts
Based on the robot framework, it has this example that i tried to follow but gave me errors such as "No keyword with name ${result} = Run Process found"
Sample code from robot framework
${result} = Run Process program stdout=${TEMPDIR}/stdout.txt stderr=${TEMPDIR}/stderr.txt
Log Many stdout: ${result.stdout} stderr: ${result.stderr}
Another way that i have discovered is to use 'Get Process Result' keyword.
So my question is - how do i print/save the output of my terminal commands?
Would appreciate if anyone can take a look at it
Referenced to
http://robotframework.org/robotframework/latest/libraries/Process.html
https://github.com/robotframework/robotframework/blob/master/atest/testdata/standard_libraries/process/get_process_result.robot
I just found out one way would be using the OperatingSystem library - 'Run'.
Then log the results of the command entered into the terminal/command prompt using 'Log To Console'
*** Settings ***
Library OperatingSystem
*** Test Cases ***
Get list of devices
${result} = Run adb devices -l
Log To Console [${result}]
To save the printed stuff in the console, just do
robot xx.robot > console.txt
Referenced to - how to run commands in CMD prompt using robot framework
Related
This is my robot code, here main.py takes input from events.json(I modify this using robot code) and generates a text file. main.py only stops running when it satisfies a condition, after running it will create a text file and I want to terminate the program and then read the results of text file.But the problem is if i run the below code the test cases are not executing the robotcode keeps on running.
See this
robot framework
*** Settings ***
Library JSONLibrary
Library OperatingSystem
Library Process
*** Variables ***
#{events} READY_TO_WAIT STARTING COMPLETE
*** Test Cases ***
Testcase with correct events and checking final state is DONE
Testing with correct events events-Create Dict/Convert json to string/create file
validating state.txt to check if its ending the state with DONE
*** Keywords ***
Testing with correct events events-Create Dict/Convert json to string/create file
Run Process ${CURDIR}${/}main.py
FOR ${event} IN #{events}
${new_dict}= Create Dictionary event=${event}
${json_str1}= Convert Json To String ${new_dict}
Create File ${CURDIR}${/}events.json ${json_str1}
END
Terminate All Processes
validating state.txt to check if its ending the state with DONE
${result}= Get File ${CURDIR}${/}state.txt
Should Be Equal ${result} DONE
How do I run python scripts and terminate them manually?
I'm trying to invoke a shell scrip from within a .robot test case.
The .sh file is in the same folder as the .robot file
*** Settings ***
Library Process
*** Test cases ***
Run the shell script
Start Process ./getIDfromDB.sh shell=yes
I'm getting the error:
Setting variable 'Start Process ./getIDfromDB.sh' failed: Invalid variable name 'Start Process ./getIDfromDB.sh'.
Running on Ubuntu
Researched documentation for Robot framework but could not find a solution. Maybe digging in the wrong spot.
I'm not sure how you are trying to set the path of the shell script in the robot file. The error message seems to convey that something is wrong with the way you're initialising the variable to hold the path.
The following code should work:
*** Settings ***
Library Process
*** Variables ***
${pathToScript} ./getIDfromDB.sh
*** Test cases ***
Run shell script
${output} Run process ${pathToScript} shell=yes
The return code and the output displayed in the terminal are stored in the ${output} variable. You can access the details as ${output.rc} and ${output.stdout} respectively.
You can find more details about the result object here.
According error details the keyword is not recognized, I think, you need add extra spaces after keyword name:
Start Process ./getIDfromDB.sh shell=yes
I try to Run a simple robot framework script in PyCharm.Here is my code:
*** Settings ***
Documentation This is some basic info about the whole suite
Library Selenium2Library
*** Variables ***
*** Test Cases ***
User must sign in to check out
[Documentation] This is some basic info about the test
[Tags] Smoke
Open Browser http://www.google.com.ua chrome
Close Browser
I customized robot framework with PyCharm as it was in videos but when I run this script in terminal of PyCharm, the desired site isn't opened and I get the next information:
C:\Users\user\PycharmProjects\amazon>
C:\Users\user\PycharmProjects\amazon>pybot -d results tests/Amazon.robot
Amazon :: This is some basic info about the whole suite
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
User must sign in to check out :: This is some basic info about th... | FAIL |
error: [Errno 10054]
------------------------------------------------------------------------------
Amazon :: This is some basic info about the whole suite | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: C:\Users\user\PycharmProjects\amazon\results\output.xml
Log: C:\Users\user\PycharmProjects\amazon\results\log.html
Report: C:\Users\user\PycharmProjects\amazon\results\report.html
Tell me, please, why this script doesn't open the browser and actions that it should execute and why do I get this error. Thank you.
If the code you posted is literally your code, you're missing at least one space before chrome on the open browser line. There must be two or more spaces between the URL and the browser.
This may not be the only problem, but it's definitely a problem.
I use robot framework at following environment.
Python 2.7.6
robotframework 2.8.7
Ubuntu 14.04.3 LTS
I use robotframwork like this.
*** settings ***
Suite Setup setupkeyword # Provisioning for test
Suite Teardown teardownkeyword # Delete all resources
*** testcases ***
TestCase1
TestCase2
TestCase3...
In this case,
if Teardown fails, test case is shown Failed in report like followings.
Suite Setup:PASS
Suite Teardown:FAIL
TestCase1:FAIL
TestCase2:FAIL
TestCase3:FAIL
But Teardown is not the purpose of this test,
So I want report shows like followings.
Suite Setup:PASS
Suite Teardown:FAIL
TestCase1:PASS
TestCase2:PASS
TestCase3:PASS
I test like followings.
Suite Teardown Run Keyword And Ignore Error teardownkeyword # Delete all resources
But in this case, report shows
Suite Teardown:PASS
but I want to know whether Teardown was passed or not.
Is there any good method for this case?
I think the best method would be to redesign teardown keyword to give a warn when it is about to fail (but avoid failure). It can be accomplished with log keyword:
Log This keyword would fail due a some reason level=WARN
you could try with level=ERROR (maybe it won't fail whole test suite then?)
I use robot framework at following environment.
Python 2.7.6
robotframework 2.8.7
Ubuntu 14.04.3 LTS
I make directory like followings,
and execute robot like this to get report in TestPTX units.
TestCaseRoot
L TestPT1
L test_1.robot
L test_2.robot
L test_3.robot
L TestPT2
L test_a.robot
L test_b.robot
$ pybot -L TRACE -b debug.log --outputdir <LOG_DIR> TestPT1/
In this case, test_1,test_2,test_3 are executed and report and log file is included one file.
But when test_2 were failed , pybot continue to execute test_3, and until test_3 were done report were not outputed.
I wish that if test_2 were failed , output report.html and log.html of test_1 and test_2(Interim report), and pybot continue to execute test_3.
Is any idea of grant my wish?
You cannot get what you want. Robot keeps the report in memory and only writes it to disk when the entire test run is completed.
You can create a listener that will give you the same information that is in the report if you wish, and you can use that to write your own file. Or, you can create a custom script that runs each suite separately, and then combines all of the individual reports after all of the tests have run.