How to use a variable for verification on a GET request?

Hi,

I’m trying to figure out how I can incorporate variables in to my verifications for GET requests. As an example, lets say the below is the hardcoded value of my verification:

WS.verifyElementPropertyValue(response, ‘address.postcode[0]’, ‘DE1 3GL’)

I named the variable ‘postcode’ and have tried doing the following:

WS.verifyElementPropertyValue(response, ‘address.postcode[0]’, ‘${GlobalVariable.Postcode’)

and

WS.verifyElementPropertyValue(response, ‘address.postcode’, ‘${GlobalVariable.Postcode’)

but no joy with either of these. Does anyone know how I would make this work (either using my example as a demo or a different example)?

Thanks

Try this:

WS.verifyElementPropertyValue(response, "address.postcode", 
 "${GlobalVariable.Postcode}")

Or, just…

WS.verifyElementPropertyValue(response, "address.postcode", 
  GlobalVariable.Postcode)

Unfortunately I got no luck with those attempts as well.

I noticed I think I had a missing bracket so tweaked a few things to the below but still no luck:

WS.verifyElementPropertyValue(response, ‘address.postcode’, ‘${GlobalVariable.Postcode}’)

When I use this, I got the following in the verification log:

Unable to verify element property value (Root cause: com.kms.katalon.core.exception.StepFailedException: Expected element property value ‘${GlobalVariable.Postcode}’ is not equal with actual property value ‘BH2 5LT’

I have input the value for the variable as a string of BH2 5LT and in the body, the value is returning as “postcode”: “BH2 5LT” so I’m not sure why it doesn’t think these values meet.

Read my code again. Make yours match mine. Only THEN can you say it doesn’t work.

Also, please post any error logs.

I did try the those but they also didn’t work.

With WS.verifyElementPropertyValue(response, “address.postcode”, “${GlobalVariable.Postcode}”) and WS.verifyElementPropertyValue(response, “address.postcode”,
GlobalVariable.Postcode) I got given the following message:

5: verifyElementPropertyValue(response, “address.postcode”, $GlobalVariable.Postcode)
2022-05-05 14:44:10.115 ERROR c.k.k.core.main.WSVerificationExecutor - ? Verification FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: Postcode for class: internal.GlobalVariable

What does this do?

println GlobalVariable.Postcode

Add that before your WS calls.

Sorry for the long message but thought I’d add the verification log’s in case that might help.

I tried with both of the below but the same error log still:

println WS.verifyElementPropertyValue(response, “address.postcode”, “${GlobalVariable.Postcode}”)

println WS.verifyElementPropertyValue(response, “address.postcode”, GlobalVariable.Postcode)

The full log is:

2022-05-05 16:29:00.553 INFO c.k.k.core.main.WSVerificationExecutor - --------------------
2022-05-05 16:29:00.553 INFO c.k.k.core.main.WSVerificationExecutor - START Verification
2022-05-05 16:29:00.766 DEBUG testcase. - 1: request = getInstance().getCurrentRequest()
2022-05-05 16:29:00.903 DEBUG testcase. - 2: response = getInstance().getCurrentResponse()
2022-05-05 16:29:00.914 DEBUG testcase. - 3: println(verifyElementPropertyValue(response, “address.postcode”, $GlobalVariable.Postcode))
2022-05-05 16:29:00.934 ERROR c.k.k.core.main.WSVerificationExecutor - ? Verification FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: Postcode for class: internal.GlobalVariable
at WSVerification1651764540588.run(WSVerification1651764540588:15)
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.WSVerificationExecutor.runScript(WSVerificationExecutor.java:180)
at com.kms.katalon.core.main.WSVerificationExecutor.doExecute(WSVerificationExecutor.java:174)
at com.kms.katalon.core.main.WSVerificationExecutor.processExecutionPhase(WSVerificationExecutor.java:157)
at com.kms.katalon.core.main.WSVerificationExecutor.accessMainPhase(WSVerificationExecutor.java:149)
at com.kms.katalon.core.main.WSVerificationExecutor.execute(WSVerificationExecutor.java:131)
at com.kms.katalon.core.main.TestCaseMain.runWSVerificationScript(TestCaseMain.java:155)
at com.kms.katalon.core.main.TestCaseMain$runWSVerificationScript$0.call(Unknown Source)
at TempTestCase1651764538826.run(TempTestCase1651764538826.groovy:25)

2022-05-05 16:29:00.941 INFO c.k.k.core.main.WSVerificationExecutor - END Verification

I don’t think Katalon likes the way either of those requests are done I’m afraid. When doing it this way:

WS.verifyElementPropertyValue(response, ‘address.postcode’, ‘${GlobalVariable.Postcode}’)

or this way:

println WS.verifyElementPropertyValue(response, ‘address.postcode’, ‘${GlobalVariable.Postcode}’)

then it give the the following log:

2022-05-05 16:33:04.384 INFO c.k.k.core.main.WSVerificationExecutor - --------------------
2022-05-05 16:33:04.386 INFO c.k.k.core.main.WSVerificationExecutor - START Verification
2022-05-05 16:33:04.601 DEBUG testcase. - 1: request = getInstance().getCurrentRequest()
2022-05-05 16:33:04.742 DEBUG testcase. - 2: response = getInstance().getCurrentResponse()
2022-05-05 16:33:04.753 DEBUG testcase. - 3: println(verifyElementPropertyValue(response, “address.postcode”, “${GlobalVariable.Postcode}”))
2022-05-05 16:33:04.883 ERROR c.k.k.core.keyword.internal.KeywordMain - ? Expected element property value ‘${GlobalVariable.Postcode}’ is not equal with actual property value ‘BH2 5LT’
2022-05-05 16:33:04.892 ERROR c.k.k.core.keyword.internal.KeywordMain - ? Unable to verify element property value (Root cause: com.kms.katalon.core.exception.StepFailedException: Expected element property value ‘${GlobalVariable.Postcode}’ is not equal with actual property value ‘BH2 5LT’
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:50)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword$_verifyElementPropertyValue_closure1.doCall(VerifyElementPropertyValueKeyword.groovy:56)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword$_verifyElementPropertyValue_closure1.call(VerifyElementPropertyValueKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:74)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.verifyElementPropertyValue(VerifyElementPropertyValueKeyword.groovy:48)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.execute(VerifyElementPropertyValueKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue(WSBuiltInKeywords.groovy:189)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords$verifyElementPropertyValue.call(Unknown Source)
at WSVerification1651764784419.run(WSVerification1651764784419:15)
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.WSVerificationExecutor.runScript(WSVerificationExecutor.java:180)
at com.kms.katalon.core.main.WSVerificationExecutor.doExecute(WSVerificationExecutor.java:174)
at com.kms.katalon.core.main.WSVerificationExecutor.processExecutionPhase(WSVerificationExecutor.java:157)
at com.kms.katalon.core.main.WSVerificationExecutor.accessMainPhase(WSVerificationExecutor.java:149)
at com.kms.katalon.core.main.WSVerificationExecutor.execute(WSVerificationExecutor.java:131)
at com.kms.katalon.core.main.TestCaseMain.runWSVerificationScript(TestCaseMain.java:155)
at com.kms.katalon.core.main.TestCaseMain$runWSVerificationScript$0.call(Unknown Source)
at TempTestCase1651764782303.run(TempTestCase1651764782303.groovy:25)
)
2022-05-05 16:33:04.898 ERROR c.k.k.core.main.WSVerificationExecutor - ? Verification FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Expected element property value ‘${GlobalVariable.Postcode}’ is not equal with actual property value ‘BH2 5LT’
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:50)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword$_verifyElementPropertyValue_closure1.doCall(VerifyElementPropertyValueKeyword.groovy:56)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword$_verifyElementPropertyValue_closure1.call(VerifyElementPropertyValueKeyword.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:74)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.verifyElementPropertyValue(VerifyElementPropertyValueKeyword.groovy:48)
at com.kms.katalon.core.webservice.keyword.builtin.VerifyElementPropertyValueKeyword.execute(VerifyElementPropertyValueKeyword.groovy:43)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:74)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords.verifyElementPropertyValue(WSBuiltInKeywords.groovy:189)
at com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords$verifyElementPropertyValue.call(Unknown Source)
at WSVerification1651764784419.run(WSVerification1651764784419:15)
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.WSVerificationExecutor.runScript(WSVerificationExecutor.java:180)
at com.kms.katalon.core.main.WSVerificationExecutor.doExecute(WSVerificationExecutor.java:174)
at com.kms.katalon.core.main.WSVerificationExecutor.processExecutionPhase(WSVerificationExecutor.java:157)
at com.kms.katalon.core.main.WSVerificationExecutor.accessMainPhase(WSVerificationExecutor.java:149)
at com.kms.katalon.core.main.WSVerificationExecutor.execute(WSVerificationExecutor.java:131)
at com.kms.katalon.core.main.TestCaseMain.runWSVerificationScript(TestCaseMain.java:155)
at com.kms.katalon.core.main.TestCaseMain$runWSVerificationScript$0.call(Unknown Source)
at TempTestCase1651764782303.run(TempTestCase1651764782303.groovy:25)

2022-05-05 16:33:04.902 INFO c.k.k.core.main.WSVerificationExecutor - END Verification

No. Type this line EXACTLY above your WS calls.

println GlobalVariable.Postcode

WS.verifyElementPropertyValue(response, “address.postcode”, “${GlobalVariable.Postcode}”)

and

println GlobalVariable.Postcode

WS.verifyElementPropertyValue(response, “address.postcode”, GlobalVariable.Postcode)

Getting the same response:

2022-05-05 16:52:00.642 INFO c.k.k.core.main.WSVerificationExecutor - --------------------
2022-05-05 16:52:00.642 INFO c.k.k.core.main.WSVerificationExecutor - START Verification
2022-05-05 16:52:00.860 DEBUG testcase. - 1: request = getInstance().getCurrentRequest()
2022-05-05 16:52:00.999 DEBUG testcase. - 2: response = getInstance().getCurrentResponse()
2022-05-05 16:52:01.011 DEBUG testcase. - 3: println(Postcode)
2022-05-05 16:52:01.022 ERROR c.k.k.core.main.WSVerificationExecutor - ? Verification FAILED.
Reason:
groovy.lang.MissingPropertyException: No such property: Postcode for class: internal.GlobalVariable
at WSVerification1651765920677.run(WSVerification1651765920677:15)
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.WSVerificationExecutor.runScript(WSVerificationExecutor.java:180)
at com.kms.katalon.core.main.WSVerificationExecutor.doExecute(WSVerificationExecutor.java:174)
at com.kms.katalon.core.main.WSVerificationExecutor.processExecutionPhase(WSVerificationExecutor.java:157)
at com.kms.katalon.core.main.WSVerificationExecutor.accessMainPhase(WSVerificationExecutor.java:149)
at com.kms.katalon.core.main.WSVerificationExecutor.execute(WSVerificationExecutor.java:131)
at com.kms.katalon.core.main.TestCaseMain.runWSVerificationScript(TestCaseMain.java:155)
at com.kms.katalon.core.main.TestCaseMain$runWSVerificationScript$0.call(Unknown Source)
at TempTestCase1651765918987.run(TempTestCase1651765918987.groovy:25)

2022-05-05 16:52:01.031 INFO c.k.k.core.main.WSVerificationExecutor - END Verification

The println method outputs its result to the console:

image

It’s not displaying anything in the console.

Just a heads up, I’m leaving for the day and then off until Tuesday, so may be a delay in me responding to anything posted.

Now we’re getting somewhere…

image

That underline means the variable (property) is undefined. So the error you’re getting is correct.

I believe I have the value defined correctly within my profile. Is there anything that looks like it should be done differently?

You would be able to find a file <projectDir>/Libs/internal/GlobalVariable.groovy. This is the source code of internal.GlobalVariable class generated out of the Project *.glbl file(s). Please open the file with some text editor, and see how it is written.

I guess, you would find there is no Postcode property in the current version of that groovy source code. In other words, the groovy source is NOT in sync with the Profile you set. This is the reason why Postcode is displayed underlined in the code editor. Such discrepancy sometimes occur in Katalon Studio, perhaps due to some bugs of KS.

You need to drop the out-of-sync groovy source code.

How to?

  1. Close the project
  2. By Windows Explorer or shell command line, Delete some folders under the project root folder:
    • Libs
    • bin
    • .cache
  3. Reopen the project

and see how it goes. Hopefully this clean-up will solve your problem.