api - 如何在 Karate 中复制节点及其子节点

标签 api testing cucumber karate

您好,我正在尝试替换结构第二层中的一个节点,例如下面的“两个”节点(我想复制该节点及其子节点)

<root>
   <first>1</first>
   <second>
      <one>1</one>
      <two>
         <a>a</a>
         <b>b</b>
         <c>c</c>
      </two>
      <three>c</three>
   </second>
   <third>3</third>
</root>

所以它最终看起来像这样:

<root>
   <first>1</first>
   <second>
      <one>1</one>
      <two>
         <a>a</a>
         <b>b</b>
         <c>c</c>
      </two>
      <two>
         <a>a</a>
         <b>b</b>
         <c>c</c>
      </two>
      <three>c</three>
   </second>
   <third>3</third>
</root>

这在 Karate 中可以做到吗?

非常感谢

最佳答案

通常我不推荐“太聪明”的测试 - 每个 Scenario 都应该专注于一个“静态”有效负载 - 稍后当你尝试阅读你的测试时你会感谢自己。

还要确保您查看了这组“模板化”想法的示例:xml.feature

但不管怎样,给你:

* def root =
"""
<root>
   <first>1</first>
   <second>
      <one>1</one>
      <two>
         <a>a</a>
         <b>b</b>
         <c>c</c>
      </two>
      <three>c</three>
   </second>
   <third>3</third>
</root>
"""
* xmlstring two = $root/root/second/two
* replace root.<three>c</three> = two + '<three>c</three>'
* xml root = root
* print root

关于api - 如何在 Karate 中复制节点及其子节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59259687/

相关文章:

java - CLI runner cucumber.api.cli.Main 找不到步骤定义

java - 在 Cucumber java 的特定步骤中访问 Cucumber 中的场景对象

java - Cucumber StepDef ResultActions NullPointerException

api - Powershell Invoke-RestMethod

java - 如何使用结果集从mysql中获取char数据类型

api - 使用字节流和 Dropbox API 损坏 docx 文件

testing - 多个发布同时进行时如何处理自动化脚本

django - 在测试中使用 Django 缓存强制连接错误

unit-testing - uC/OS 的单元测试 - II

php - 如何通过 Magento API 创建可下载的产品?