Groovy解析xml并且注入Project,TestSuite,TestCase级别的custom properties
import com.eviware.soapui.support.GroovyUtils
import groovy.util.XmlParser def groovyUtils = new GroovyUtils( context )
def xmlFilePath = groovyUtils.getProjectPath()+"\\Properties.xml" def testAndBmkEnv = context.expand('${#Project#testAndBmkEnv}').trim()
String testEnv = testAndBmkEnv.split("vs")[0].trim()
String bmkEnv = testAndBmkEnv.split("vs")[1].trim() //loadProperties(testEnv,bmkEnv,xmlFilePath)
//loadProperties(testEnv,bmkEnv,xmlFilePath,testSuiteName,testCaseName) //******************************All TestSuies and TestCases**********************************
// Inject custom properties in xml file to Project, all TestSuites or all TestCases.
def loadProperties(String testEnv, String bmkEnv, String xmlFilePath){
def xmlParser = new XmlParser().parse(xmlFilePath);
xmlParser.Env.each{
if (it.attribute("id")==testEnv){
setProjectProperties(it, "Test")
setTestSuiteAndTestCaseProperties(it, "Test")
}
if (it.attribute("id")==bmkEnv){
setProjectProperties(it, "Bmk")
setTestSuiteAndTestCaseProperties(it, "Bmk")
}
}
} def setProjectProperties(Object obj, String env){
obj.Project.each{
it.CusProperty.each{
String propertyName = it.attribute("name")+env
String propertyValue = it.attribute("value")
testRunner.testCase.testSuite.project.setPropertyValue(propertyName,propertyValue)
}
}
} // Set custom properties of all TestSuites and TestCases
def setTestSuiteAndTestCaseProperties(Object obj, String env){
obj.TestSuite.each{
String testSuiteName = it.attribute("name")
it.CusProperty.each{
String propertyName = it.attribute("name")+env
String propertyValue = it.attribute("value")
testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).setPropertyValue(propertyName,propertyValue)
}
it.TestCase.each{
String testCaseName = it.attribute("name")
it.CusProperty.each{
String propertyName = it.attribute("name")+env
String propertyValue = it.attribute("value")
testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).setPropertyValue(propertyName,propertyValue)
}
}
}
}
//******************************All TestSuies and All TestCases********************************** //******************************One TestSuie and One/All TestCases**********************************
// Inject custom properties in xml file to Project, one TestSuite or one TestCase.
def loadProperties(String testEnv, String bmkEnv, String xmlFilePath, String suiteName, String caseName){
def xmlParser = new XmlParser().parse(xmlFilePath);
xmlParser.Env.each{
if (it.attribute("id")==testEnv){
setProjectProperties(it, "Test")
setTestSuiteAndTestCaseProperties(it, "Test", suiteName, caseName)
}
if (it.attribute("id")==bmkEnv){
setProjectProperties(it, "Bmk")
setTestSuiteAndTestCaseProperties(it, "Bmk", suiteName, caseName)
}
}
} // Set custom properties of one TestSuite and one TestCase
def setTestSuiteAndTestCaseProperties(Object obj, String env, String suiteName, String caseName){
obj.TestSuite.each{
String testSuiteName = it.attribute("name")
if (testSuiteName==suiteName){
it.CusProperty.each{
String propertyName = it.attribute("name")+env
String propertyValue = it.attribute("value")
testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).setPropertyValue(propertyName,propertyValue)
}
if(caseName!=""){
it.TestCase.each{
String testCaseName = it.attribute("name")
if (testCaseName==caseName){
it.CusProperty.each{
String propertyName = it.attribute("name")+env
String propertyValue = it.attribute("value")
testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).setPropertyValue(propertyName,propertyValue)
}
return
}
}
}else{
it.TestCase.each{
String testCaseName = it.attribute("name")
it.CusProperty.each{
String propertyName = it.attribute("name")+env
String propertyValue = it.attribute("value")
testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).setPropertyValue(propertyName,propertyValue)
}
}
}
return
}
}
}
//******************************One TestSuie and One/All TestCases**********************************
Groovy解析xml并且注入Project,TestSuite,TestCase级别的custom properties的更多相关文章
- 移除project,testsuite,testcase级别所有的custom properties
// Remove all custom properties on Project level. If removed, custom properties cannnot be injected ...
- 在当前TestSuite/TestCase run之前先run另一个TestSuite/TestCase
在当前的TestSuite/TestCase的Setup Script里面写上这段代码: import com.eviware.soapui.model.support.PropertiesMap l ...
- SQLServer解析xml到Oracle
写了一个程序:根据状态位读取SQLserver 中的一张表,下载其中一个字段的值,这个值是XML类型的,然后把这个XML文件的内容插入到另一Oracle数据库,并更新SQLServer表的标志位,表示 ...
- Android开发学习---使用XmlPullParser解析xml文件
Android中解析XML的方式主要有三种:sax,dom和pull关于其内容可参考:http://blog.csdn.net/liuhe688/article/details/6415593 本文将 ...
- java解析xml
一.Document对象相关 1.读取XML文件,获得document对象. SAXReader reader = new SAXReader(); ...
- iOS-数据解析XML解析的多种平台介绍
在iPhone开发中,XML的解析有很多选择,iOS SDK提供了NSXMLParser和libxml2两个类库,另外还有很多第三方类库可选,例如TBXML.TouchXML.KissXML.Tiny ...
- java生成解析xml的另外两种方法Xstream
Xstream生成和解析xm和JAXB生成和解析xml的方法. 一,Xstream Xstream非jdk自带的,需要到入Xstream-1.4.3.jar和xpp3_min-1.1.4.jar 1. ...
- 解析XML文档之一:使用SAX解析
使用sax解析xml方法总结 解析的的xml文档格式如下 <?xml version="1.0" encoding = "UTF-8"?> < ...
- 01_Java解析XML
[打印list.Map集合的工具方法] /** * 打印List集合对应的元素 */ public void printList(List<Object> list){ for(Objec ...
随机推荐
- 上传文件fileupload
文件上传: 需要使用控件-fileupload 1.如何判断是否选中文件? FileUpload.FileName - 选中文件的文件名,如果长度不大于0,那么说明没选中任何文件 js - f.va ...
- mybatis入门_一对多,多对多映射以及整合spring框架
一.一对多映射. 1.1 一对多映射之根据多的一方关联查询一的一方 示例:查询出具体的订单信息,同时也查询出来订单的用户信息. 引入的订单表如下所示: 框选出来的为具体的外键. 订单的Pojo类如下所 ...
- Redis教程(三) list类型
一.概述: redis的list类型其实就是一个每个子元素都是string类型的双向链表.所以[lr]push和[lr]pop命令的算法时间复杂度都是O(1) 另外list会记录链表的长度.所以ll ...
- js this理解
原文链接:http://www.ruanyifeng.com/blog/2010/04/using_this_keyword_in_javascript.html this是js语言的几个关键字,代表 ...
- SQL Server Reporting Service(SSRS) 第四篇 SSRS 用法总结
1. 如何让表头在每页显示(译) A. 打开高级模式: 在分组栏中点击Column Goups右侧的箭头选择高级模式; B. 找到第一个Static组 在Row Groups区域中(注意不是Colu ...
- cfDNA(circulating cell free DNA)全基因组测序
参考资料: [cfDNA专题]cell-free DNA在非肿瘤疾病中的临床价值(好) ctDNA, cfDNA和CTCs有什么区别吗? cfDNA你懂多少? 新发现 | 基因是否表达,做个cfDNA ...
- ArcGIS创建tpk切片缓存
一. 背景知识 1. tpk是什么? 从地图或底图生成切片,并将切片进行打包从而创建单个压缩的 .tpk 文件.切片包(.tpk)是在地图或栅格数据集中能作为 Web 切片或 Web 高程图层发布的一 ...
- js中Json 对象,Json字符串转换
//tmppcd 是一个对象 //JSON.stringify() 是把对象转换成json 字符串
- 时间控件之赋值问题:datetimebox
1.datetimebox不显示毫秒数: <input class="easyui-datetimebox" name="birthday" data-o ...
- javascript中对象在OOP方面的一些知识(主要是prototype和__proto__相关)
在ES6的Class到来之前,先总结下个人对js中prototype属性的理解. 1.构造函数(大写函数名 this 无return) 2.原型对象(函数.prototype) 3.实例对象( ...