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的更多相关文章

  1. 移除project,testsuite,testcase级别所有的custom properties

    // Remove all custom properties on Project level. If removed, custom properties cannnot be injected ...

  2. 在当前TestSuite/TestCase run之前先run另一个TestSuite/TestCase

    在当前的TestSuite/TestCase的Setup Script里面写上这段代码: import com.eviware.soapui.model.support.PropertiesMap l ...

  3. SQLServer解析xml到Oracle

    写了一个程序:根据状态位读取SQLserver 中的一张表,下载其中一个字段的值,这个值是XML类型的,然后把这个XML文件的内容插入到另一Oracle数据库,并更新SQLServer表的标志位,表示 ...

  4. Android开发学习---使用XmlPullParser解析xml文件

    Android中解析XML的方式主要有三种:sax,dom和pull关于其内容可参考:http://blog.csdn.net/liuhe688/article/details/6415593 本文将 ...

  5. java解析xml

    一.Document对象相关   1.读取XML文件,获得document对象.             SAXReader reader = new SAXReader();             ...

  6. iOS-数据解析XML解析的多种平台介绍

    在iPhone开发中,XML的解析有很多选择,iOS SDK提供了NSXMLParser和libxml2两个类库,另外还有很多第三方类库可选,例如TBXML.TouchXML.KissXML.Tiny ...

  7. java生成解析xml的另外两种方法Xstream

    Xstream生成和解析xm和JAXB生成和解析xml的方法. 一,Xstream Xstream非jdk自带的,需要到入Xstream-1.4.3.jar和xpp3_min-1.1.4.jar 1. ...

  8. 解析XML文档之一:使用SAX解析

    使用sax解析xml方法总结 解析的的xml文档格式如下 <?xml version="1.0" encoding = "UTF-8"?> < ...

  9. 01_Java解析XML

    [打印list.Map集合的工具方法] /** * 打印List集合对应的元素 */ public void printList(List<Object> list){ for(Objec ...

随机推荐

  1. java面向对象的语言

    对象:真实存在唯一的事物. 类: 实际就是对某种类型事物的共性属性与行为的抽取. 抽象的概念.... 车 我们从小的时候就不断的接触很多的对象,我们的大脑就会把 这些具备相同属性与行为的事物进行分类. ...

  2. CSS3中的伪类选择器详解

      类选择器和伪类选择器区别 类选择器我们可以随意起名,而伪类选择器是CSS中已经定义好的选择器,不可以随意起名. 伪类选择器以及伪元素 我们把它放到这里 p.aaas{ text-align: le ...

  3. R语言实战(一)介绍、数据集与图形初阶

    本文对应<R语言实战>前3章,因为里面大部分内容已经比较熟悉,所以在这里只是起一个索引的作用. 第1章       R语言介绍 获取帮助函数 help(), ? 查看函数帮助 exampl ...

  4. SPSS数据分析—广义线性混合模型

    广义线性混合模型是目前线性模型范畴内最为完备的模型框架,它是广义线性模型的进一步延伸,进一步突破适用条件,因变量既 可以非正态,也可以非独立,由于其最为复杂,因此SPSS对其输出结果采用模型格式,而不 ...

  5. node与mongodb的使用

    1.mongdb安装好后,在.bin文件夹下执行mongod.exe --dbpath=D:\mongodb\db  即可启动mongodb,表示将数据放在db这个文件夹,且每一次启动要执行完整的这句 ...

  6. JAVA GUI布局管理器

    边界布局管理器: a.布局方式:是把整个容器划分为五个部分.东西南北中,南北要贯通,中间最大 (不仅是中间的范围最大,权利也最大)当周边不存在的时候中间会占领周边,当中间不存在的时候周边不能占据中间 ...

  7. angularJS 2.0 开发的简单dome

    与其说这是一个demo,不如说是一个与高手的讨教过程.虽然demo出来了,可其中有些问题我还是不太明白,如果有angularjs2.0的大神,请进来指导一番,~~~~~不甚感激. 说明第一点:我采用的 ...

  8. 开发Blog整理

    开发Blog记录 清理收藏夹 太多了,来不及看了. http://blog.sina.com.cn/s/blog_67d95f40010113ec.htmlhttp://segmentfault.co ...

  9. UImenuController

    长按出现选择项:关键方法 在 tabview 中需要制定 tabview 的一些方法:关键为 在某种特殊情况下,需要自定义的时候:采用如下方式

  10. 【转】js插件zClip实现复制到剪贴板功能

    相信这个功能大家平时上网经常能碰到,以前也没怎么留意怎么实现的,直到项目中需要. 网上一搜一大堆,单纯使用js方法也不是没有,但是由于各浏览器的安全机制不同,不是跨浏览器的.去看了几个常用的网站,都是 ...