A decorated WebDriver doesn't have a session ID ?!

Context

In my scraping project, we use a residential rotating proxy. To integrate this proxy into our Katalon project, we create a custom ChromeDriver to pass into the DriverFactory:

	public static void SetUpDriver() {
		// create if not exists the download directory
		File downloadDir = new File(this.GetDownloadDirectory());
		if (!downloadDir.exists()) {
			downloadDir.mkdirs();
		}

		System.setProperty('webdriver.chrome.driver', ChromeDriverUtil.getChromeDriverPath())

		ChromeOptions options = new ChromeOptions();

		options.setExperimentalOption('prefs', [
			'download.prompt_for_download' : false,
			'download.default_directory' : downloadDir.getPath(),
		]);

		Proxy proxy = ClientUtil.createSeleniumProxy(this.getProxy())
		proxy.setHttpProxy(proxyAddress)
		proxy.setSslProxy(proxyAddress)

		options.setProxy(proxy)

		options.addArguments("--disable-web-security");
		options.addArguments("--ignore-urlfetcher-cert-requests");

		options.setAcceptInsecureCerts(true)

		driver = new ChromeDriver(options);
		driver.manage().window().maximize();

		System.out.println("Window size: " + driver.manage().window().getSize());

		WebDriver eventDriver = new EventFiringDecorator<ChromeDriver>(new InitialNavigationEventListener()).decorate(driver);

		DriverFactory.changeWebDriver(eventDriver);
	}

This seems to work… as it is literally just updating our code to work with the new version fo Katalon Studio (v10)… However…

The problem

When running a sanity test case against the proxy integration, it errors, because the following exception got thrown on web driver setup:

Feb 08, 2025 11:56:49 PM com.kms.katalon.core.logging.KeywordLogger logError
SEVERE: ❌ java.lang.NullPointerException: Cannot invoke "org.openqa.selenium.remote.SessionId.toString()" because the return value of "com.kms.katalon.core.webui.driver.DriverFactory.getRemoteSessionId(org.openqa.selenium.WebDriver)" is null
	at com.kms.katalon.core.webui.driver.DriverFactory.logBrowserRunData(DriverFactory.java:435)
	at com.kms.katalon.core.webui.driver.DriverFactory.changeWebDriver(DriverFactory.java:187)
	at me.mikewarren.myCaseScraper.utils.WebDriverUtils.SetUpDriver(WebDriverUtils.groovy:69)

What are you trying to fix it?

I noticed that the new version of Katalon Studio (v10) has paywalled the ability to debug your scripts :rage:

To get around that, we attempt to “caveman-debug” :

		assert driver.getClass().getMethod('getSessionId') != null
		
		println driver.getClass().getMethod('getSessionId').invoke(driver);

The assertion passes, and we see a non-null session ID on the Console:

3e08b7d3c03b556bf9b714175ec172d2

NOTE: forced to do this roundabout bullshit to get the session ID, as an attempt to straight up just

println driver.getSessionId()

threw invocation error

Not sure how to fix this…

@kazurayam
@Elly_Tran

1 Like

It’s too difficult for me to look into your issue.

I’m sorry that you are facing difficulty looking into this…

What can I provide that would make this issue easier to look into?

I can not reproduce your system on my side, so it is too difficult for me to look into your issue.

Oh, I am running Katalon Studio v10.0.1, free edition, on Windows 11 machine.

I don’t need a proxy, so I’m not familiar with the coding, however, where is the “proxyAddress” picked up from or is it static somewhere else?

        // Configure proxy settings
        String proxyAddress = "your_proxy_address:port";

And, AI says you may have an issue with getting the sessionId, so perhaps go through the release notes for KS 10 and see if you can find any updates on changes to get it.

Edit: And KS paywalled “Debug” way back in version 6 or 7. “Debug” was there in version 5.6, but it was paywalled when we upgraded to version 7 or 8 a few years ago.

We are using residential rotating proxy from a third party. This proxyAddress is picked up from static.

It is working, but for some reason we face issue on DriverFactory.changeWebDriver(eventDriver);

I will check out those release notes; // Katalon’s DriverFactory.changeWebDriver() is the one that is checking the driver’s session ID

A couple of updates here:

First, I found out that !eventDriver instanceof RemoteWebDriver (and the session ID only exist for RemoteWebDrivers)

As a matter of fact…

Second, I found out that when trying to declare eventDriver as ChromeDriver, that I face this issue:

SEVERE: ❌ org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object 'Decorated {ChromeDriver: chrome on windows (d4accde383a42b77998f79731567a3a5)}' with class 'net.bytebuddy.renamed.java.lang.Object$ByteBuddy$MSuMTJy5' to class 'org.openqa.selenium.chrome.ChromeDriver'
	at me.mikewarren.myCaseScraper.utils.WebDriverUtils.SetUpDriver(WebDriverUtils.groovy:63)

Ok, so get rid of the decorated shit and be done with this!

Problem is that, we need, in this project, to take some custom action to authenticate the proxy service!

In pure Selenium WebDriver, we don’t need to (we could just authenticate programmatically via that proxyAddress String), but in Katalon Studio, we would need to make an auth alert spawn from the proxy service, and handle it with an AutoIT script that inputs the proxy credentials…

This was working in Katalon Studio v9, but in v10, with the upgrade to Selenium WebDriver v4 it is not anymore after updating my code from:

		EventFiringWebDriver eventDriver = new EventFiringWebDriver(driver);
		eventDriver.register(new InitialNavigationEventListener());

to

		WebDriver eventDriver = new EventFiringDecorator<ChromeDriver>(new InitialNavigationEventListener()).decorate(driver);

(and of course updating that InitialNavigationEventListener class)

Speaking of which…

eventDriver happens to be an instance of org.openqa.selenium.support.decorators.Decorated, and the source code in Katalon Studio’s DriverFactory.getRemoteSessionId() doesn’t handle that:

    private static SessionId getRemoteSessionId(WebDriver webDriver) {
        try {
            if (webDriver instanceof RemoteWebDriver) {
                return ((RemoteWebDriver) webDriver).getSessionId();
            }
        } catch (Exception e) {
            logger.logInfo(ExceptionUtils.getStackTrace(e));
        }
        return null;
    }

I recommend changing it to the following:

    private static SessionId getRemoteSessionId(WebDriver webDriver) {
        try {
            if (webDriver instanceof Decorated) { 
				return ((RemoteWebDriver)((Decorated) webDriver).getOriginal()).getSessionId();
            }

            if (webDriver instanceof RemoteWebDriver) {
                return ((RemoteWebDriver) webDriver).getSessionId();
            }
        } catch (Exception e) {
            logger.logInfo(ExceptionUtils.getStackTrace(e));
        }
        return null;
    }

@Elly_Tran @albert.vu

UPDATE to the update…

Seems we would have to change a lot of places in the Katalon code base that we are doing ((RemoteWebDriver) webDriver) to instead do a check on what webDriver actually is (is it Decorated)?

This new version of Selenium sure seems to be making things…difficult…

May be worth creating some util class/method to get the actual underlying web driver (similar to what I just did in this post) for the purposes of logging things like the browser name, version, session ID, etc…

…and for any puropse that does NOT boil down to logging something… we can simply use the webDriver object as-is.

Hi Michael @mwarren04011990, :wave:

Thank you very much for sharing your issue with us. As our Product team has yet to see this issue before, we’ll report this to them so they can take a closer look at it. Hopefully, they’ll be able to provide you with workarounds or suggesstions.


Hi em @Elly_Tran, can you please create a KSR Jira ticket for our Product team and link Michael’s topic to it? Thanks em.

1 Like

Hi @mwarren04011990,

Thank you for sharing your issue. I have created a ticket for my team to investigate this further. I will let you know soon if any updates.

1 Like

Thank you for the update!

There is another issue, that I’ve been facing for longer…

… That I’ve been forced to code around…

That issue is with the Selenium proxy returned by ClientUtil.createSeleniumProxy(), somehow NOT having the HTTP and SSL proxies set.

This has forced us to basically set them ourselves, and have to manually authenticate the proxy before any navigation can happen.

Sure. I will deliver your issue to my team also. Thank you

1 Like