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**********************************