关于项目自动化测试架构的改良计划 - 对于内容文件动作指令信息

简介:

我们分为3个方法依次对于<add_elements>,<update_elements>,<remove_elements>进行解析:


对于<add_elements>内部遍历解析的代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* add the new information which configured in original xml and finally generate the new xml
*/
publicstaticString addElementToXML(String xmlString ,XMLModifyInfoExtractor extractor,String originalFilePath) throwsException{
Document doc =  null ;
doc = DocumentHelper.parseText(xmlString);
extractor.extractModifyInfo(originalFilePath);
//All the add information are provided by XMLModifyInfoExtractor
List<AddElement>  addElementInfoList = extractor.getAddElementInfoList();
List<Node> nodes ;
for (AddElement addElement : addElementInfoList){
String testcaseXPath =addElement.getTestcaseXPath();
String path =addElement.getPath();
String value=addElement.getValue();
//make the value as a Element block
Element newElementSnippet = DocumentHelper.parseText(value).getRootElement();         
nodes = doc.selectNodes(path);
for (Node node :nodes){
//if in the node is in matching testcase ,then remove it
String nodeUniquePath = node.getUniquePath();
if (nodeUniquePath.indexOf(testcaseXPath) !=- 1 ){
//node.getParent().remove(node);
//node.setText(value);
Element addingPointElement = (Element) node;
addingPointElement.add(newElementSnippet);
}
}
}
returndoc.asXML();
}


对于<update_elements>内部元素进行遍历的代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* update the information which configured in original xml and finally generate the new xml
*/
publicstaticString updateElementFromXML(String xmlString ,XMLModifyInfoExtractor extractor,String originalFilePath) throwsException{
Document doc =  null ;
doc = DocumentHelper.parseText(xmlString);
extractor.extractModifyInfo(originalFilePath);
//All the update information are provided by XMLModifyInfoExtractor
List<UpdateElement>  updateElementInfoList = extractor.getUpdateElementInfoList();
List<Node> nodes ;
for (UpdateElement updateElement : updateElementInfoList){
String testcaseXPath =updateElement.getTestcaseXPath();
String path =updateElement.getPath();
String value=updateElement.getValue();
nodes = doc.selectNodes(path);
for (Node node :nodes){
//if in the node is in matching testcase ,then remove it
String nodeUniquePath = node.getUniquePath();
if (nodeUniquePath.indexOf(testcaseXPath) !=- 1 ){
node.setText(value);
}
}
}
returndoc.asXML();
}


对于<remove_elements>中元素进行遍历解析的代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* remove the information which configured in original xml and finally generate the new xml
*/
publicstaticString removeElementFromXML(String xmlString ,XMLModifyInfoExtractor extractor,String originalFilePath) throwsException{
Document doc =  null ;
doc = DocumentHelper.parseText(xmlString);
extractor.extractModifyInfo(originalFilePath);
//All the remove information are provided by XMLModifyInfoExtractor
List<RemoveElement>  removeElementInfoList = extractor.getRemoveElementInfoList();
List<Node> nodes ;
for (RemoveElement removeElement : removeElementInfoList){
String testcaseXPath =removeElement.getTestcaseXPath();
String path =removeElement.getPath();
nodes = doc.selectNodes(path);
for (Node node :nodes){
//if in the node is in matching testcase ,then remove it
String nodeUniquePath = node.getUniquePath();
if (nodeUniquePath.indexOf(testcaseXPath) !=- 1 ){
node.getParent().remove(node);
}
}
}
returndoc.asXML();
}



最后,当执行3步骤动作系列转化之后,最终的xml文件就是包含最终的我们修改后的结果了。






本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1221752,如需转载请自行联系原作者
目录
相关文章
|
5月前
|
Java 测试技术 数据安全/隐私保护
通过yaml文件配置自动化测试程序
通过yaml文件可以将自动化测试环境,测试数据和测试行为分开,请看一下案例
181 4
|
7月前
HI1105定频测试指令
HI1105模块在无线图传,特别是远距离无线图传领域有广泛应用,产品认证过程需要牵涉到定频测试,分享以下步骤参考! 主要牵涉到:11a测试、11n(H20)测试、11n(H40)测试、802.11ac 20测试、802.11ac 40测试、802.11ax 20测试、802.11ax 40M测试:
|
算法 数据安全/隐私保护 计算机视觉
基于FPGA的图像双线性插值算法verilog实现,包括tb测试文件和MATLAB辅助验证
本项目展示了256×256图像通过双线性插值放大至512×512的效果,无水印展示。使用Matlab 2022a和Vivado 2019.2开发,提供完整代码及详细中文注释、操作视频。核心程序实现图像缩放,并在Matlab中验证效果。双线性插值算法通过FPGA高效实现图像缩放,确保质量。
|
10月前
|
安全 关系型数据库 MySQL
MySQL8使用物理文件恢复MyISAM表测试
MySQL8使用物理文件恢复MyISAM表测试
234 0
|
运维
【运维基础知识】用dos批处理批量替换文件中的某个字符串(本地单元测试通过,部分功能有待优化,欢迎指正)
该脚本用于将C盘test目录下所有以t开头的txt文件中的字符串“123”批量替换为“abc”。通过创建批处理文件并运行,可实现自动化文本替换,适合初学者学习批处理脚本的基础操作与逻辑控制。
1089 56
|
Serverless 决策智能 UED
构建全天候自动化智能导购助手:从部署者的视角审视Multi-Agent架构解决方案
在构建基于多代理系统(Multi-Agent System, MAS)的智能导购助手过程中,作为部署者,我体验到了从初步接触到深入理解再到实际应用的一系列步骤。整个部署过程得到了充分的引导和支持,文档详尽全面,使得部署顺利完成,未遇到明显的报错或异常情况。尽管初次尝试时对某些复杂配置环节需反复确认,但整体流程顺畅。
273 3
|
运维 监控 安全
自动化运维的利剑:Ansible在现代IT架构中的应用
在数字化浪潮中,企业对IT系统的敏捷性和可靠性要求日益提高。Ansible,一种简单但强大的自动化运维工具,正成为现代IT架构中不可或缺的一部分。它通过声明式编程语言YAM,简化了系统配置、应用部署和任务自动化的过程,显著提升了运维效率和准确性。本文将深入探讨Ansible的核心特性、应用场景以及如何有效整合进现有IT环境,为读者揭示其在自动化运维中的实用价值和未来发展潜力。
|
存储 人工智能 编译器
【AI系统】CPU 指令集架构
本文介绍了指令集架构(ISA)的基本概念,探讨了CISC与RISC两种主要的指令集架构设计思路,分析了它们的优缺点及应用场景。文章还简述了ISA的历史发展,包括x86、ARM、MIPS、Alpha和RISC-V等常见架构的特点。最后,文章讨论了CPU的并行处理架构,如SISD、SIMD、MISD、MIMD和SIMT,并概述了这些架构在服务器、PC及嵌入式领域的应用情况。
1354 5
|
运维 Devops 应用服务中间件
自动化运维的利剑:Ansible在现代IT架构中的应用
【10月更文挑战第42天】本文旨在揭示自动化运维工具Ansible如何革新现代IT架构,通过简化配置管理和部署流程,提升效率和可靠性。我们将探索Ansible的核心功能、语言特性以及其在DevOps文化中的角色。文章还将展示如何借助Ansible构建模块化和可重用的配置代码,实现快速迭代与部署,并确保系统一致性。通过阅读本文,运维人员将了解如何利用Ansible优化日常任务,加速产品上线速度,同时提高系统的稳健性。
293 5