Why Selenium's DriverService prints to the error stream? and how to avoid it? - Java

72 views Asked by At

I’m using Selenium with ChromeDriverService.

In its base class, DriverService, it starts the service and prints output messages to System.err stream.

private CommandLine process = null;

  public void start() throws IOException {
    lock.lock();
    try {
      if (process != null) {
        return;
      }
      process = new CommandLine(this.executable, args.toArray(new String[] {}));
      process.setEnvironmentVariables(environment);
      process.copyOutputTo(System.err);
      process.executeAsync();

      waitUntilAvailable();
    } finally {
      lock.unlock();
    }
  }

My first question is why to the error stream? It just prints some info messages about the initialization of chrome driver.

In my application, everything that goes to System.err shown in the app’s log with SEVERE log level.

My second question is how can I avoid it and show it as INFO log level? It is impossible to extend ChromeDriverService and override the start method, because DriverService contains some private data members that I need and can’t access to.

Thanks.

P.S. I’m using Selenium 2.5.2 but it’s the same concept in the newer versions

1

There are 1 answers

0
mancocapac On

Selenium 3.14.0 From DriverService, you are correct the default is System.err. It does look like you can change this default value as shown below and in the newer version the start() method has changed to use getOutputStream(). This will now allow you to change the default value.

private OutputStream outputStream = System.err;  // default


// You should call this method and set the output to your desired location
    public void sendOutputTo(OutputStream outputStream) {
      this.outputStream = Preconditions.checkNotNull(outputStream);
    }


public void start() throws IOException {
    lock.lock();
    try {
      if (process != null) {
        return;
      }
      process = new CommandLine(this.executable, args.toArray(new String[] {}));
      process.setEnvironmentVariables(environment);
      process.copyOutputTo(getOutputStream());   // This has changed...
      process.executeAsync();

      waitUntilAvailable();
    } finally {
      lock.unlock();
    }
  }