jdario
7 years agoOccasional Contributor
Reading SOAP Request Attachment using Groovy
Hello,
I have a SOAP request with an attachment. I'm trying to read the attachment, generate it's SHA-256 hash, and put the value in the request before sending. I've found various snippets of ...
- 6 years ago
I figured it out. Let me first state what I wanted to do.
I wanted to get the SHA-256 value from the cached attachment in my SOAP Request and then place that value in the SOAP Request as a property. If the attachment changes it doesnt matter because the test will generate a new hash value from it.
To do this:
1. I created a Groovy Script test step to go get the attachment, generate the SHA-256 value and return it.
import java.security.MessageDigest import java.math.BigInteger def attachment = testRunner.testCase.testSteps['SOAP_Request'].httpRequest.getAttachmentAt(0).data String sha256 = org.apache.commons.codec.digest.DigestUtils.sha256Hex(attachment); assert sha256 return sha256 log.info(sha256)
2. I created a Property Transfer test step to move the "result" property value to a property I created at the Test Case level.
3. I then reference the custom Test Case property in my SOAP Request by using ${#TestCase#sha256} (where sha256 is the name I gave the custom proerty) in the corresponding XML element.