Handle WebDrivers

Starting from Katalon Studio version 7.0, you can terminate WebDriver processes or update WebDrivers including Chrome, FireFox and Internet Explorer Drivers.

Terminate WebDriver processes

From the main toolbar, select Tools > Web > Terminate running WebDrivers> a pop-up message will inform whether your operation succeeds or not.

Update a WebDriver

From the main toolbar, select Tools > Update WebDrivers > select a browser in the drop-down list.

In the console mode, you can use this command argument, --config -webui.autoUpdateDrivers=true, to allow WebDriver binaries to be updated automatically. Learn more about Console Mode Execution.

Replace Selenium library

Location:

  • Windows: <Katalon Studio folder>\configuration\resources\lib\selenium-server-standalone-3.x.jar
  • macOS: /Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/lib/selenium-server-standalone-3.x.jar

Replace WebDriver binaries (application-level)

Windows

Chrome

You can use 32-bit Windows Chromedriver for both 32-bit and 64-bit Windows.

Location:

  • <Katalon Studio folder>\configuration\resources\drivers\chromedriver_win32
  • <Katalon Studio folder>\configuration\resources\drivers\chromedriver_win64

Firefox

Location:

  • <Katalon Studio folder>\configuration\resources\drivers\firefox_win32
  • <Katalon Studio folder>\configuration\resources\drivers\firefox_win64

Internet Explorer

Location:

  • <Katalon Studio folder>\configuration\resources\drivers\iedriver_win32
  • <Katalon Studio folder>\configuration\resources\drivers\iedriver_win64

Edge

Location:

  • <Katalon Studio folder>\configuration\resources\drivers\edgedriver

Edge (Chromium)

Location:

  • <Katalon Studio folder>\configuration\resources\drivers\edgechromium_win32
  • <Katalon Studio folder>\configuration\resources\drivers\edgechromium_win64

macOS

Chrome

Location:

  • /Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/drivers/chromedriver_mac

Firefox

Location:

  • /Applications/Katalon Studio.app/Contents/Eclipse/configuration/resources/drivers/firefox_mac

Edge (Chromium)

Location:

  • /Applications/Katalon Studio.app/Contents/Eclipse/configuration\resources\drivers\edgechromium_mac

Replace WebDriver binaries (project-level)

WebDriver binaries can be replaced at project-level by copying new files into the Include directory inside the project.

Location:

  • Include/drivers/chromedriver_win32/chromedriver.exe
  • Include/drivers/chromedriver_win64/chromedriver.exe
  • Include/drivers/chromedriver_mac64/chromedriver
  • Include/drivers/chromedriver_linux32/chromedriver
  • Include/drivers/chromedriver_linux64/chromedriver
  • Include/drivers/geckodriver_win32/geckodriver.exe
  • Include/drivers/geckodriver_win64/geckodriver.exe
  • Include/drivers/geckodriver_mac64/geckodriver
  • Include/drivers/geckodriver_linux32/geckodriver
  • Include/drivers/geckodriver_linux64/geckodriver
  • Include/drivers/iedriver_win32/IEDriverServer.exe
  • Include/drivers/iedriver_win64/IEDriverServer.exe
  • Include/drivers/edgedriver_win32/MicrosoftWebDriver.exe
  • Include/drivers/edgedriver_win64/MicrosoftWebDriver.exe
  • Include/drivers/edgechromiumdriver_win64/msedgedriver.exe
  • Include/drivers/edgechromiumdriver_win32/msedgedriver.exe
  • Include/drivers/edgechromiumdriver_mac/msedgedriver

Use the WebDriver Object

To use the current session created by Katalon Studio, you can refer to example code below:

WebDriver driver = DriverFactory.getWebDriver()

The returned 'driver' parameter will use the current browser's session launched by Katalon Studio. You need to import necessary libraries also (can be done by pressing Ctrl + Shift + O).

WebDriver Event Listeners

Starting in Katalon Studio version 7.0, the Katalon Studio's WebDriver extends the EventFiringWebDriver.

You can use WebDriverEventListener to handle events triggered by the WebDriver, which happens before or after navigation; before or after a click and etc. EventFiringWebDriver is a class in Selenium that supports the WebDriver with event-driven capabilities. Those capabilities are useful for many use cases - one of which is for logging steps or triggering certain events before an operation.

Below is an example of how to add your custom WebDriverEventListener method:

  1. Create a class named MyCustomWebEventListener to handle WebDriver's events.
package customlistener

import org.openqa.selenium.WebDriver
import org.openqa.selenium.support.events.AbstractWebDriverEventListener

public class MyCustomWebEventListener extends AbstractWebDriverEventListener {
	@Override
	public void beforeNavigateTo(String url, WebDriver driver) {
		 println "Before navigating to " + url;
	}
}
  1. Register MyCustomWebEventListener with WebDriver
import org.openqa.selenium.WebDriver as WebDriver
import org.openqa.selenium.support.events.EventFiringWebDriver as EventFiringWebDriver

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

import customlistener.MyCustomWebEventListener as MyCustomWebEventListener

WebUI.openBrowser('')

WebDriver webdriver = DriverFactory.getWebDriver()

EventFiringWebDriver eventFiring = ((webdriver) as EventFiringWebDriver)

eventFiring.register(new MyCustomWebEventListener())
// Don't use changeWebDriver, there's a bug we will fix in upcoming releases and will update
// the docs to reflect the fix
DriverFactory.changeWebDriverWithoutLog(eventFiring)

WebUI.navigateToUrl('www.google.com')

WebUI.closeBrowser()
  1. Observe the result in the Console log
2019-09-06 13:45:55.845 INFO  c.k.k.core.webui.driver.DriverFactory    - sessionId = 2cde39924e0651313007e6beedae94bf
2019-09-06 13:45:55.865 INFO  c.k.k.core.webui.driver.DriverFactory    - browser = Chrome 76.0.3809.132
2019-09-06 13:45:55.866 INFO  c.k.k.core.webui.driver.DriverFactory    - platform = Mac OS X
2019-09-06 13:45:55.867 INFO  c.k.k.core.webui.driver.DriverFactory    - seleniumVersion = 3.141.59
2019-09-06 13:45:55.876 INFO  c.k.k.core.webui.driver.DriverFactory    - proxyInformation = ProxyInformation{proxyOption=NO_PROXY, proxyServerType=HTTP, password=, proxyServerAddress=, proxyServerPort=0}
2019-09-06 13:45:55.888 DEBUG testcase.Event Firing Web Driver         - 2: webdriver = getWebDriver()
2019-09-06 13:45:55.895 DEBUG testcase.Event Firing Web Driver         - 3: eventFiring = webdriver
2019-09-06 13:45:55.910 DEBUG testcase.Event Firing Web Driver         - 4: eventFiring.register(new customlistener.MyCustomWebEventListener())
2019-09-06 13:45:55.927 DEBUG testcase.Event Firing Web Driver         - 5: changeWebDriverWithoutLog(eventFiring)
2019-09-06 13:45:55.947 DEBUG testcase.Event Firing Web Driver         - 6: navigateToUrl("www.google.com")
Before navigating to http://www.google.com
2019-09-06 13:45:56.965 DEBUG testcase.Event Firing Web Driver         - 7: closeBrowser()
2019-09-06 13:45:57.091 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/Ev
  1. Using RemoteWebDriver

Because EventFiringWebDriver does not implement the interface 'RemoteWebDriver'. If your code is currently casting the WebDriver obtained from DriverFactory like this:

....
RemoteWebDriver katalonWebDriver = (RemoteWebDriver) DriverFactory.getWebDriver()
// Using RemoteWebDriver from now on

Then starting from Katalon 7.0.0, the following exception will be thrown:

Cannot cast object 'com.kms.katalon.core.webui.driver.SmartWaitWebDriver@7cab1508' with class 'com.kms.katalon.core.webui.driver.SmartWaitWebDriver' to class 'org.openqa.selenium.remote.RemoteWebDriver'

(From Russ Thomas's bug report)

To obtain the RemoteWebDriver instance safely:

....
// Cast Katalon's WebDriver into EventFiringWebDriver
EventFiringWebDriver eventFiring = (EventFiringWebDriver) DriverFactory.getWebDriver()
// Get the driver wrapped inside
WebDriver wrappedWebDriver = eventFiring.getWrappedDriver()
// Cast the wrapped driver into RemoteWebDriver
RemoteWebDriver katalonWebDriver = (RemoteWebDriver) wrappedWebDriver
// Using RemoteWebDriver from now on

We recommend encapsulating the above logic into a function to avoid code duplication.

Feedback