In Katalon, users can set additional keywords to increase the functionality of Katalon Studio in addition to the built-in keywords. Like other built-in keywords, custom keywords can be used in test cases once developed. Users can expand keywords and reuse them across projects thanks to this capability.
Katalon Studio is built on top of webDriver API. To use the webDriver API first, we need to get the implementation of webDriver API from the Katalon studio. Now we can use the webDriver instance to access the interface and methods present inside the webDriver API. We have to use the class driverFactory and the method getWebDriver. After getting the instance of webDriver, I can use webDriver API.
Create a Package
Custom keywords can be categorized into a package to make them easier to search for and utilize.
- Select File – New – Package from the main menu. Enter the name of your package and click OK.
- Accordingly, a new package is created in Katalon Studio.
Creating A Custom Keyword
- Create a custom keyword.
Select File – New – Keyword from the main menu to open the New Keyword dialog. Fill in with appropriate details and click on OK.
Choosing a Global Software Development Partner to Accelerate Your Digital Strategy
To be successful and outpace the competition, you need a software development partner that excels in exactly the type of digital projects you are now faced with accelerating, and in the most cost effective and optimized way possible.
- Accordingly, a new keyword is added to the designated package.
- To define a Unique Keyword in Java/Groovy, add the following block of code to your class.
We are creating an object “driver” that will get the instance of webDriver.
We Created a method executeScript with one parameter and a “@Keyword” annotation. It can be uniquely identified as a keyword.
In the second executeScript, we must Convert the testObject into a webElement to use it along with the webDriver API. To achieve this, we use the class webUicommonHelper.findWebElement(). Helps us get a response as a webElement.