1. import com.eviware.soapui.support.GroovyUtils
  2. import groovy.util.XmlParser
  3.  
  4. def groovyUtils = new GroovyUtils( context )
  5. def xmlFilePath = groovyUtils.getProjectPath()+"\\Properties.xml"
  6.  
  7. def testAndBmkEnv = context.expand('${#Project#testAndBmkEnv}').trim()
  8. String testEnv = testAndBmkEnv.split("vs")[0].trim()
  9. String bmkEnv = testAndBmkEnv.split("vs")[1].trim()
  10.  
  11. //loadProperties(testEnv,bmkEnv,xmlFilePath)
  12. //loadProperties(testEnv,bmkEnv,xmlFilePath,testSuiteName,testCaseName)
  13.  
  14. //******************************All TestSuies and TestCases**********************************
  15. // Inject custom properties in xml file to Project, all TestSuites or all TestCases.
  16. def loadProperties(String testEnv, String bmkEnv, String xmlFilePath){
  17. def xmlParser = new XmlParser().parse(xmlFilePath);
  18. xmlParser.Env.each{
  19. if (it.attribute("id")==testEnv){
  20. setProjectProperties(it, "Test")
  21. setTestSuiteAndTestCaseProperties(it, "Test")
  22. }
  23. if (it.attribute("id")==bmkEnv){
  24. setProjectProperties(it, "Bmk")
  25. setTestSuiteAndTestCaseProperties(it, "Bmk")
  26. }
  27. }
  28. }
  29.  
  30. def setProjectProperties(Object obj, String env){
  31. obj.Project.each{
  32. it.CusProperty.each{
  33. String propertyName = it.attribute("name")+env
  34. String propertyValue = it.attribute("value")
  35. testRunner.testCase.testSuite.project.setPropertyValue(propertyName,propertyValue)
  36. }
  37. }
  38. }
  39.  
  40. // Set custom properties of all TestSuites and TestCases
  41. def setTestSuiteAndTestCaseProperties(Object obj, String env){
  42. obj.TestSuite.each{
  43. String testSuiteName = it.attribute("name")
  44. it.CusProperty.each{
  45. String propertyName = it.attribute("name")+env
  46. String propertyValue = it.attribute("value")
  47. testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).setPropertyValue(propertyName,propertyValue)
  48. }
  49. it.TestCase.each{
  50. String testCaseName = it.attribute("name")
  51. it.CusProperty.each{
  52. String propertyName = it.attribute("name")+env
  53. String propertyValue = it.attribute("value")
  54. testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).setPropertyValue(propertyName,propertyValue)
  55. }
  56. }
  57. }
  58. }
  59. //******************************All TestSuies and All TestCases**********************************
  60.  
  61. //******************************One TestSuie and One/All TestCases**********************************
  62. // Inject custom properties in xml file to Project, one TestSuite or one TestCase.
  63. def loadProperties(String testEnv, String bmkEnv, String xmlFilePath, String suiteName, String caseName){
  64. def xmlParser = new XmlParser().parse(xmlFilePath);
  65. xmlParser.Env.each{
  66. if (it.attribute("id")==testEnv){
  67. setProjectProperties(it, "Test")
  68. setTestSuiteAndTestCaseProperties(it, "Test", suiteName, caseName)
  69. }
  70. if (it.attribute("id")==bmkEnv){
  71. setProjectProperties(it, "Bmk")
  72. setTestSuiteAndTestCaseProperties(it, "Bmk", suiteName, caseName)
  73. }
  74. }
  75. }
  76.  
  77. // Set custom properties of one TestSuite and one TestCase
  78. def setTestSuiteAndTestCaseProperties(Object obj, String env, String suiteName, String caseName){
  79. obj.TestSuite.each{
  80. String testSuiteName = it.attribute("name")
  81. if (testSuiteName==suiteName){
  82. it.CusProperty.each{
  83. String propertyName = it.attribute("name")+env
  84. String propertyValue = it.attribute("value")
  85. testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).setPropertyValue(propertyName,propertyValue)
  86. }
  87. if(caseName!=""){
  88. it.TestCase.each{
  89. String testCaseName = it.attribute("name")
  90. if (testCaseName==caseName){
  91. it.CusProperty.each{
  92. String propertyName = it.attribute("name")+env
  93. String propertyValue = it.attribute("value")
  94. testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).setPropertyValue(propertyName,propertyValue)
  95. }
  96. return
  97. }
  98. }
  99. }else{
  100. it.TestCase.each{
  101. String testCaseName = it.attribute("name")
  102. it.CusProperty.each{
  103. String propertyName = it.attribute("name")+env
  104. String propertyValue = it.attribute("value")
  105. testRunner.testCase.testSuite.project.getTestSuiteByName(testSuiteName).getTestCaseByName(testCaseName).setPropertyValue(propertyName,propertyValue)
  106. }
  107. }
  108. }
  109. return
  110. }
  111. }
  112. }
  113. //******************************One TestSuie and One/All TestCases**********************************
  1.  
  1.  

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. iOS - GeoCoder 地理编码

    前言 NS_CLASS_AVAILABLE(10_8, 5_0) @interface CLGeocoder : NSObject 地理编码 地名 -> 经纬度 等具体位置数据信息.根据给定的位 ...

  2. angular学习input输入框筛选

    学习angular,看到 angular-phonecat测试用例,照着教程运行了一遍,对于初学者有点不是很理解angular 帅选代码的意思,于是找教材,参考资料,明白了input筛选原来这么简单. ...

  3. javascript事件之:谈谈自定义事件(转)

    http://www.cnblogs.com/pfzeng/p/4162951.html 对于JavaScript自定义事件,印象最深刻的是用jQuery在做图片懒加载的时候.给需要懒加载的图片定义一 ...

  4. Python_Day7_面向对象学习

    1.面向对象编程介绍 2.为什么要用面向对象进行开发? 3.面向对象的特性:封装.继承.多态 4.类.方法. 面向过程 VS 面向对象 编程范式 编程是程序员用特定的语法+数据结构+算法组成的代码来告 ...

  5. SAP公司间采购订单关联交货单报表源代码(自己收藏)

    SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF } ...

  6. git 提交代码到github错误处理

    git push -u origin mastererror: The requested URL returned error: 403 Forbidden while accessing http ...

  7. 【LeetCode】#7 Reverse Integer

    [Question] Reverse digits of an integer. Example: x = 123, return 321 x = -123, return -321 [My Solu ...

  8. SpringMVC拦截器(资源和权限管理)

    1.DispatcherServlet SpringMVC具有统一的入口DispatcherServlet,所有的请求都通过DispatcherServlet.    DispatcherServle ...

  9. <python 深入理解>变量交换x,y=y,x实现机制--元组

    python中有一种赋值机制即多元赋值,采用这种方式赋值时,等号两边的对象都是元组并且元组的小括号是可选的.通常形式为 x, y, z = 1, 2, 'a string' 等同于 (x, y, z) ...

  10. tab切换-2016.6.4

    以前的tab切换,一般都是自己找网上的源代码,不知道含义,直接套,然后会有一些不知道的问题出现. 最近学习了jq(当然属于懒人的我,学习进度很慢),然后再工作中遇到了tab选项卡,所以决定自己写一个. ...