0
  • I'm doing API testing using Jmeter3.1. [im junior tester and new]
  • I have a test where i have to send an xml in request iteratively. with each iteration a different xml block is added in original xml. This xml block will be further evaluated by the recieving system and values will be stored in DB. This will be stored in form of Hash-256 in db tables. Now i need to :

[A] - first calculate the Hash256 for this block of xml for each request.[*see yellow highlighted part in image]

[B]- then secondly compare it after logging into the DB using jdbc sampler. [for this part i will get a query from developers.] But i dont understand how to calculate the hash-256 for just the block of xml code and not the complete xml. please see example below- in the image- the yellow background xml block i need to convert to hash-256 and then compare with db

<?xml version="1.0" encoding="UTF-8" ?><r:Document SchemaVersion="1.0" xmlns:r="http://www.qqq.ddqn.qqqv.qe/XSD/qq9/qqSchema" Status="000">
<r:DateTime>2020-09-02T09:28:15</r:DateTime>    <r:FileInfo Language="nl"><r:cSecurityNumbers><r:Legal Type="200" Structure="A1">
            <r:Date><r:Century>20</r:Century>
                <r:Year>20</r:Year>
                <r:Month>09</r:Month>
                <r:Day>21</r:Day>
            </r:Date>
            <r:Legal>06999996</r:Legal></r:Legal><r:Legal Type="200" Structure="A1">
            <r:Date>
                <r:Century>20</r:Century>
                <r:Year>20</r:Year>
                <r:Month>12</r:Month>
                <r:Day>1</r:Day>
            </r:Date>
            <r:Legal>06999996</r:Legal></r:Legal><r:Legal Type="200" Structure="A1">
            <r:Date>
                <r:Century>20</r:Century>
                <r:Year>20</r:Year>
                <r:Month>11</r:Month>
                <r:Day>3</r:Day>
            </r:Date>
            <r:Legal>06999996</r:Legal></r:Legal></r:cSecurityNumbers></r:FileInfo Language="nl"></r:Document>

1 Answers1

0
  1. I don't know what is HASH256
  2. As far as I can see your XML is malformed, this bit: </r:FileInfo Language="nl"> should look like </r:FileInfo>

In any case you should be looking at JSR223 PostProcessor and Groovy language so you would be able to:

  • Parse previous sampler response
  • Fetch first <Legal> tag value
  • Calculate SHA256 Hex out of it

Example code:

def data = new groovy.xml.XmlSlurper().parseText(prev.getResponseDataAsString())
def firstLegal = new groovy.xml.StreamingMarkupBuilder().bindNode(data.FileInfo.cSecurityNumbers.'*'[0]) as String
def hash256 = org.apache.commons.codec.digest.DigestUtils.sha256Hex(firstLegal) 

Demo:

enter image description here

More information:

I cannot guarantee the above code will work as you expect due to the aforementioned 2 points, but it should guide you to the proper direction

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • 1. I have to use REQUEST not RESPONSE. – TesterRicky Sep 24 '20 at 12:41
  • 1. I have to use REQUEST not RESPONSE. your solution is for response! 2. I checked with developer over the xml point you mentioned he says its ok and its in use for 10 years now. 3 for hash 256 conversionyou can see this article- https://www.programmersought.com/article/67175301675/ – TesterRicky Sep 24 '20 at 12:47
  • If you have to use REQUEST than change `prev.getResponseDataAsString()` to `sampler.getArguments().getArgument(0).getValue()`. If your DEVELOPER considers this XML as VALID then GOOD LUCK to both of YOU. The article YOU referenced doesn't contain ANY information about HASH256. – Dmitri T Sep 24 '20 at 13:21
  • 1. i will try this. 2. i raised a bug for xml. 3. these two links may be usefull - https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.hashalgorithm.computehash?view=netcore-3.1 and https://hash.online-convert.com/sha256-generator – TesterRicky Sep 24 '20 at 13:30
  • Its not working as expected. I have tried the code "sampler.getArguments().getArgument(0).getValue()". Im getting exactly same hash as in your image. But your image is for Response. it is not the same when i paste the xml block in online converter. 20 20 09 21 06999996 HEX: B8A575A3E198437B54EFEBB626BC69BA241C0F865EFD612C3AABC1B0BBCC9411 hash.online-convert.com/sha256-generator – TesterRicky Sep 25 '20 at 08:44