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. python连接mysql的驱动

    对于py2.7的朋友,直接可以用MySQLdb去连接,但是MySQLdb不支持python3.x.这是需要注意的~ 那应该用什么python连接mysql的驱动呢,在stackoverflow上有人解 ...

  2. ZigBee 安全探究

    ZigBee 安全探究 0x02 ZigBee安全机制 (注:对于本节内容,可能在新版ZigBee协议标准中会有所变化,请以新版为准.) ZigBee主要提供有三个等级的安全模式: 1. 非安全模式: ...

  3. 让Java和MySQL连接起来

    Java 连接 MySQL 需要驱动包,可以下载菜鸟教程提供的 jar 包:http://static.runoob.com/download/mysql-connector-java-5.1.39- ...

  4. (转)pymysql 连接mysql数据库---不支持中文解决

    往数据库里插入中文时出现异常:UnicodeEncodeError: 'latin-1' codec can't encode characters 就是编码的问题,pymysql默认的编码是lati ...

  5. 各种文件的mime类型

    扩展名:abs MIME类型:audio/x-mpeg 扩展名:ai MIME类型:application/postscript 扩展名:aif MIME类型:audio/x-aiff 扩展名:aif ...

  6. 【LeetCode】Hamming Distance

    问题网址 https://leetcode.com/problems/hamming-distance/ 就是一个异或后,求1的位数的问题. 看到问题之后,首先困扰是: int能不能求异或?是不是要转 ...

  7. git的常用命令

    简介  上篇讲解git的博客,在centos6.5中安装完成了github客户端,接下来我们来熟悉git的操作命令 1.查看自己机器中安装的git版本 [root@jacky conf]# git - ...

  8. 如何判断Javascript对象是否存在

    Javascript语言的设计不够严谨,很多地方一不小心就会出错. 举例来说,请考虑以下情况. 现在,我们要判断一个全局对象myObj是否存在,如果不存在,就对它进行声明.用自然语言描述的算法如下: ...

  9. SPSS数据分析—主成分分析

    我们在分析问题的时候,为了准确全面的反映问题,常常收集很多变量,这些变量之间往往具有相关性,导致存在大量的重复信息,直接使用的话,不但模型非常复杂,而且所引起的共线性问题会使模型准确度降低. 对此,我 ...

  10. 11.10 Taolu1234组信息汇总

    团队名称: Taolu1234 团队选题: <餐厅到店点餐系统>WEB版 团队博客地址: http://www.cnblogs.com/queenjuan/ 团队GITHUB地址: htt ...