Showing posts with label Properties in SoapUI. Show all posts
Showing posts with label Properties in SoapUI. Show all posts

Sunday, November 23, 2014

How to access property in Script Assertion in SoapUI using Groovy Script

//Set Property
messageExchange.modelItem.testStep.testCase.setPropertyValue("MyProp", someValue)

//Get Property
def testCaseProperty = messageExchange.modelItem.testStep.testCase.getPropertyValue("MyProp")

Setting and Getting properties at all levels in SoapUI with Groovy Script

Getting Properties…

-From a Groovy Script test step
def testCaseProperty = testRunner.testCase.getPropertyValue("MyProp")
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue("MyProp")
def projectProperty = testRunner.testCase.testSuite.project.getPropertyValue("MyProp")
def globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("MyProp")

Setting Properties…

-From a Groovy Script test step:
testRunner.testCase.setPropertyValue("MyProp", someValue)
testRunner.testCase.testSuite.setPropertyValue("MyProp", someValue)
testRunner.testCase.testSuite.project.setPropertyValue("MyProp", someValue)
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue("MyProp", someValue)

How to save all Test Case properties in a Map using Groovy Script

def tcProps = testRunner.testCase.getProperties()
def map = [:]

//grab all the properties from the test case and put them in a map as long as they aren't empty
for(p in tcProps){    
            if (p.value.getValue() != "") {
            map.put(p.key, p.value.getValue())            
    } 
}

How to transfer property proerty to all Test Cases in Test Suite an access it

Transfer property to all TC

def ABC = testRunner.testCase.testSuite.project.getTestSuiteList()
def DEF = testRunner.testCase.testSuite.getPropertyValue("w2_SessionID")

for (testSuite in ABC){
for (testCase in testSuite.getTestCaseList()){
testCase.setPropertyValue("w2_SessionID", DEF)
}
}


Access property in each Test Case

def abdProjProp = context.expand( '${#Project#abdProjProp}' )

How to run a TestCase located in another project

def prj = testRunner.testCase.testSuite.project.workspace.getProjectByName("ProjectName")

2.tCase = prj.testSuites['TestSuiteName'].testCases['TestCaseName']

3.tStep = tCase.getTestStepByName("TestStepName")

4.def runner = tStep.run(testRunner, context)

How to transfer properties between projects

//get test case from other project
project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName(project_name)
testSuite = project.getTestSuiteByName(suite_name);
testCase = testSuite.getTestCaseByName(testcase_name);

//set properties
testRunner.testCase.setPropertyValue(property_name, property_value);
testRunner.testCase.setPropertyValue(another_property_name, another_property_value);

// run test case
runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);