how to calculate HASH256 on just a part of xml in JMETER

后端 未结 1 1923
名媛妹妹
名媛妹妹 2021-01-27 13:33
  • 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 differe
相关标签:
1条回答
  • 2021-01-27 14:24
    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:

    More information:

    • Apache Groovy - Processing XML
    • Apache Groovy - Why and How You Should Use It
    • StreamingMarkupBuilder
    • DigestUtils

    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

    0 讨论(0)
提交回复
热议问题