Forum Discussion

7V's avatar
7V
Occasional Contributor
7 years ago

Using context parameter in Request Authorization

Hi,   I am currently building a Test Case in which I use scripts to parse the response body of a few REST API Call Test Steps. 1. I create a user: POST /user/signup. 2. I log in with the created ...
  • 7V's avatar
    7 years ago

    This case is now resolved. I created a Properties Test Step named "StepProperties" as the first step.

     

    I now stock my variables in the step properties thanks to the following script:

    import groovy.json.JsonSlurper
    responseContent = testRunner.testCase.getTestStepByName("POST User Login").getPropertyValue("response")
    jsonParser = new JsonSlurper().parseText(responseContent)
    testRunner.testCase.getTestStepByName("StepProperties").setPropertyValue("JWT",jsonParser.token)

    Then I pass as a header parameter the following properties In the following calls:

     

    At the end of the test case I run a TearDown Script that erases every properties created in StepProperties during that run:

    data = context.testCase.getTestStepByName("StepProperties");
    String[] propToRemove = new String[data.getPropertyCount()];
    propToRemove = data.getPropertyNames();
    
    if(propToRemove.size()==0){
    		log.info("No properties to remove.")
    	}else{
    	log.info("Removing properties...")
    	for ( int i = 0 ; i < propToRemove.size(); i++ ){
        		data.removeProperty( propToRemove[i] ); 
    	}
    	log.info("Properties removed.")
    }

     

    This documentation helped me understand how to access different hierarchy of properties in SoapUI: https://groovyinsoapui.wordpress.com/tag/teststep-level-property-access/

     

    Bye !