IT-SDK-SoapUI

From wiki.samerhijazi.net
Jump to navigation Jump to search

Source

Properties

Initial

Properties can be accessed at following levels:
Project:	${#Project#PropertyName}
TestSuite:	${#TestSuite#PropertyName}
TestCase:	${#TestCase#PropertyName}
TestStep:	${TestStepName#PropertyName}
...
System:		${#System#PropertyName}
Env:		${#Env#PropertyName}
Global:		${#Global#PropertyName}

Coding

//Project
testRunner.testCase.testSuite.project.getPropertyValue("Name")
testRunner.testCase.testSuite.project.setPropertyValue("Name","I am in Project")
//TestSuite
testRunner.testCase.testSuite.getPropertyValue("Name")
testRunner.testCase.testSuite.setPropertyValue("Name","I am in TestSuite")
//TestCase
testRunner.testCase.getPropertyValue("Name")
testRunner.testCase.setPropertyValue("Name","I am in TestCase")
//TestStep
testRunner.testCase.getTestStepByName("CountryCodes").getPropertyValue("Name")
testRunner.testCase.getTestStepByName("CountryCodes").setPropertyValue("Name","I am in Test Step")
//Global
com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "Name")
com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( "Name","I am in Global Prop" )

// Add, Remove Property
testRunner.testCase.testSuite.project.addProperty("DOB")
testRunner.testCase.testSuite.project.removeProperty("Name");

testRunner.testCase.testSuite.addProperty("Name")
testRunner.testCase.testSuite.removeProperty("Name")

// Loop through properties

testRunner.testCase.properties.each
{
 key,value -
 log.info (testRunner.testCase.getPropertyValue(key))
 //log.info (key+" - "+value)
}

Rest

context.setProperty("Hello", new Hello(log,context,testRunner))
...
def testStep = testRunner.testCase.getTestStepByName("Hello")
testStep.run(testRunner, context)
context.Hello.sayHello("Raghav")
...
project = testRunner.testCase.testSuite.project ;
tcase = project.testSuites["TestSuite3"].testCases["TestCase1"] ; 
hello = tcase.getTestStepByName("Hello");

hello.run(testRunner, context)
context.Hello.sayHello("Raghav")
...
project = testRunner.testCase.testSuite.project ;
tcase = project.testSuites["TestSuite"].testCases["TestCaseName"] ; 
hello = tcase.getTestStepByName("Hello");

log.info testRunner.metaClass.methods*.name.unique().sort()

context.setProperty("Hello", new Hello(log,context,testRunner))

def hello = testRunner.testCase.getTestStepByName("Hello");

hello.run(testRunner, context)

def ref = context.Hello;
ref.printHello("Raghav");
############################################################################################
Notes: TU09
/Groovy - run request from same TestCase
def status = testRunner.runTestStepByName("TestStepName")
def result = status.getStatus().toString();
log.info ("   ---- "+result)

//Groovy - run request from another TestCase or TestSuite
project = testRunner.testCase.testSuite.project ;
tcase = project.testSuites["TestSuiteName"].testCases["TestCaseName"] ; 
tstep = tcase.getTestStepByName("TestStepName");
def status = tstep.run(testRunner, context)
def result = status.getStatus().toString();
log.info ("   ----   "+result)
############################################################################################
Notes TU10
groovy code to run test case
=====================
def tCase = testRunner.testCase.testSuite.testCases["TestCaseName"]
runner = tCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);

groovy code to loop test cases in a test suite
==================================
def testCases = context.testCase.testSuite.getTestCaseList() 
testCases.each{
log.info(it.name)
}
command line run
==============
cd C:\Program Files\SmartBear\SoapUI-5.4.0\bin\
testrunner.bat -sTestSuite3 -cTestCase2 "C:\Users\Raghav Pal\OneDrive\Projects\SoapUIProjects\CountryInfoService-soapui-project1.xml"
############################################################################################
def tCase = testRunner.testCase.testSuite.testCases["TestCaseName"]
runner = tCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);
...
def suite = context.testCase.testSuite.project.testSuites["TestSuiteName"]
suite.run(null,false)
...
projectName=testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("REST Project 1")
projectName.run(null,true)
##################################
testRunner.testCase.testSuite.project.getTestSuiteByName('TestSuite1').getTestCaseByName('TestCase1').setSetupScript('log.info "setup"')
testRunner.testCase.testSuite.project.getTestSuiteByName('TestSuite1').getTestCaseByName('TestCase1').setTearDownScript('log.info "teardown"')