如何在 JMETER 中仅对一部分 xml 计算 HASH256 [英] how to calculate HASH256 on just a part of xml in JMETER
问题描述
- 我正在使用 Jmeter3.1 进行 API 测试.[我是初级测试员和新人]
- 我有一个测试,我必须在请求中迭代发送一个 xml.每次迭代都会在原始 xml 中添加不同的 xml 块.接收系统将进一步评估此 xml 块,并将值存储在 DB 中.这将以 Hash-256 的形式存储在 db 表中.现在我需要:
[A] - 首先为每个请求计算这个 xml 块的 Hash256.[*参见图片中黄色突出显示的部分]
[B]- 然后在使用 jdbc 采样器登录数据库后进行第二次比较.[对于这部分,我将从开发人员那里得到一个查询.]但我不明白如何仅为 xml 代码块而不是完整的 xml 计算 hash-256.请看下面的例子-
更多信息:
由于上述 2 点,我不能保证上面的代码会像你期望的那样工作,但它应该引导你走向正确的方向
- 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>
- I don't know what is
HASH256
- 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
这篇关于如何在 JMETER 中仅对一部分 xml 计算 HASH256的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!