How to use custom keyword inside a custom keyword

Hi,

Is it possible to put a custom keyword inside a custom keyword in a test case?

Here are my custom keywords:

  1. CustomKeywords.‘myPackage.PDFVerification.isFileDownloaded’(String downloadPath, String fileName)
    • this verifies if the downloaded filename format is correct
  2. CustomKeywords.‘myPackage.DateTimeVerification.today’()
    • this only prints the current date/time

I want custom keyword # 2 to be the ‘fileName’ in custom keyword #1.
I tried doing it so but it returns “null”.

Here’s what I did:

CustomKeywords.‘myPackage.PDFVerification.isFileDownloaded’(‘C:\Users\Admin\Downloads’, “Report”+CustomKeywords.‘myPackage.DateTimeVerification.today’()+“.csv”)

Here’s the error message:

06-30-2019 10:29:41 PM Test Cases/Download PDF and Export Functions/RMS_Locate_AssetStatus_Export

Elapsed time: 21.478s

myPackage.PDFVerification.isFileDownloaded:41

myPackage.PDFVerification.invokeMethod:0

Test Cases/Download PDF and Export Functions/RMS_Locate_AssetStatus_Export FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Report_null.csv does not exist in C:\Users\Admin\Downloads
at com.kms.katalon.core.util.KeywordUtil.markFailed(KeywordUtil.java:19)
at com.kms.katalon.core.util.KeywordUtil$markFailed.call(Unknown Source)
at myPackage.PDFVerification.isFileDownloaded(PDFVerification.groovy:41)
at myPackage.PDFVerification.invokeMethod(PDFVerification.groovy)
at com.kms.katalon.core.main.CustomKeywordDelegatingMetaClass.invokeStaticMethod(CustomKeywordDelegatingMetaClass.java:50)
at RMS_Locate_AssetStatus_Export.run(RMS_Locate_AssetStatus_Export:41)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1561904979984.run(TempTestCase1561904979984.groovy:21)

Thanks in advance.

String fname = CustomKeywords.‘myPackage.DateTimeVerification.today’()
CustomKeywords.‘myPackage.PDFVerification.isFileDownloaded’("path", fname)

That will do what you asked, if I understood you correctly.

1 Like

I already tried that and still getting null. I am not sure why it is returning null because I can see in my console log that custom keyword for current date/time is being logged correctly (when I run it separately).

Oh wait, I put a semi-colon in my variable.

String fname = CustomKeywords.‘myPackage.DateTimeVerification.today’();

I’ll just try it without the semi-colon.

This isn’t working. I tried to print the string and it also prints null. How do I get the log in the console? Because the correct date/time is logged there when I run the custom keyword for it.

String currentdatetime = CustomKeywords.‘myPackage.DateTimeVerification.today’()
CustomKeywords.‘myPackage.DateTimeVerification.today’()
println "Current Date / Time: "+currentdatetime

But you haven’t shown me (us) “this”. Paste a copy of the CustomKeywords.‘myPackage.DateTimeVerification.today’() method here.

package myPackage

import java.text.SimpleDateFormat

import com.kms.katalon.core.annotation.Keyword

public class DateTimeVerification {

@Keyword

def today() {

  Date date = new Date()
  String datePart = date.format("yyyyMMdd")
  String timePart = date.format("hhmm")

  println datePart+timePart

}
}

Sorry for that :smile:

And I’m sorry you deleted the post with info I was asking for. I was in the middle of replying to you when you deleted the post.

Sorry, but I don’t have time for this.

Good luck - you’re going to need a ton of it.

I’m very sorry :frowning: I thought I posted the wrong one. Thanks anyway :frowning:

Your keyword is just printing something, therefore returning null.
It should return a string with the value needed (datePart+timePart)

1 Like

@Ibus Thank you! It is working now :hugs: