Setting WebDriver instance at runtime

According to this documentation:

One can do something like:

WebDriver driver = new ChromeDriver()
DriverFactory.changeWebDriver(driver)

However, looking at the source, it appears that the changeWebDriver() currently has a private access modifier:

private static void changeWebDriver(WebDriver webDriver) {
    changeWebDriverWithoutLog(webDriver);
    logBrowserRunData(webDriver);
    switchToSmartWaitWebDriver(webDriver);
}

Is there any chance that this could become public facing again? If not, could we get another method to set a custom driver at runtime? If not, please update the documentation.

Some context:

I’m trying to implement a way to modify request headers programmatically using BrowserMob. Basically, I can instantiate my own webdriver, and associate a custom BrowserMob proxy (with custom headers) with that driver through desired capabilities. The problem is that I can’t then inject that back into the DriverFactory as shown above.

Thanks in advance!

I can confirm that in KS 7.2.1 DriverFactory#changeWebDriver() method is declared public.

On the other hand, the source code shared at https://github.com/katalon-studio/katalon-studio-testing-framework/blob/master/Include/scripts/groovy/com/kms/katalon/core/webui/driver/DriverFactory.java declares the method as private. The disclosed source code is obviously obsolete.

1 Like

Cool, thank you so much for checking this @kazurayam. This means our existing functionality won’t break (at least in 7.2.1).