Introduction
Let's ensure we understand the foundational concepts before delving further into the subjects. Here is a brief introduction if you are unfamiliar with Katalon Studio.
Katalon Studio is a tool that is developed by KM technology. It will also help you automate Web Based Applications, Mobile Applications, and API Testing. It increases the speed of delivery and time to market. Our organisation has become better.
This product's recording feature is helpful for our testing needs. User-friendliness and AI smart healing capabilities are two of Its most valuable features.
This article explains how to handle Web drivers with the support of Event firing Web driver in katalon studio.
Without further ado, let's get started.
Handle Web Drivers with Event Firing Web Driver
This can be used, for instance, to log operations or to set off specific events before them.
📜 Suppose you want to learn more about this class. You can go through the Selenium documentation.
💁 Note: With Katalon Studio version 7.0.0, you can set event-driven features related to your WebDrivers for test execution by using the Selenium-based class Event Firing Web Driver.
Use Web Driver Event Listeners
The Web Driver Event Listener is a tool you can use to handle events the Web Driver starts, such as those that occur before or after clicking or before or after navigating. Web Driver Event Listeners is an interface to receive events from the Web Driver, whereas EventFiringWebDriver is a class that wraps around the WebDriver to fling events.
📜 Suppose you want to learn more about this class. You can go through the Selenium documentation here: Web Driver Event Listener.
📲 The use of a custom Web Driver Event Listener is shown below:
1️⃣ Create a package with a keyword in it. Click File > New > Package to start. Here, the package's name is customkeyword.
2️⃣ To manage WebDriver events, add a new keyword.
a. Select File > New > Keywords. New dialogue box appears.
b. For your keyword, click Browse to select a package, then type the class name by hand. In this case, we select the package we built in Step 1 and give the keyword the name MyCustomWebEventListener. Press OK. A brand-new keyword page loads.
c. Insert the sample code from below into the newly formed keyword.
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;
}
}
3️⃣ Open the test script. Copy the sample code below, and then paste it to 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())
DriverFactory.changeWebDriver(eventFiring)
WebUI.navigateToUrl('www.google.com')
WebUI.closeBrowser()
4️⃣ Press Run, then check the Console log to see the outcome.
Use Remote Web Driver
There are two parts that make up a remote WebDriver: a client and a server. The server is just a Java servlet, which can be hosted on any contemporary JEE app server. The client is your WebDriver test.The main difference is that a remote WebDriver needs to be set up in order for it to execute your tests on a different computer.
📜 Since Event Firing Web Driver does not implement the Remote Web Driver interface, you must take the following steps in order to obtain a Remote Web Driver 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
// Katalon now uses RemoteWebDriver instead of your local driver