Ask a Question

Add test step name and project name to header SOAP test

SOLVED
Raven25
New Contributor

Add test step name and project name to header SOAP test

Hi!

 

I'm pretty new to testing so still figuring everything out the best I can 😀

 

I was wondering is someone could help me out with the following dilemma:

To make my life a bit easier, I want to add the name of the teststep (and possibly the project name as well) to the header of a SOAP request (and response).

How can I make that happen? I've been experimenting with Event handlers and have tried the following (of which I'm quite sure is totally wrong 😅)

Event handlers.png

 

Can someone point me in the right direction? Thanks in advance!! 😊

5 REPLIES 5
KarelHusa
Super Contributor

Hi @Raven25,

The approach you have chosen definitely makes sense.

 

To modify the test step headers, you should use TestRunListener.beforeStep. Also, you will be able to use the testStep variable. You can look at the following script and accommodate it for your needs.

 

import com.eviware.soapui.support.types.StringToStringMap 
import com.eviware.soapui.impl.support.http.HttpRequestTestStep

if (testStep instanceof HttpRequestTestStep) {
testRequest = testStep.testRequest

// Create new headers map
def headers = new StringToStringMap()
// Copy existing headers
testRequest.requestHeaders.each { headers.put(it.key, it.value[0])}
// Add TestStep Name
headers.putIfAbsent("x-Testing-TestStep", testStep.getName())

testRequest.setRequestHeaders(headers)
}

 

Best regards,

Karel

 

Karel@apimate.eu
https://apimate.eu

Hi Karel,

I tried (copy paste of your code) this and got the following ClassCastException:

Caused by: java.lang.ClassCastException: class java.util.ArrayList cannot be cast to class java.lang.String (java.util.ArrayList and java.lang.String are in module java.base of loader 'bootstrap')
at com.eviware.soapui.support.types.StringToStringsMap.<init>(StringToStringsMap.java:55)
at com.eviware.soapui.impl.support.AbstractHttpRequest.setRequestHeaders(AbstractHttpRequest.java:514)

 

Any ideas ?

 

Kind regards, Heymen

Hi @hnicolaij,@Raven25,

I have fixed the script; see above.

 

Karel@apimate.eu
https://apimate.eu

Thanks, Karel, for your solution! (Excuse my late response; I was enjoying my holiday)


Is it also possible to use that same script for adding the Project name to the header?

KarelHusa
Super Contributor

Sure, just add another header by:

 

headers.putIfAbsent(...)

 

Karel@apimate.eu
https://apimate.eu
cancel
Showing results for 
Search instead for 
Did you mean: