Unable to see created custom keyword in the test case


#1

Created a Custom keyword is not displayed in test case custom keyword drop down. Though there is no error in the created custom keyword.

Code:

package dynamicWebElements

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.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.webui.driver.DriverFactory

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.remote.RemoteWebDriver;
import java.lang.System;
import java.util.Properties;

import internal.GlobalVariable

public class HandlingDynamicWebElements {

public HandleDynamicWebElement() throws InterruptedException {

	try {

		System.setProperty("webdriver.chrome.driver","Driver Path");
		WebDriver driver = new ChromeDriver();

		String baseUrl = "URL";
		driver.get(baseUrl);
		driver.manage().window().maximize();
		Thread.sleep(15000);

		driver.findElement(By.linkText("Sections")).click();
		println("Section Clicked");
		Thread.sleep(5000);

		driver.findElement(By.xpath("//a[text()=' Add New Section']")).click();
		println("Add section clicked");
		Thread.sleep(5000);
		driver.findElement(By.id("projectHeading")).sendKeys("hello");
		Thread.sleep(5000);
		driver.findElement(By.id("select2-sel_DocumentCategoryList-container")).click();
		Thread.sleep(3000);
		driver.findElement(By.xpath("//*[contains(@id,'CERTINS')]")).click();
		Thread.sleep(5000);
		driver.findElement(By.id("btnAddNewSectionOk")).click();
		Thread.sleep(5000);
		driver.findElement(By.linkText("hello")).click();



		List<WebElement> allLinks = driver.findElements(By.tagName("a"));
		println("allLinks......"+allLinks.size());

		try {
			for(WebElement link:allLinks){

				if(link.getAttribute("href").contains("section-")==true) {
					println("Get Text 1 : "+link.getText());
				}
				else {
					//System.out.println("");
				}
			}
		} catch (NullPointerException e) {
			println("NullPointerException occurred");
		}

		try {
			for(int i=0;i<allLinks.size();i++) {
				println(allLinks.get(i).getAttribute("href").contains("section-"));
				if(allLinks.get(i).getAttribute("href").contains("section-")==true) {
					println("Get Text  2 : "+allLinks.get(i).getText());
				}
			}
		} catch (NullPointerException e) {
			println("NullPointerException occurred");
		}
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}

}


#2

I’m a little concerned because your method is a class constructor - maybe that’s okay, but I don’t know for sure. Either way, to have your keyword show up in the list, you need to decorate the method with @Keyword.


#3

Thanks Russ… Its resolved… As you said just the @keyword was missing


#4