QTP中读写xml的组件

来源:互联网 发布:数据结构与算法 pdf 编辑:程序博客网 时间:2024/05/11 16:19

QTP中读写xml可以使用其自带的组件,下面是简单的使用脚本。

''''''The class use to write data for test result report ''''===========Demo to use this class====================='Dim xmlobj'Set xmlobj = new XML'xmlobj.init'xmlobj.add_case 1'xmlobj.add_content 1'xmlobj.add_casename "casename"'xmlobj.add_pagename "pagename"'xmlobj.save "D:\test.xml"''''======================================================Class XMLDim oXML, root, currentcase, currentheader, currentcontentFunction init(file_name)'创建xml保留对象组件set oXML = XMLUtil.CreateXML '新建一个documentSet fso = CreateObject("Scripting.FileSystemObject")If fso.FileExists(file_name) ThenoXML.LoadFile file_name          ''''文件存在则读取文件elseoXML.CreateDocument "prodtest"   ''''文件不存在则创建根节点End If'获取root根元素set root = oXML.GetRootElement        ''''获取根元素End FunctionFunction add_case()                          '添加一个空的子节点caseroot.AddChildElementByName "case",""int_case_index = root.ChildElements.CountSet currentcase = root.ChildElements.Item(int_case_index)add_header()End FunctionFunction add_header()currentcase.AddChildElementByName "header",""Set currentheader = currentcase.ChildElements.ItemByName("header")End FunctionFunction add_content()currentcase.AddChildElementByName "content",""int_content_index = currentcase.ChildElements.AllItemsByName("content").CountSet currentcontent = currentcase.ChildElements.ItemByName("content", int_content_index)End FunctionFunction add_casename(casename)currentheader.AddChildElementByName "testcase", casename    '''''添加带指定内容的子节点End FunctionFunction add_starttime(starttime)currentheader.AddChildElementByName "starttime", starttimeEnd FunctionFunction add_endtime(endtime)currentheader.AddChildElementByName "endtime", endtimeEnd FunctionFunction add_passcount(passcount)currentheader.AddChildElementByName "passcount", passcountEnd FunctionFunction add_failcount(failcount)currentheader.AddChildElementByName "failcount", failcountEnd FunctionFunction add_donecount(donecount)currentheader.AddChildElementByName "donecount", donecountEnd FunctionFunction add_pagename(page)currentcontent.AddChildElementByName "page", pageEnd FunctionFunction add_url(url)currentcontent.AddChildElementByName "url", urlEnd FunctionFunction add_element(element)currentcontent.AddChildElementByName "element", elementEnd FunctionFunction add_function(function_name)currentcontent.AddChildElementByName "function", function_nameEnd FunctionFunction add_reason(reason)currentcontent.AddChildElementByName "reason", reasonEnd FunctionFunction add_detail(detail)currentcontent.AddChildElementByName "detail", detailEnd FunctionFunction add_screen(screen_file)currentcontent.AddChildElementByName "screenshot", "img\"+screen_fileEnd FunctionFunction add_index(int_index)currentcontent.AddChildElementByName "index", int_indexEnd FunctionFunction save(file_name)   '保存文件oXML.SaveFile file_name     ''''保存文件'释放对象Set root = nothingSet oXML = nothingEnd FunctionEnd Class
当然你也可以使用vbs支持的xml组件来读写。比如:Microsoft.XMLDOM。更多关于XMLUtil对象的使用方法请查阅QTP自带帮助文档(Utility.chm)

原创粉丝点击