Creating Functions in Custom User defined Class for Re-Use

After using KATALON for long now. I am a fan of it, however I feel one of the biggest feature which enables re-usability is missing, and that is ability to create user defined classes. Then use the functions created in those classes across Test. I know there is a feature of creating Keywords however with classes it is more structured and readable.

Not sure if we have the support for classes in KATALON. If yes, then kindly let me know.

Also would be good to have direct support of creating .properties file like we have csv, excel support.

Also would be good to have direct support of creating .properties file like we have csv, excel support.

The Katalon Keywords facility is a system of Package -> Class(es) -> methods

Don’t let the name confuse the purpose.

And you don’t need to use the @Keyword decorator.

package my_package

class MyClass extends MyOtherClass {

  MyClass() {
    WebUI.comment("I am the MyClass constructor.")
  }

  def myMethod() {
    WebUI.comment("I am myMethod")
  }

  static void staticMethod() {
    WebUI.comment("I am a static method. You can call me anywhere you import me statically.")
  }
}
2 Likes

Russ Thomas said:

The Katalon Keywords facility is a system of Package → Class(es) → methods

Don’t let the name confuse the purpose.

And you don’t need to use the @Keyword decorator.

package my_package

class MyClass extends MyOtherClass {

MyClass() {
WebUI.comment(“I am the MyClass constructor.”)
}

def myMethod() {
WebUI.comment(“I am myMethod”)
}

static void staticMethod() {
WebUI.comment(“I am a static method. You can call me anywhere you import me statically.”)
}
}


  
  

  

Can you instantiate an object somewhere once and use it across test suites?

Can you instantiate an object somewhere once and use it across test suites?

Yes. Use GlobalVariable to store the object. Possibly you want to instantiate the object in Test Listener’s @BeforeTestSuite-annotated method.

kazurayam said:

Can you instantiate an object somewhere once and use it across test suites?

Yes. Use GlobalVariable to store the object. Possibly you want to instantiate the object in Test Listener’s @BeforeTestSuite-annotated method.

Thanks for the reply. But by across test suites I actually meant across a test suite collection. So If I instantiate the object in a test listener, it will be destroyed after every test suite completion.

Ian,

So If I instantiate the object in a test listener, it will be destroyed after every test suite completion.

You are absolutely right.

What we currently call “GlobalVariable” is in effect “Variable In a Test Suite scope”. You are talking about something which covers one layer up: “Variable In a Test Suite Collection scope”, which we do not have.