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. Mysql 5.7.12 配置

    打算用express+mysql写一个博客.本来在公司电脑已经配置好了的,但是为了方便在家里也能修改,所以在自己的电脑里也安装好环境. 公司电脑是win7系统32位的,安装的是5.5的mysql,用的 ...

  2. C#常用错误

    解决方法: 在配置文件连接数据库设置后加 MultipleActiveResultSets=true; <add key="ConnectionString" value=& ...

  3. Strus2学习Exception处理集锦(一)

    2015-01-05 同学用dom4j写的一个更改节点文本的方法爆出这样一个错误: 代码: for(Iterator itr=root.elementIterator();itr.hasNext(); ...

  4. 上传文件创建目录 mkdir

    mkdir($save_path,0777,true); $save_path  :文件名 0777:权限 .windows 下面可以忽略 当创建多级文件目录的时候一定要加上 true

  5. App分类

    目前主流应用程序大体分为三类:Web App.Hybrid App. Native App.web app(网页应用)hybrid app(混合应用)native app(原生应用) 淘宝天猫这样的超 ...

  6. 转!!负载均衡器技术Nginx和F5的优缺点对比

    对于数据流量过大的网络中,往往单一设备无法承担,需要多台设备进行数据分流,而负载均衡器就是用来将数据分流到多台设备的一个转发器. 目前有许多不同的负载均衡技术用以满足不同的应用需求,如软/硬件负载均衡 ...

  7. Nodejs express中创建ejs项目,解决express下默认创建jade,无法创建ejs问题

    最近在看<Node.js开发指南>,看到使用nodejs进行web开发的时候,准备创建ejs项目遇到问题了, 书上命令为: express -t ejs microblog 可是执行后,仍 ...

  8. gulp详细入门教程-gulp demo download

    简介: gulp是前端开发过程中对代码进行构建的工具,是自动化项目的构建利器:她不仅能对网站资源进行优化,而且在开发过程中很多重复的任务能够使用正确的工具自动完成:使用她,我们不仅可以很愉快的编写代码 ...

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

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

  10. axis2开发webservice入门到精通

    1,准备工作: 首先我们要下载:axis2-1.4.1-war(发布webservice),axis2-1.4.1-bin.zip(webservice调用使用的各种包). 下载好了,把axis2-1 ...