Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: DriverServices do not work as documented #12682

Closed
Trigtrig opened this issue Sep 4, 2023 · 3 comments · Fixed by #12816
Closed

[🐛 Bug]: DriverServices do not work as documented #12682

Trigtrig opened this issue Sep 4, 2023 · 3 comments · Fixed by #12816

Comments

@Trigtrig
Copy link
Contributor

Trigtrig commented Sep 4, 2023

What happened?

Up to and including Selenium 4.10.0 it was possible to create a ChromeDriverService where the Selenium Manager automatically downloads the ChromeDriver (Chrome is already installed).

DriverService driverService = new ChromeDriverService.Builder().usingAnyFreePort().build();
driverService.start();
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(driverService.getUrl(), new ChromeOptions());
remoteWebDriver.navigate().to("https://www.selenium.dev");

Since Selenium 4.11.0 this code fails showing the following stacktrace:

Exception in thread "main" java.lang.NullPointerException
	at java.base/java.io.File.<init>(File.java:278)
	at org.openqa.selenium.os.ExecutableFinder.find(ExecutableFinder.java:47)
	at org.openqa.selenium.os.OsProcess.<init>(OsProcess.java:63)
	at org.openqa.selenium.os.CommandLine.<init>(CommandLine.java:35)
	at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:198)
	at org.example.Main.main(Main.java:24))

Looking at the ChromeDriverService documentation i tried using ChromeDriverService.createDefaultService().

DriverService driverService = ChromeDriverService.createDefaultService();
driverService.start();
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(driverService.getUrl(), new ChromeOptions());
remoteWebDriver.navigate().to("https://www.selenium.dev");

This yields the same result:

Exception in thread "main" java.lang.NullPointerException
	at java.base/java.io.File.<init>(File.java:278)
	at org.openqa.selenium.os.ExecutableFinder.find(ExecutableFinder.java:47)
	at org.openqa.selenium.os.OsProcess.<init>(OsProcess.java:63)
	at org.openqa.selenium.os.CommandLine.<init>(CommandLine.java:35)
	at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:198)
	at org.example.Main.main(Main.java:24)

The documentation of ChromeDriverService.createDefaultService() states that

In this configuration, the service will use the ChromeDriver executable identified by DriverFinder.getPath(DriverService, Capabilities).

But looking into the ChromeDriverServices and DriverServices builder code i could not find any usage of DriverFinder.getPath().

The only working solution i came up with is

SeleniumManagerOutput.Result result = SeleniumManager.getInstance().getDriverPath(new ChromeOptions(), false);
DriverService driverService = new ChromeDriverService.Builder()
                                                    .usingDriverExecutable(newFile(result.getDriverPath()))
                                                    .usingAnyFreePort()
                                                    .build();
driverService.start();
RemoteWebDriver remoteWebDriver = new RemoteWebDriver(driverService.getUrl(), new ChromeOptions());
remoteWebDriver.navigate().to("https://www.selenium.dev");

From my point of view, contrary to the documentation, the use of DriverFinder.getPath() is missing when using the ChromeDriverService.Builder with default values.

How can we reproduce the issue?

public class Main {
    public static void main(String[] args) throws IOException {

        // Use either Builder() or createDefaultService()
        // DriverService driverService = new ChromeDriverService.Builder().usingAnyFreePort().build();
        DriverService driverService = ChromeDriverService.createDefaultService();
        driverService.start(); // will fail using Selenium 4.11.0 and later

        RemoteWebDriver remoteWebDriver = new RemoteWebDriver(driverService.getUrl(), new ChromeOptions());
        remoteWebDriver.navigate().to("https://www.selenium.dev");

    }
}

Relevant log output

Sept. 04, 2023 3:53:29 PM org.openqa.selenium.remote.service.DriverService start
FINE: Starting driver at null with [--port=44284]
Exception in thread "main" java.lang.NullPointerException
	at java.base/java.io.File.<init>(File.java:278)
	at org.openqa.selenium.os.ExecutableFinder.find(ExecutableFinder.java:47)
	at org.openqa.selenium.os.OsProcess.<init>(OsProcess.java:63)
	at org.openqa.selenium.os.CommandLine.<init>(CommandLine.java:35)
	at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:198)
	at org.example.Main.main(Main.java:33)

Operating System

Windows 10

Selenium version

4.12.0 [Java]

What are the browser(s) and version(s) where you see this issue?

Chrome 116.0.5845.141

What are the browser driver(s) and version(s) where you see this issue?

ChromeDriver 116.0.5845.96

Are you using Selenium Grid?

No Selenium Grid involved

@titusfortner
Copy link
Member

The documented way to use the service is to pass it in as an argument to a local driver constructor.

For selenium manager to work, it needs to know both the options and service information. Since you can create options instance after service instance we don't force the executable in the service builder any more.

You can pass in the location of the driver in the service class, or you can use the chromedriver constructor to start the service.

@Trigtrig
Copy link
Contributor Author

Trigtrig commented Sep 5, 2023

Thanks for your quick reply and the fix. I can confirm that the issue is gone in 4.12.1 🙂

Copy link

github-actions bot commented Dec 6, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants