Forum Discussion

richie's avatar
richie
Community Hero
5 months ago
Solved

Groovy - Save off hashmapped split() values to a Property

Hey, I'm back working with ReadyAPI! and I've forgotten loads in the last 2 years....I'm going through my groovy notes and I'm struggling. I have a full URL with 2 query parms - token and value a...
  • nmrao's avatar
    5 months ago

    In this use case, there is no need even to create map, then loop thru it and put the entries in Properties test step. Can be directly added to Properties step after the first split('&').

    Here it goes the simplified further:

    def properties = context.testCase.testSteps["Properties"]
    def str = 'https://whatevs.azurewebsites.net/path?token=eyJ0eXAiOiJKV1Qi&value=123456789'
    new URL(str).query?.split('&').each {
    	properties.setPropertyValue(it.split('=').first(), it.split('=').last())
    }