How to call Test case Variable value to Test case listener

I have used the below code to set the value of file name, which is unique for each test case and it is given as variable in each test case. But still when I am trying to get its value in the BeforeTestCase listener. The value is returned as null. How should I call the value of the variable in before test case listener.

@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
println testCaseContext.getTestCaseId()
println testCaseContext.getTestCaseVariables()
Map<String, Object> map = testCaseContext.getTestCaseVariables()
String fileName = map.get(“fileName”)
helper.webDeploy(‘samautomationtest’,fileName)
}

@kazurayam please help
@Russ_Thomas
Thanks
Sam.

@duyluong If it’s true the TC variables aren’t set prior to execution of beforeTestCase, can this be fixed?

1 Like

@smlpreetham08

Please use Code Formatting syntax for better readability of your post

1 Like
  • the variable fileName of a Test Case
  • the String variable fileName in the @BeforeTestCase-annotated method in a Test Listener

these 2 varibles are independent, have no relation.

Your Test Case script can not directly read the fileName variable in the Test Listener.


the variables of a Test Case is specifically used for Data Driven feature. Katalon Studio transfers data from external file into variables of Test Case liasing by name.


Create a GlobalVariable.fileName of type String in the default profile. The initial value does not matter; can be “”.

Your @BeforeTestCase-annotated method should write any value you want into the GlobalVariable.fileName.

Your Test Case can read the value out of the GlobalVariable.fileName

1 Like

Ok Should I try to assign the value in the Test case using script mode like follows.

String fileName = 'eCOA_App_32589'

Did you mean it would work like this
@kazurayam

@kazurayam No that is not what my expectation actually the Test case should return the value. Why because this is should be used as an argument for the keyword used in the beforeTest annotation. Ok if this is not possible I found a workaround.

I do not understand what you mean.

To elaborate this we have to deploy a web build to AWS using cygwin on a specific ID. The builds for each Test case have different configurations which are zipped and stored in a separate folder locally. I have made a keyword which deploys the build on to that URL using bash.

for Example samautomationtest is my ID and URL for launching the web app is IP/hh/ecoa/${ID}

so when I want to run a suite with different Test cases. I need to deploy the build first and then execute my Test case. The parameters for this keyword which deploys the build are one is the ‘ID’ and the other is the ‘name’ of the zip file which is the name of the test case.

Why I want to get the test case name from the Test case itself to Test listener is I deploy different builds to same URL since I use sequential execution. So I can give the ID hardcoded in the keyword and declare it once for all the test cases, in the before test case annotation.

Please let me know if you have any questions?

@kazurayam

Sorry, I can not understand what you want to achieve.

@Russ_Thomas @smlpreetham08

I checked on the latest version v8.2.5 and the Test Listener can list the test case variables correctly when using testCaseContext.getTestCaseVariables() in the @BeforeTestCase method



1 Like

Is this available and working in Katalon Version 7.8.0. Because our organisation only wants us to use this version of Katalon.

@Russ_Thomas @duyluong