Hi there,
I asked the same question yesterday in Slack, but to go sure I also want to ask the community in the forum. This is the link to the discussion yesterday.
My goal is to write a Python wrapper script which can call Robot by the robot.run
method. This works pretty well in general.
But the wrapper - called by a monitoring system - is responsible to pick up the robot output.xml
and print this on STDOUT together with a special header line. It should print this and nothing else.
Poblems arise when the Robot execution also produces output on stdout.
For example the geckodriver produces lines like this:
DevTools listening on ws://127.0.0.1:55334/devtools/browser/733d93d3-f379-4208-b5ad-480e58a88016
[11216:9860:0618/113112.945:ERROR:device_event_log_impl.cc(208)] [11:31:12.945] Bluetooth: bluetooth_adapter_winrt.cc:1060 Getting Default Adapter failed.
This gets mixed up with the header line and the XML and results in invalid/not parsable data.
Hint 1: I know/assume that there are tricks to tell the different webdrivers not to log at all. But I am searching for a solution which can handle this independent of the Robot library.
Hint 2: It’s not all about Robot Logging settings. Its rather a question of how to completely mute the Robot execution, including the output of any libs, so that the stdout of my wrapper is only the header line and the content of the Robot XML.
What I have tried so far is to use temporary substitutes for stdout/err:
# Create the in-memory "file"
tmp_stdout = StringIO()
tmp_stderr = StringIO()
# Replace default stdout/err (terminal) with our stream
sys.stdout = tmp_stdout
sys.stderr = tmp_stderr
# RUN ROBOT
rc = run(robotdir.joinpath(suite), **suite_options)
# restore stdout/err
sys.stdout = sys.__stdout__
sys.stderr = sys.__stderr__
But subprocesses created by Robot (e.g. webdriver or other 3rd party tools) do not inherit this redirection and still use stdout.
I am completely clueless how to solve this and wonder if anybody has an idea to solve this.
Your help is highly appreciated, thanks in advance.
Regards,
Simon