Hey guys, I made a custom drag and drop function from here Handling drag and drop testing for web applications with Katalon Studio | Katalon Docs
now I want to use that function inside another custom keyword. Keeps giving me this error.
I have similar situation, need to call custom keyword inside of custon keyword. Is it possible? And if it is, how?
at the moment, I still am trying to figure this out, just using the custom keywords separately not together. I am sure there is a way, haven’t figured it out yet
This is not supported yet. Actually a custom keyword is presented as a function, so you just call it directly using method call, e.g:
@Keyword
def isElementPresent(TestObject to, int timeout){
//Use Katalon built-in function to find elements with time out 1 seconds
List elements = WebUiBuiltInKeywords.findWebElements(to, timeout)
//Call getHtmlTableColumns custom keyword
getHtmlTableColumns(null, “”)
return elements.size() > 0
}
Yes, it can.
thanks … I found another post that shows how… basically you put the calling keyword that is in a different package in parenthesis “()” and use the “new” java keyword
(new “packagename”.“classname”()).“methodname”()
example:
(new com.acme.common.myclass()).mymethod()
Thanks a lot! I was wishing to have this!
Thank you!
Thank you it’s working fine but how to pass values for eg
I have
@Keyword
def fill details (String Value)
To another custom keyword
hi,
why not class inside testcases
Can u give me a sample pls … i tried but not working
hello,
not sure is this what you are searched
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 static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import com.kms.katalon.core.checkpoint.Checkpoint as 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 as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as 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.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
//import TestClass
TestClass test = new TestClass("Katalon")
println(test.getTestString())
test.setTestString("Test Automation")
println(test.getTestString())
TestClass2 test2 = new TestClass2()
println("DEBUG defined in class1 constructor and called with super constructor in class2 "+test2.getTestString())
TestClass2 test3 = new TestClass2()
test3.setString("For Testers")
println("DEBUG overrided by class2 constructor "+test3.getString())
for (TestClass.Weekdays days : TestClass.Weekdays.values()){
println(days.value+" : "+days)
test.listString.add(days)
}
println test.listString
for (CrunchifyEnumExample.Company cName : CrunchifyEnumExample.Company.values()){
//System.out.println("Company Value: " + cName.value + " - Company Name: " + cName);
switch(cName.value){
case 30:
println "Company Name: "+cName
break
case 10:
println "Company Name: "+cName
break
case 15:
println "Company Name: "+cName
break
case 20:
println "Company Name: "+cName
break
case 25:
println "Company Name: "+cName
break
default:
println "no values!!!"
break
}
}
public class CrunchifyEnumExample {
public enum Company {
EBAY(30), PAYPAL(10), GOOGLE(15), YAHOO(20), ATT(25);
private int value;
private Company(int value) {
this.value = value;
}
}
}
public class TestClass{
private static String testString
private static List<String> listString = new ArrayList<>()
public enum Weekdays {
Monday(1), Tuesday(2), Wednesday(3), Thursday(4), Friday(5), Saturday(6), Sunday(7);
private int value;
private Weekdays(int value) {
this.value = value;
}
}
public TestClass(){}
public TestClass(String test){
this.testString = test
}
public static String getTestString(){
return this.testString
}
public static void setTestString(String test){
this.testString = test
}
}
public class TestClass2 extends TestClass{
private static String testString2
public TestClass2(){
//super.testString
super()
}
public static void setString(String test){
this.testString2 = test
//println("DEBUG testString in setter 2 "+testString2)
}
public static String getString(){
return this.testString2
}
}
Katalon
2020-02-21 16:59:21.027 DEBUG testcase.ClassIntoTestCase - 3: test.setTestString("Test Automation")
2020-02-21 16:59:21.027 DEBUG testcase.ClassIntoTestCase - 4: println(test.getTestString())
Test Automation
2020-02-21 16:59:21.049 DEBUG testcase.ClassIntoTestCase - 5: test2 = new TestClass2()
2020-02-21 16:59:21.119 DEBUG testcase.ClassIntoTestCase - 6: println("DEBUG defined in class1 constructor and called with super constructor in class2 " + test2.getTestString())
DEBUG defined in class1 constructor and called with super constructor in class2 Test Automation
2020-02-21 16:59:21.170 DEBUG testcase.ClassIntoTestCase - 7: test3 = new TestClass2()
2020-02-21 16:59:21.191 DEBUG testcase.ClassIntoTestCase - 8: test3.setString("For Testers")
2020-02-21 16:59:21.207 DEBUG testcase.ClassIntoTestCase - 9: println("DEBUG overrided by class2 constructor " + test3.getString())
DEBUG overrided by class2 constructor For Testers
2020-02-21 16:59:21.269 DEBUG testcase.ClassIntoTestCase - 10: for (TestClass$Weekdays days : TestClass$Weekdays.values())
2020-02-21 16:59:21.481 DEBUG testcase.ClassIntoTestCase - 1: println(value + " : " + days)
1 : Monday
2020-02-21 16:59:21.481 DEBUG testcase.ClassIntoTestCase - 2: listString.add(days)
2020-02-21 16:59:21.498 DEBUG testcase.ClassIntoTestCase - 1: println(value + " : " + days)
2 : Tuesday
2020-02-21 16:59:21.500 DEBUG testcase.ClassIntoTestCase - 2: listString.add(days)
2020-02-21 16:59:21.500 DEBUG testcase.ClassIntoTestCase - 1: println(value + " : " + days)
3 : Wednesday
2020-02-21 16:59:21.500 DEBUG testcase.ClassIntoTestCase - 2: listString.add(days)
2020-02-21 16:59:21.500 DEBUG testcase.ClassIntoTestCase - 1: println(value + " : " + days)
4 : Thursday
2020-02-21 16:59:21.516 DEBUG testcase.ClassIntoTestCase - 2: listString.add(days)
2020-02-21 16:59:21.516 DEBUG testcase.ClassIntoTestCase - 1: println(value + " : " + days)
5 : Friday
2020-02-21 16:59:21.531 DEBUG testcase.ClassIntoTestCase - 2: listString.add(days)
2020-02-21 16:59:21.547 DEBUG testcase.ClassIntoTestCase - 1: println(value + " : " + days)
6 : Saturday
2020-02-21 16:59:21.547 DEBUG testcase.ClassIntoTestCase - 2: listString.add(days)
2020-02-21 16:59:21.547 DEBUG testcase.ClassIntoTestCase - 1: println(value + " : " + days)
7 : Sunday
2020-02-21 16:59:21.562 DEBUG testcase.ClassIntoTestCase - 2: listString.add(days)
2020-02-21 16:59:21.562 DEBUG testcase.ClassIntoTestCase - 11: println(listString)
[Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday]
2020-02-21 16:59:21.578 DEBUG testcase.ClassIntoTestCase - 12: for (CrunchifyEnumExample$Company cName : CrunchifyEnumExample$Company.values())
2020-02-21 16:59:21.622 DEBUG testcase.ClassIntoTestCase - 1: switch (value)
2020-02-21 16:59:21.637 DEBUG testcase.ClassIntoTestCase - 1: case 30:
2020-02-21 16:59:21.637 DEBUG testcase.ClassIntoTestCase - 1: println("Company Name: " + cName)
Company Name: EBAY
2020-02-21 16:59:21.637 DEBUG testcase.ClassIntoTestCase - 2: break
2020-02-21 16:59:21.637 DEBUG testcase.ClassIntoTestCase - 1: switch (value)
2020-02-21 16:59:21.637 DEBUG testcase.ClassIntoTestCase - 2: case 10:
2020-02-21 16:59:21.653 DEBUG testcase.ClassIntoTestCase - 1: println("Company Name: " + cName)
Company Name: PAYPAL
2020-02-21 16:59:21.653 DEBUG testcase.ClassIntoTestCase - 2: break
2020-02-21 16:59:21.700 DEBUG testcase.ClassIntoTestCase - 1: switch (value)
2020-02-21 16:59:21.700 DEBUG testcase.ClassIntoTestCase - 3: case 15:
2020-02-21 16:59:21.731 DEBUG testcase.ClassIntoTestCase - 1: println("Company Name: " + cName)
Company Name: GOOGLE
2020-02-21 16:59:21.755 DEBUG testcase.ClassIntoTestCase - 2: break
2020-02-21 16:59:21.757 DEBUG testcase.ClassIntoTestCase - 1: switch (value)
2020-02-21 16:59:21.757 DEBUG testcase.ClassIntoTestCase - 4: case 20:
2020-02-21 16:59:21.757 DEBUG testcase.ClassIntoTestCase - 1: println("Company Name: " + cName)
Company Name: YAHOO
2020-02-21 16:59:21.773 DEBUG testcase.ClassIntoTestCase - 2: break
2020-02-21 16:59:21.773 DEBUG testcase.ClassIntoTestCase - 1: switch (value)
2020-02-21 16:59:21.791 DEBUG testcase.ClassIntoTestCase - 5: case 25:
2020-02-21 16:59:21.791 DEBUG testcase.ClassIntoTestCase - 1: println("Company Name: " + cName)
Company Name: ATT