Are CustomKeyword dieing after their call?

So basically, can you call a CustomKeyword then store some data in variable in the class and reuse later ? If this is not possible, is there a way to store data from tests in global variable maybe ?

The answer is: yes, but…

Basically, the “lifetime” of your keywords/classes is the lifetime of your test case. When your test case is running as part of a suite, each test case is a new instance of the test case so your storage requirement would need to come from GlobalVariables (or use your own system, writing values to an external file, perhaps).

This is the crucial part of your question. What do you mean by “later”? Later in the same script? Later in a different script? In a different test suite altogether?

my answer:
the keyword don’t die, because is a class.a class is just a blueprint.
but the instance of it, created when you run a testcase, yes, will be destroyed when the testcase ends, as @Russ_Thomas briefly explained.
you may have to read a bit about java scopes.
global variable instance it is scoped to a testsuite,so is more suitable for sharing data across testcases ‘in memory’ (his instance will survive until the suite ends)… or, less memory hungry but with IO cost, use external files (that can survive across test collections too … based on the implementation)

However, from what I understand, Test Listener lifetime is longer and can be used to keep data from each tests.

Yes, but not by much. Your test case is executed as in instance of the test case script class. beforeTestCase et al (“hooks”) are executed prior to and after the invisible run method of your test case script class. (It’s a bit more complex than that, but that’s the essence of how it works).

Something like this pseudocode:

tc.beforeTestCase()
tc.run("your tc")
tc.afterTestCase()

No, but Test suite listener are living during all tests cases.

True. So now what?

The answer to your original question (the subject of this thread) is still “Yes, but…”

Three people have given essentially the same answer. If you’re looking for WebUI.doSomeMagic() I’m sorry it doesn’t exist. If you have another question on this topic, please ask it.

Here’s my suite hook. Maybe it will trigger something for you:

class SuiteListener extends com.co.base.basePage {
  
  /**
   * Executes before every test suite starts.
   * @param testSuiteContext: related information of the executed test suite.
   */
  @BeforeTestSuite
  def beforeTestSuite(TestSuiteContext testSuiteContext) {
    String suiteId = testSuiteContext.getTestSuiteId() 
    setSuiteId(suiteId)
    new com.co.reports.Report().startSuiteReport(suiteId)
    new com.co.reports.Report().startSuiteErrorReport(suiteId)
  }

  /**
   * Executes after every test suite ends.
   * @param testSuiteContext: related information of the executed test suite.
   */
  @AfterTestSuite
  def afterTestSuite(TestSuiteContext testSuiteContext) {
    new com.co.reports.Report().endSuiteErrorReport()
  }
}

nope. only instances survive or not. for the defined scope. listeners are instances/ methods of an abstract class. with an ‘extended scope’ but limited to the main runtime loop.

in the end, if we realy want, we can hook the hooks