问题描述
- 我正在使用Jmeter3.1进行API测试。 [初级测试人员和新手]
- 我有一个测试,我必须迭代地发送xml请求。 每次迭代时,都会在原始xml中添加一个不同的xml块。 接收系统将进一步评估该xml块,并将值存储在DB中。这将以Hash-256的形式存储在db表中。 现在我需要:
[A]-首先为每个请求为此xml块计算Hash256。[*请参阅图像中突出显示的黄色部分
[B]-然后使用jdbc sampler登录到数据库之后,进行第二次比较。 [对于这一部分,我将从开发人员处获得查询。] 但是我不明白如何仅针对xml代码块而不是完整的xml计算hash-256。 请参见下面的示例- 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>
解决方法
- 我不知道什么是
HASH256
- 据我所知,您的XML格式错误,此位:
</r:FileInfo Language="nl">
应该看起来像</r:FileInfo>
无论如何,您都应该使用JSR223 PostProcessor和Groovy语言,以便能够:
- 解析先前的采样器响应
- 获取第一个
<Legal>
标签值 - 从中计算出SHA256 Hex
示例代码:
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)
演示:
更多信息:
- Apache Groovy - Processing XML
- Apache Groovy - Why and How You Should Use It
- StreamingMarkupBuilder
- DigestUtils
由于上述两点,我不能保证上面的代码能按您的预期工作,但是它应该指导您正确的方向