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

简介:

我们分为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,如需转载请自行联系原作者
目录
相关文章
|
前端开发 测试技术 API
测试金字塔:别再只盯着UI自动化了
测试金字塔:别再只盯着UI自动化了
1022 116
|
敏捷开发 测试技术 API
测试金字塔:构建高效自动化测试策略的基石
测试金字塔:构建高效自动化测试策略的基石
1011 116
|
人工智能 自然语言处理 测试技术
从人工到AI驱动:天猫测试全流程自动化变革实践
天猫技术质量团队探索AI在测试全流程的落地应用,覆盖需求解析、用例生成、数据构造、执行验证等核心环节。通过AI+自然语言驱动,实现测试自动化、可溯化与可管理化,在用例生成、数据构造和执行校验中显著提效,推动测试体系从人工迈向AI全流程自动化,提升效率40%以上,用例覆盖超70%,并构建行业级知识资产沉淀平台。
从人工到AI驱动:天猫测试全流程自动化变革实践
|
人工智能 自然语言处理 JavaScript
利用MCP Server革新软件测试:更智能、更高效的自动化
MCP Server革新软件测试:通过标准化协议让AI实时感知页面结构,实现自然语言驱动、自适应维护的自动化测试,大幅提升效率,降低脚本开发与维护成本,推动测试左移与持续测试落地。
|
测试技术 API 数据库
测试金字塔:构建高效自动化测试策略的基石
测试金字塔:构建高效自动化测试策略的基石
968 114
|
存储 人工智能 算法
AI测试平台实战:深入解析自动化评分和多模型对比评测
在AI技术迅猛发展的今天,测试工程师面临着如何高效评估大模型性能的全新挑战。本文将深入探讨AI测试平台中自动化评分与多模型对比评测的关键技术与实践方法,为测试工程师提供可落地的解决方案。
|
JSON JavaScript 测试技术
用Postman玩转电商API:一键测试+自动化请求教程
Postman 是电商 API 测试的高效工具,涵盖基础配置、自动化测试、环境管理与请求自动化,助你快速提升开发效率。
|
Java 测试技术 数据安全/隐私保护
通过yaml文件配置自动化测试程序
通过yaml文件可以将自动化测试环境,测试数据和测试行为分开,请看一下案例
568 4
|
算法 数据安全/隐私保护 计算机视觉
基于FPGA的图像双线性插值算法verilog实现,包括tb测试文件和MATLAB辅助验证
本项目展示了256×256图像通过双线性插值放大至512×512的效果,无水印展示。使用Matlab 2022a和Vivado 2019.2开发,提供完整代码及详细中文注释、操作视频。核心程序实现图像缩放,并在Matlab中验证效果。双线性插值算法通过FPGA高效实现图像缩放,确保质量。
|
jenkins 测试技术 Shell
利用Apipost轻松实现用户充值系统的API自动化测试
API在现代软件开发中扮演着连接不同系统与模块的关键角色,其测试的重要性日益凸显。传统API测试面临效率低、覆盖率不足及难以融入自动化工作流等问题。Apipost提供了一站式API自动化测试解决方案,支持零代码拖拽编排、全场景覆盖,并可无缝集成CI/CD流程。通过可视化界面,研发与测试人员可基于同一数据源协作,大幅提升效率。同时,Apipost支持动态数据提取、性能压测等功能,满足复杂测试需求。文档还以用户充值系统为例,详细介绍了从创建测试用例到生成报告的全流程,帮助用户快速上手并提升测试质量。
1568 18