Last active
August 29, 2015 14:07
-
-
Save anandsunderraman/42785f1e1be0cd7dcc15 to your computer and use it in GitHub Desktop.
iterate thru test steps and add header to each of them
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonSlurper; | |
import com.eviware.soapui.support.types.StringToStringMap; | |
//get the response from the test step that makes the call to get the authentication token | |
def authResponse = testRunner.testCase.getTestStepByName("GetToken").getPropertyValue("response"); | |
//parse the json response | |
def authResponseJSON = new JsonSlurper().parseText(authResponse); | |
//access the access_token property in the respose | |
def oauthToken = authResponseJSON.access_token; | |
//create a new empty map for headers | |
def headers = new StringToStringMap(); | |
//create a key value pair in the headers mao | |
headers.put("OAuth-Token", oauthToken); | |
//obtain the list of test steps | |
def steps = context.testCase.getTestStepList(); | |
//iterate thru each of the test steps and set the oauth token to each of the steps | |
steps.each{ | |
// This block will loop through the test steps and set headers for each of them | |
if (it.name != 'GetToken' && it.name != 'TransferOauthToken') | |
it.testRequest.setRequestHeaders(headers); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment