Groovy解析xml并且注入Project,TestSuite,TestCase级别的custom properties
- 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的更多相关文章
- 移除project,testsuite,testcase级别所有的custom properties
// Remove all custom properties on Project level. If removed, custom properties cannnot be injected ...
- 在当前TestSuite/TestCase run之前先run另一个TestSuite/TestCase
在当前的TestSuite/TestCase的Setup Script里面写上这段代码: import com.eviware.soapui.model.support.PropertiesMap l ...
- SQLServer解析xml到Oracle
写了一个程序:根据状态位读取SQLserver 中的一张表,下载其中一个字段的值,这个值是XML类型的,然后把这个XML文件的内容插入到另一Oracle数据库,并更新SQLServer表的标志位,表示 ...
- Android开发学习---使用XmlPullParser解析xml文件
Android中解析XML的方式主要有三种:sax,dom和pull关于其内容可参考:http://blog.csdn.net/liuhe688/article/details/6415593 本文将 ...
- java解析xml
一.Document对象相关 1.读取XML文件,获得document对象. SAXReader reader = new SAXReader(); ...
- iOS-数据解析XML解析的多种平台介绍
在iPhone开发中,XML的解析有很多选择,iOS SDK提供了NSXMLParser和libxml2两个类库,另外还有很多第三方类库可选,例如TBXML.TouchXML.KissXML.Tiny ...
- java生成解析xml的另外两种方法Xstream
Xstream生成和解析xm和JAXB生成和解析xml的方法. 一,Xstream Xstream非jdk自带的,需要到入Xstream-1.4.3.jar和xpp3_min-1.1.4.jar 1. ...
- 解析XML文档之一:使用SAX解析
使用sax解析xml方法总结 解析的的xml文档格式如下 <?xml version="1.0" encoding = "UTF-8"?> < ...
- 01_Java解析XML
[打印list.Map集合的工具方法] /** * 打印List集合对应的元素 */ public void printList(List<Object> list){ for(Objec ...
随机推荐
- iOS - GeoCoder 地理编码
前言 NS_CLASS_AVAILABLE(10_8, 5_0) @interface CLGeocoder : NSObject 地理编码 地名 -> 经纬度 等具体位置数据信息.根据给定的位 ...
- angular学习input输入框筛选
学习angular,看到 angular-phonecat测试用例,照着教程运行了一遍,对于初学者有点不是很理解angular 帅选代码的意思,于是找教材,参考资料,明白了input筛选原来这么简单. ...
- javascript事件之:谈谈自定义事件(转)
http://www.cnblogs.com/pfzeng/p/4162951.html 对于JavaScript自定义事件,印象最深刻的是用jQuery在做图片懒加载的时候.给需要懒加载的图片定义一 ...
- Python_Day7_面向对象学习
1.面向对象编程介绍 2.为什么要用面向对象进行开发? 3.面向对象的特性:封装.继承.多态 4.类.方法. 面向过程 VS 面向对象 编程范式 编程是程序员用特定的语法+数据结构+算法组成的代码来告 ...
- SAP公司间采购订单关联交货单报表源代码(自己收藏)
SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF } ...
- git 提交代码到github错误处理
git push -u origin mastererror: The requested URL returned error: 403 Forbidden while accessing http ...
- 【LeetCode】#7 Reverse Integer
[Question] Reverse digits of an integer. Example: x = 123, return 321 x = -123, return -321 [My Solu ...
- SpringMVC拦截器(资源和权限管理)
1.DispatcherServlet SpringMVC具有统一的入口DispatcherServlet,所有的请求都通过DispatcherServlet. DispatcherServle ...
- <python 深入理解>变量交换x,y=y,x实现机制--元组
python中有一种赋值机制即多元赋值,采用这种方式赋值时,等号两边的对象都是元组并且元组的小括号是可选的.通常形式为 x, y, z = 1, 2, 'a string' 等同于 (x, y, z) ...
- tab切换-2016.6.4
以前的tab切换,一般都是自己找网上的源代码,不知道含义,直接套,然后会有一些不知道的问题出现. 最近学习了jq(当然属于懒人的我,学习进度很慢),然后再工作中遇到了tab选项卡,所以决定自己写一个. ...