首页 文章 精选 留言 我的

精选列表

搜索[项目自动化构建工具],共10000篇文章
优秀的个人博客,低调大师

关于项目自动化测试架构的改良计划 - XML格式转为json格式

因为讨论下来,最终的DataProvider格式需要是一个json格式,所以我们还必须提供方法吧xml格式转为json格式,现在很多框架比如json-lib框架能很轻易的完成这个任务了。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /** * This class will read the xml file and then change it to a json object *@author cwang58 *@created date: Jun 9, 2013 */ public class XMLJSONConverter { /** * This method will convert the xml to json object * @param xml the xml string * @return the json string */ public static String xml2JSON(String xml){ XMLSerializer xmlSerializer = new XMLSerializer(); JSON json = xmlSerializer.read(xml); return json.toString(); } .. } 就几行代码,很容易读懂。 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1221759,如需转载请自行联系原作者

优秀的个人博客,低调大师

关于项目自动化测试架构的改良计划 - 分离出动作指令信息

但是,我们这些动作指令信息毕竟是让测试用例数据的设计者告诉Engine怎样修改原始数据集合的,所以我们必须把这些信息分离出来,但是刚才一步骤,已经把这些片断移除了,那么怎么把这些信息拿到呢?很简单,不是我们有原始数据么,所以我们就可以对于原始数据的xml字符串,一个testcase,一个testcase的吧这些动作指令解析出来并且存放在相应的Value Object 列表中,以后我们只要根据这些列表中提供的信息就可以正确的对于原来的数据集合进行操作了。 分离信息的类叫XMLModifyInfoExtractor,它负责分离动作: 代码如下: 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 /** * extract all the modification information and store to member fields. * @param filePath * @throws Exception */ public void extractModifyInfo(String filePath) throws Exception{ SAXReader reader = new SAXReader(); Document document = reader.read( new File(filePath)); Element rootElement = document.getRootElement(); String testcaseElementPathValue; Element addElements; Element addElementPath; String addElementPathValue; Element addElementValue; String addElementValueValue; Element updateElements; Element updateElementPath; String updateElementPathValue; Element updateElementValue; String updateElementValueValue; Element removeElements; Element removeElementPath; String removeElementPathValue; //first ,get all the <test_case> element List<Element> testcaseElementList = rootElement.elements( "test_case" ); for (Element testcaseElement : testcaseElementList){ testcaseElementPathValue = testcaseElement.getUniquePath(); //get <add_elements> part from the <test_case> addElements= testcaseElement.element( "add_elements" ); if (addElements!= null ){ //traverse the <add_elements> to get a seris of <add_element> List<Element> addElementList = addElements.elements( "add_element" ); for (Element addElement : addElementList){ //extract the <path> information from <add_element> addElementPath = addElement.element( "path" ); addElementPathValue = addElementPath.getTextTrim(); //extract the <value> information from <add_element> addElementValue = addElement.element( "value" ); String xmlValue=addElementValue.asXML(); //remove the <value> and </value> part from this xml addElementValueValue=xmlValue.replace( "<value>" , "" ).replace( "</value>" , "" ); addElementInfoList.add ( new AddElement(testcaseElementPathValue,addElementPathValue,addElementValueValue)); } } //get <update_elements> part from the <test_case> updateElements= testcaseElement.element( "update_elements" ); if (updateElements!= null ){ //traverse the <update_elements> to get a seris of <update_element> List<Element> updateElementList = updateElements.elements( "update_element" ); for (Element updateElement : updateElementList){ //extract the <path> information from <update_element> updateElementPath = updateElement.element( "path" ); updateElementPathValue = updateElementPath.getTextTrim(); //extract the <value> information from <update_element> updateElementValue = updateElement.element( "value" ); updateElementValueValue=updateElementValue.getTextTrim(); updateElementInfoList.add ( new UpdateElement(testcaseElementPathValue,updateElementPathValue,updateElementValueValue)); } } //get <remove_elements> part from the <test_case> removeElements= testcaseElement.element( "remove_elements" ); if (removeElements != null ){ //traverse the <remove_elements> to get a seris of <remove_element> List<Element> removeElementList = removeElements.elements( "remove_element" ); for (Element removeElement : removeElementList){ //extract the <path> information from <remove_element> removeElementPath = removeElement.element( "path" ); removeElementPathValue = removeElementPath.getTextTrim(); removeElementInfoList.add( new RemoveElement(testcaseElementPathValue,removeElementPathValue)); } } } } 现在经过上述3步骤之后,我们的代码中所有的动作序列的执行内容都被存放在相应变量中了。 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1221749,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册