Custom keywords in Katalon studio

How to create custom keywords in katalon studio. You can define your own Keyword. It will work like same as built-in keywords. In this tutorial, I am going to show you how can you define and call your custom keywords in katalon studio.

Testcase Scenario:

For example, we are going to perform login activity so we need to perform following steps.

  • Open Browser.
  • Navigate URL.
  • Enter username and password.
  • Click on the login button.
  • Close Browser.

We can perform this test case by using custom keywords but here we are going to do the same task by Custom keyword.

 Custom keywords in Katalon studio

Keyword>new>Keyword

Enter a Package name and Keyword name:

Define custom keyword in Katalon studio. You just need to enter “@Keyword” and another code is same as Java methods.

@Keyword
  public void goLogin(){
    WebUI.navigateToUrl('http://demoaut.katalon.com/profile.php#login')
    
    WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_username'), 'John Doe')
    
    WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_password'), 'ThisIsNotAPassword')
    
    WebUI.click(findTestObject('Page_CURA Healthcare Service/button_Login'))
  }

Call custom keyword in katalon Studio.

CustomKeywords.‘mypack.Login.goLogin’()

Complete SourceCode

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testcase.TestCaseFactory as TestCaseFactory
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testdata.TestDataFactory as TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys


WebUI.openBrowser('')
CustomKeywords.'mypack.Login.goLogin'()
WebUI.closeBrowser()

CustomKeyword(Login.groovy):

package mypack

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords

import internal.GlobalVariable

import MobileBuiltInKeywords as Mobile
import WSBuiltInKeywords as WS
import WebUiBuiltInKeywords as WebUI

public class Login {
  @Keyword
  public void goLogin(){
    WebUI.navigateToUrl('http://demoaut.katalon.com/profile.php#login')
    
    WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_username'), 'John Doe')
    
    WebUI.setText(findTestObject('Page_CURA Healthcare Service/input_password'), 'ThisIsNotAPassword')
    
    WebUI.click(findTestObject('Page_CURA Healthcare Service/button_Login'))
  }
}

Add a Comment

Your email address will not be published. Required fields are marked *

15 + 6 =