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知识积累-XML的DOM解析修改和删除方法

    import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder;import jav ...

  2. HTML5扩展之微数据与丰富网页摘要

    一.微数据是? 一个页面的内容,例如人物.事件或评论不仅要给用户看,还要让机器可识别.而目前机器智能程度有限,要让其知会特定内容含义,我们需要使用规定的标签.属性名以及特定用法等.举个简单例子,我们使 ...

  3. 利用SSH传输文件

    在linux下一般用scp这个命令来通过ssh传输文件. 1.从服务器上下载文件scp username@servername:/path/filename /var/www/local_dir(本地 ...

  4. 推荐6款常用的Java开源报表制作工具

    JasperReports是一个基于Java的开源报表工具,它可以在Java环境下像其它IDE报表工具一样来制作报表.JasperReports 支持PDF.HTML.XLS.CSV和XML文件输出格 ...

  5. Markdown渲染后文章标题收缩控件

    文章首发于szhshp的第三边境研究所(szhshp.org), 转载请注明 一个让Markdown-Post的标题拥有Collapse功能的JS 直接把鼠标放在这篇文章下方的header上,点击标题 ...

  6. css学习笔记 9

    两列定宽和两列宽度自适应结构: 在ie7及以下,container的宽度和两列子元素的宽度设置为具体值或百分比的任意组合时,两列子元素即使浮动,container的高度也能自适应:其他浏览器需要为co ...

  7. css权值计算

    外部样式表<内部样式表<内联样式: HTML 标签选择器的权值为 1: Class 类选择器的权值为 10: ID 选择器的权值为 100: 内联样式表的权值最高 1000: !impor ...

  8. c#数据绑定(3)——数据转化为信息

    文/嶽永鹏 本文主要在数据绑定1和2中新增了DataSet对象,练习了如何在DataSet中添加表.关系和约束,同时本文也简要的介绍了如何将数据转化为信息. 目标界面: XAML代码: <Gri ...

  9. 学习笔记找到多个具有相同 ID“_header”的控件,FindControl 要求控件具有唯一的 ID.

    解决 找到多个具有相同 ID“_header”的控件,FindControl 要求控件具有唯一的 ID. private void DisplayHotBooks()    {        //获取 ...

  10. jrebel注意事项

    -Xms2048m -Xmx2048m -XX:MaxPermSize=4096m -noverify -javaagent:C:\Users\Administrator\.IntelliJIdea2 ...