Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Welcome to another blog on Katalon Studio. We have finally come to the topic of Selenium WebDriver.
This blog will take you through a series of fundamental concepts of Katalon Studio along with How to use Selenium WebDriver in Katalon Studio.
Before going any further, Let's discuss the word and world of Katalon Studio.
We need to thoroughly verify & test our product/project before launching it in the market. Product testing is done either manually or automatically. The manual testing of API is very time-consuming. Hence, Automated Testing has become very popular these days. Based on Selenium, Katalon is one of the best and most used automated testing software with easy-to-use features.
Features of Katalon Studio
Katalon Studio helps in the automated testing of APIs as it has an inbuilt API testing module.
Automated scripts can be created which are easy and simple to use.
Katalon provides accessible features like snippets, a debugger, and code references.
Katalon Studio is compatible with other third-party testing tools like Swagger and Postman.
What are Web Drivers?
Before directly jumping to the primary topic of this blog, we should know what WebDrivers are.
A WebDriver is an open-source tool used for the automated testing of web apps across multiple browsers. It brings features for navigating web pages, user input, JavaScript execution, etc. In the Katalon Studio, it is effortless to handle them. There are direct go-to options like Terminate, Update, etc.
One of the WebDrivers that help in automated web application testing is the Selenium WebDriver. It tends to provide a friendly API that's easy to explore and use. Selenium WebDriver framework helps in hiding the complexities of dealing with the WebDriver from users and only focuses on Katalon Keywords.
How to use Selenium WebDriver in Katalon Studio
Create/Call/Terminate
One of the best go-to feature of Selenium is that we do not need to create and call the instance of the WebDriver. It is automatically created when we call the keyword. In the below example, Chrome is taken as the WebDriver
WebUI.openBrowser
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
WebUI.openBrowser('')
WebDriver myDriver = new ChromeDriver()
You can also try this code with Online Java Compiler
And lastly, We can easily terminate the WebDriver instance by calling driver.close().
It’s important to note that we can not use Katalon WebUI keywords with a manually created WebDriver instance.
DriverFactory
We have a library ‘Driver Factory’, mainly responsible for providing easy-to-use inbuilt methods for using WebDriver along with manipulation with the WebDriver instance.
We can use the Katalon Keywords with the manually created WebDriver instances with the help of changeWebDriver() method which sets the driver as a default driver.
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
System.setProperty("webdriver.chrome.driver", "C:\\test\\chromedriver.exe")
WebDriver mydriver = new ChromeDriver()
// this will not work
//exception would be thrown
WebUI.click(testObject)
DriverFactory.changeWebDriver(mydriver)
//Now, it works as expected
WebUI.click(testObject)
You can also try this code with Online Java Compiler
Next up we have the getWebDriver()method,opposite of the changeWebDriver() method to get an instance of WebDriver created by Katalon itself and use its methods.
Firstly, a WebDriver instance is created in the openBrowser() method.
Multiple WebDrivers
It is not permitted to use multiple drivers in Katalon at the same time. Calling WebUI.openBrowser() twice will lead to the termination of the first browser window and opening the second one.
The method findElements() returns a list of WebElements found by a specified selector. It becomes handy when we access multiple elements, like tally or select all of them.
Refer to the code below which shows How we can count the total of options in a select box using WebDriver.
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
System.setProperty("webdriver.chrome.driver", DriverFactory.getChromeDriverPath())
WebDriver myDriver = new ChromeDriver()
List optionsList = myDriver.findElements(By.xpath("//select[@id='selectBox1']/option"))
int numOfOptions = optionsList.size()
You can also try this code with Online Java Compiler
Actions is one powerful API used to emulate complex user gestures from Selenium. To use Actions, we need a constructor which needs an instance of WebDriver.
How can we terminate the WebDrivers from the main menu?
Go to the main toolbar. From there, you need to select Tools. After selecting Tools, Tools > Web >Terminate WebDrivers
Which Scripting language do we use in Katalon Studio?
Groovy is used as a scripting language in Katalon.
Which method returns the path to any driver without coding it?
DriverFactory.getChromeDriverPath() is the method that returns the path to any driver.
Conclusion
We hope the blog helped you understand the concept of selenium WebDriver. Firstly, We began with the fundamentals of Katalon Studio and then the blog concluded with the concept of using Selenium WebDriver in Katalon Studio.
If you found this blog interesting and insightful, refer to similar blogs: