We are using soapui to test API, currently we have some testcases. I have created new test suit, in this test suite we have more than 120test cases, I need to add additional header in that, please suggest code snippet how can add additional header in this?
Asked
Active
Viewed 75 times
1 Answers
0
you really ought to try something then ask for help, it's the best way to learn.
However, this is not very straightforward. The following snippet will help you I guess, but you'll have to adapt it to your needs.
testRunner.testCase.testSuite.project.testSuiteList.each
{
suite ->
name = suite.getName()
suite.testCaseList.each{
TC ->
// parse each Test Case
TC.testStepList.each{
TS ->
// parse each Test Step
if (TS.config.type == "restrequest")
{
// only on REST request type steps
// check its headers
headers = TS.getHttpRequest().getRequestHeaders()
//log.info "headers = " + headers
refHeaderName = "Accept" // search Accept header
found = false
headers.find(){
hd ->
//log.info "header name = ${hd.key}, value = ${hd.value}"
if(hd.key == refHeaderName)
{
found = true
}
}
if (found == false)
{
log.info "testSuite $name - testCase ${TC.getName()} - testStep ${TS.getName()}"
// le header n'existe pas, on le cree
headers.put("Accept", "application/json")
//log.info "add a new header : " + headers
TS.testRequest.setRequestHeaders(headers)
}
}
} // TS each
} // TC
} // TSuite each
This is what I've done in my project, I use REST requests ...
good luck
Alexandre

A.Joly
- 2,317
- 2
- 20
- 25