How to wild card Katalon installation path

So going down the path of trying to be able to launch specific browser types from within a Katalon script.

So far I’ve found this previous topic (How to open a second browser without closing the first?) which mentions to following solution:

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe")
WebDriver chrome = new ChromeDriver()
WebDriver ff = new FirefoxDriver()
// let Katalon know that chrome driver is usedDriverFactory.changeWebDriver(chrome)// Katalon keywords work as usual
WebUI.navigateToUrl("")// now you can switch to FF driver

The issue is that yes, I can set the path to the driver for my personal PC, but that may not apply to other who want to run the script. Is there any default Katalon variable / path command that would allow me to build the path to the various drivers programmatically?

1 Like
import com.kms.katalon.core.webui.driver.DriverFactory

println "DriverFactory.getChromeDriverPath()=${DriverFactory.getChromeDriverPath()}"
println "DriverFactory.getEdgeDriverPath()=${DriverFactory.getEdgeDriverPath()}"
println "DriverFactory.getGeckoDriverPath()=${DriverFactory.getGeckoDriverPath()}"

I ran this Test Case while I chose Firefox browser. I got the following output

2024-02-24 14:15:36.824 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2024-02-24 14:15:36.826 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/TCy
2024-02-24 14:15:37.297 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/TCy

If you choose Chrome, then DriverFactory.getChromeDriverPath() will return something meaningful.

This way you can query for the absolute path of the webdriver. With it you can derive the Katalon installation path.

1 Like

Interesting, will give it a try, thanks!!

I happened to visit the javadoc of Katalon API v9.3.0

and I was surprised to find that com.kms.katalon.core.webui.driver.DriverFactory class is not there.

It seems that Katalon has turned the class to be “non public”.

If it is the case, it would significant for me. Most of the “tips & ticks” that I have contributed to this Katalon User Forum depend on the DriverFactory.changeWebDriver(WebDriver) method being publicly available. If it is turned to “non-public” then all my efforts will be wasted. I don’t know any alternative in v9.3.0.

well that stinks, will keep looking then, thanks!

I got the source code of v9.3.0 and checked the com.kms.katalon.core.webui.driver.DriverFactory class.

I found it there:

package com.kms.katalon.core.webui.driver;
public class DriverFactory {

The class stays “public”. There seems to be no significant change.

Then, the published javadoc must be wrong somehow. => @Elly_Tran

Did Katalon developer decide to exclude the DriverFactory class out of the the public API doc? Do they want to hide it? I don’t know.

But I would not mind this finding anymore.

Finally getting back to this - one additional question - once the driver for the current pass is set (say in a Keyword function), is there any need to pass that back to the calling script using DriverFactory.changeWebDriver(XXX) , or once it’s set for a given run it stays set (unless that function is called again at some point, of course)?

Also I can’t get the blasted driver path to return even though i clearly see the drivers in the Katalon config folder, any ideas what I’m doing wrong?

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import org.apache.poi.xssf.usermodel.XSSFRow
import org.apache.poi.xssf.usermodel.XSSFSheet

import com.kms.katalon.core.configuration.RunConfiguration
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.testobject.impl.HttpTextBodyContent
import com.kms.katalon.core.util.KeywordUtil
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import org.openqa.selenium.WebDriver
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.edge.EdgeDriver

import btt_api.Endpoints
import btt_tag.*
import btt_helper.*
import groovy.json.JsonSlurper

//Define page parameters (note that first page has no xpath, is covered by target_site_url variable)
Tag_Processing tag = new Tag_Processing ()
Tag_API api = new Tag_API ()
Tag_Reporting report = new Tag_Reporting ()
Setup_Run setupRun = new Setup_Run ()

//Select desired browser

switch (browser_type.toLowerCase())	{
	//Standard Case - No Browser Identified
	case (""):
		KeywordUtil.markWarning ("*** No Browser Type Specified ***")
	//Set Chrome Driver
	case ("chrome"):
		def chrome_driverpath = DriverFactory.getChromeDriverPath()
		KeywordUtil.logInfo("Chrome Driverpath: " + chrome_driverpath)
		WebDriver chrome = new ChromeDriver()
	//Set Firefox Driver
	case ("firefox"):
		def firefox_driverpath = DriverFactory.getGeckoDriverPath()
		KeywordUtil.logInfo("Firefox Driverpath: " + firefox_driverpath)
		WebDriver firefox = new FirefoxDriver()
	//Set Edge Driver
	case ("edge"):
		def edge_driverpath = DriverFactory.getEdgeChromiumDriverPath()
		KeywordUtil.logInfo("Edge Driverpath: " + edge_driverpath)
		System.setProperty("webdriver.edge.driver", edge_driverpath)
		WebDriver edge = new EdgeDriver()
	//If none of the above are found, give an error and stop the run
		KeywordUtil.markFailedAndStop ("*** Indicated Browser (" + browser_name + "not found, please check and try again", )

I’ve confirmed that the driver call appears to be correct per katalon-studio-testing-framework/Include/scripts/groovy/com/kms/katalon/core/webui/driver/ at master · katalon-studio/katalon-studio-testing-framework · GitHub

Not sure what gives here :frowning:

@kazurayam - I’m also digging through your explanation in Opening Firefox with a Specific, non anonymous profile - #9 by Zeeshan_Shaikh to see if I can get an easier way to work, as per reading a few other articles once I leverage the selenium webdriver it appears I can no longer call WebUI for Katalon?

Though I’m fine with using an anonymous Firefox / Edge Chromium profile, so that might make things easier

UPDATE: This is quite frustrating, as even trying to run with different browser profiles using a collection only runs Chrome instead :frowning:

I don’t understand your question. What is “that”? What do you mean “to pass that back”

I don’t see why you want to develop the code above. It seems to be a mimic of WebUI.openBrowser() build-in keyword. I don’t see why you want to re-invent the wheel yourself.

switch (browser_type.toLowerCase())	{
    //Set Chrome Driver
	case ("chrome"):
		def chrome_driverpath = DriverFactory.getChromeDriverPath()

DriverFactory.getChromeDriverPath() will return some meaningful path ONLY WHEN you run your test case while manually you have chosen Chome in Katalon Studio’s tool bar window, as follows:

As for Katalon Runtime Engine, DriverFactory.getChromeDriverPath() will return some meaningful path ONLY WHEN you run your test case while you have specified Chrome in the commandline option.

If you did not chose Chorme manually, then DriverFactory.chromeDriverFactory() will return null. Therefore

switch (browser_type.toLowerCase())	{
    //Set Chrome Driver
	case ("chrome"):
		def chrome_driverpath = DriverFactory.getChromeDriverPath()

this code wouldn’t work because DirverFactory.getChromeDriverPath() is likely to return null.

I don’t understand what you are talking about, sorry.