如何遍历XML文件并提取特定值,并将其传递给for each控制器。

huangapple go评论116阅读模式
英文:

How to traverse through XML file and fetch a particular value and pass it on to for each controller

问题

从我的先前回复中,我得到以下的XML:

<?xml version="1.0" encoding="UTF-8"?>
-
<viewList>
-
	<view title="107cd5b450594e9ba1e2834b10ccfcb" transaction_id="307288fbcc9948f8ab6596d2a3b336a7" key_testcase="52dc4c0bcdb6413484cab16f43ef9d49" active="true" raw="true">
		<testcase id="52dc4c0bcdb6413484cab16f43ef9d49" size="530374"/>
		<testcase id="5d7e204dec034bfaa130757a98728816" size="530374"/>
		<testcase id="e165b07bea874896be6d2aa81abeac19" size="530374"/>
		<testcase id="3ac054f9bbec41f8b39f4fe236e4e358" size="530374"/>
		<testcase id="e4c48aee4aa4b588e1c263290722212" size="530374"/>
		<testcase id="389cf80bdcb4e27b7fd2cd07fd7464a" size="530374"/>
		<testcase id="17cd8be81227463e8ccbfd6b4263b872" size="530374"/>
		<testcase id="2d8b3214ae441948edfc472cb654cb" size="530374"/>
		<testcase id="610004abc53b45dbb7d075c7c02b1fae" size="530374"/>
		<testcase id="121a016bc32e43779a634b7990687312" size="530374"/>
		<testcase id="119b1fd4e4334b1a84707e2fd67667b4" size="530374"/>
		<testcase id="9253b4da50ff488081e9fd3e93da85c" size="530374"/>
		<testcase id="808c3055549c48e2a0e3a95aadd54918" size="530374"/>
	</view>
</viewList>

想要检索所有测试用例并将其传递给for each控制器。如何做?

英文:

From my previous response I am getting the following XML,

     &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    
    -
    &lt;viewList&gt;
    -
    	&lt;view title=&quot;107cd5b450594e9ba1e2834b10ccfcb&quot; transaction_id=&quot;307288fbcc9948f8ab6596d2a3b336a7&quot; key_testcase=&quot;52dc4c0bcdb6413484cab16f43ef9d49&quot; active=&quot;true&quot; raw=&quot;true&quot;&gt;
    		&lt;testcase id=&quot;52dc4c0bcdb6413484cab16f43ef9d49&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;5d7e204dec034bfaa130757a98728816&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;e165b07bea874896be6d2aa81abeac19&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;3ac054f9bbec41f8b39f4fe236e4e358&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;e4c48aee4aa4b588e1c263290722212&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;389cf80bdcb4e27b7fd2cd07fd7464a&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;17cd8be81227463e8ccbfd6b4263b872&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;2d8b3214ae441948edfc472cb654cb&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;610004abc53b45dbb7d075c7c02b1fae&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;121a016bc32e43779a634b7990687312&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;119b1fd4e4334b1a84707e2fd67667b4&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;9253b4da50ff488081e9fd3e93da85c&quot; size=&quot;530374&quot;/&gt;
    		&lt;testcase id=&quot;808c3055549c48e2a0e3a95aadd54918&quot; size=&quot;530374&quot;/&gt;
	&lt;/view&gt;
&lt;/viewList&gt;

Want to retrieve all test case it and pass it to for each controller. How to do it ?

答案1

得分: 1

你可以使用XPath Extractor来完成这个操作。

  1. 将其添加为返回上述XML的请求的子节点,并配置如下:

    如何遍历XML文件并提取特定值,并将其传递给for each控制器。

  2. 然后添加ForEach Controller,并进行如下设置:

    如何遍历XML文件并提取特定值,并将其传递给for each控制器。

  3. 就这样,XPath Extractor将获取所有测试用例的ID,ForEach Controller将迭代所有这些ID,您可以在ForEach Controller中引用当前测试用例的ID,如${testcase_id}所示:

    如何遍历XML文件并提取特定值,并将其传递给for each控制器。

更多信息:在JMeter中使用XPath Extractor

英文:

You can do it using XPath Extractor

  1. Add it as a child of the request which returns the above XML and configure as follows:

    如何遍历XML文件并提取特定值,并将其传递给for each控制器。

  2. Then add ForEach Controller and set it up like:

    如何遍历XML文件并提取特定值,并将其传递给for each控制器。

  3. That's it, the XPath Extractor will fetch all testcases ids and ForEach Controller will iterate all of them, you will be able to refer the current testcase id inside the ForEach Controller as ${testcase_id} where required:

    如何遍历XML文件并提取特定值,并将其传递给for each控制器。

More information: Using the XPath Extractor in JMeter

huangapple
  • 本文由 发表于 2023年6月29日 18:21:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76580145.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定