Open oomelianchuk opened 3 years ago
For now, I found only 2 options to enable full support of all driver arguments.
The difficulty in this approach is though, that the builders of the DriverServer
implementation only offer a limited number of methods for public access. This fact can be overwhelmed with inheritance like in the example below:
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeDriverService.Builder;
import org.openqa.selenium.net.PortProber;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
public class ChromeBuilder extends Builder
{
private File binary;
private int port;
private List<String> arguments;
public ChromeDriverService createDriverService(List<String> arguments)
{
binary = findDefaultExecutable();
port = PortProber.findFreePort();
this.arguments = arguments;
try
{
return new ChromeDriverService(binary, port, createArgs(), ImmutableMap.copyOf(System.getenv()));
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
}
@Override
protected ImmutableList<String> createArgs()
{
ImmutableList.Builder<String> argsBuilder = ImmutableList.builder();
argsBuilder.addAll(super.createArgs());
argsBuilder.add(String.format("--port=%d", port));
if (firefoxBinary != null)
{
argsBuilder.add("-b");
argsBuilder.add(binary.getPath());
}
if (arguments != null)
{
argsBuilder.addAll(arguments);
}
return argsBuilder.build();
}
}
The wrapper-builder from above can then be used to pass arguments to the driver constructor:
ChromeDriverService driverServer = new ChromeBuilder().createDriverService(List.of("--log-level=OFF"));
if (driverServer != null)
{
wDSC.setWebDriver(new ChromeDriver(driverServer, options));
}
else
{
wDSC.setWebDriver(new ChromeDriver(options));
}
#!/bin/sh
chromedriver --log-level=OFF $@
and then use this script as executable.
IMO, the code approach is the more preferred one, as this guarantees platform independence. However, if this approach seems to be "hacky" and hard to maintain, we can select the script approach, as it seems to require lower maintenance effort.
All the currently supported webdrivers accept their own list of arguments, which allow to customize the behavior of the driver itself. It might be useful e.g. to decrease the logging level of the driver.
From the list of avaliable option for chromedriver:
and from geckodriver:
we can see some further use cases of these arguments.
Therefore, it would be nice to help the users passing the arguments to the executable file.