Disable any output of robot.run()?

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

1 Like

After spending one day with this issue I want to share my results…
I tried many approaches with subprocess, threading etc. - all with stdout/stderr redirected to prevent this Chrome message to appear on STDOUT of the wrapper. No chance. There is some other guy who had the same problem with Powershell:
https://mlog.club/article/5383512
So this seems to be something related to Chrome that logs are coming to the console though.

Even if I did not want to go that way at all - my current “solution” is now to suppress the Chrome logging (see below) - and hope that there won’t be any other tools/libs where logs appear despite redirected stdout.

*** Keywords ***
Open Chrome
    ${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    
    Call Method    ${chrome_options}    add_argument    --disable-extensions
    Call Method    ${chrome_options}    add_argument    --headless
    Call Method    ${chrome_options}    add_argument    --disable-gpu
    Call Method    ${chrome_options}    add_argument    --no-sandbox
    Call Method    ${chrome_options}    add_argument    --disable-logging
    ${EXCLUDES}    Create list     enable-logging  
    # this removes the option "enable-logging" which chromedriver automatically starts Chrome with
    Call Method    ${chrome_options}    add_experimental_option    excludeSwitches  ${EXCLUDES}

    Create Webdriver    Chrome    chrome_options=${chrome_options} 
3 Likes