how to call object value defined in keyword into the script to print on console/log viewer.

//custom defined keyword
package testpack
public class Message
{

@Keyword
public static void PageName(String message)
{
    String s= "praveen"
}

}

//call of keyword in the script
def a= CustomKeywords.'testpack.Message.PageName.s'()
log.logInfo(" my name is " + a)

**it shows error **
FAILED because (of) java.lang.ClassNotFoundException: testpack.Message.PageName

_i want to call object s in the script and print in the log viewer. _

Comments

  • edited October 11
    1. You can call a static method directly using Class.method() notation
    2. You can't call s because it is a variable, not a method. If you want to get a value of s, you have to return it as method output.

      // custom keyword
      public class Message {
      public static String PageName(String message) {
      String s = "praveen"
      return s
      }
      }

      // keyword call
      import testpack.Message
      def a = Message.PageName("yourMessageString")
      log.logInfo(" my name is " + a)

  • It worked exactly what i was looking for. Thank you so much . Can you also look at my this query, it will be great help

    https://forum.katalon.com/discussion/2573/how-to-print-custom-message-in-failure-handling#latest

Sign In or Register to comment.