Check for string in the list

Hi, I want to check if a specific text appears in a value of the site headers.
I came up with something like this:



ArticleUrl = "$GlobalVariable.URL/node/12345"


response = WS.sendRequestAndVerify(findTestObject('API/Production/Get headers'))

Map<String, List> headerFields = response.getHeaderFields()


def thingy = "HIT"


Output of getHeaders looks a bit like this :

[Permissions-Policy:[interest-cohort=()], Server-Timing:[HIT, test;desc="Edge time";dur=1, HIT-CLUSTER, test;desc="Edge time";dur=2]

And I need to check if I there is a β€˜HIT’ value in the Server-timing.
With the current code Im getting error

No signature of method: java.util.HashMap.contains() is applicable for argument types: (java.lang.String) values: [HIT]
Possible solutions: containsKey(java.lang.Object), containsKey(java.lang.Object), toString(), toString(), toString(), toString()

Thanks for any tips

This stringified headerField is terriblly difficult to understand.

You should convert the headerFields variable into a JSON string, and print it in a pretty-print format.
Then you would see the data structure more cleary, and you would get better idea how to manipulate it.

You can convert any type of variable values into JSON by the GSON library, which is built-in Katlaon.

1 Like