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

简介:

我们分为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,如需转载请自行联系原作者
目录
相关文章
|
15天前
|
前端开发 JavaScript 测试技术
android做中大型项目完美的架构模式是什么?是MVVM吗?如果不是,是什么?
android做中大型项目完美的架构模式是什么?是MVVM吗?如果不是,是什么?
51 2
|
8天前
|
运维
【运维基础知识】用dos批处理批量替换文件中的某个字符串(本地单元测试通过,部分功能有待优化,欢迎指正)
该脚本用于将C盘test目录下所有以t开头的txt文件中的字符串“123”批量替换为“abc”。通过创建批处理文件并运行,可实现自动化文本替换,适合初学者学习批处理脚本的基础操作与逻辑控制。
103 56
|
9天前
|
测试技术
自动化测试项目学习笔记(五):Pytest结合allure生成测试报告以及重构项目
本文介绍了如何使用Pytest和Allure生成自动化测试报告。通过安装allure-pytest和配置环境,可以生成包含用例描述、步骤、等级等详细信息的美观报告。文章还提供了代码示例和运行指南,以及重构项目时的注意事项。
40 1
自动化测试项目学习笔记(五):Pytest结合allure生成测试报告以及重构项目
|
9天前
|
测试技术 Python
自动化测试项目学习笔记(四):Pytest介绍和使用
本文是关于自动化测试框架Pytest的介绍和使用。Pytest是一个功能丰富的Python测试工具,支持参数化、多种测试类型,并拥有众多第三方插件。文章讲解了Pytest的编写规则、命令行参数、执行测试、参数化处理以及如何使用fixture实现测试用例间的调用。此外,还提供了pytest.ini配置文件示例。
14 2
|
9天前
|
测试技术 Python
自动化测试项目学习笔记(二):学习各种setup、tearDown、断言方法
本文主要介绍了自动化测试中setup、teardown、断言方法的使用,以及unittest框架中setUp、tearDown、setUpClass和tearDownClass的区别和应用。
22 0
自动化测试项目学习笔记(二):学习各种setup、tearDown、断言方法
|
14天前
|
存储 分布式计算 Hadoop
Hadoop-33 HBase 初识简介 项目简介 整体架构 HMaster HRegionServer Region
Hadoop-33 HBase 初识简介 项目简介 整体架构 HMaster HRegionServer Region
34 2
|
14天前
|
存储 数据采集 分布式计算
Hadoop-17 Flume 介绍与环境配置 实机云服务器测试 分布式日志信息收集 海量数据 实时采集引擎 Source Channel Sink 串行复制负载均衡
Hadoop-17 Flume 介绍与环境配置 实机云服务器测试 分布式日志信息收集 海量数据 实时采集引擎 Source Channel Sink 串行复制负载均衡
32 1
|
8天前
|
前端开发 JavaScript 测试技术
Kotlin教程笔记 - 适合构建中大型项目的架构模式全面对比
Kotlin教程笔记 - 适合构建中大型项目的架构模式全面对比
19 0
|
8天前
|
存储 消息中间件 前端开发
.NET常见的几种项目架构模式,你知道几种?
.NET常见的几种项目架构模式,你知道几种?
|
19天前
|
机器学习/深度学习 人工智能 运维
构建高效运维体系:从自动化到智能化的演进
本文探讨了如何通过自动化和智能化手段,提升IT运维效率与质量。首先介绍了自动化在简化操作、减少错误中的作用;然后阐述了智能化技术如AI在预测故障、优化资源中的应用;最后讨论了如何构建一个既自动化又智能的运维体系,以实现高效、稳定和安全的IT环境。
46 4