Karate API Converting String from JSON Response into UPPERCASE

Viewed 499

JSON Response has __typename in the response. I am defining and storing it so I can use this in the next graphQL Request

  • def contentType1 = response.data.getPublicList.items[0].__typename

__typename comes back as "Movie"

The next Request requires "Movie" to be "MOVIE" query { getContentById(id: "", contentType: "MOVIE") {

Is there a way I can convert/define the entire string value as UPPERCASE?

1 Answers

That should be easy, behind the scenes it is a "Java" string, so there are methods you can use:

* def contentType1 = 'Movie'
* def after = contentType1.toUpperCase()
* match after == 'MOVIE'

EDIT: If you want to convert "in place", just do JS-style operations:

* def data = { foo: 'bar' }
* data.foo = data.foo.toUpperCase()
* match data == { foo: 'BAR' }

If you need more sophistication, please look at the docs for JSON transforms: https://github.com/karatelabs/karate#json-transforms

Related