Skip to content

Instantly share code, notes, and snippets.

@nmrao
Last active July 1, 2021 15:07
Show Gist options
  • Save nmrao/c489a485bbe3418cf49d8442f9fb92eb to your computer and use it in GitHub Desktop.
Save nmrao/c489a485bbe3418cf49d8442f9fb92eb to your computer and use it in GitHub Desktop.
Passing arguments to class from Soapui groovy step
//Define the class in library
class Mylibrary {
def context
def log
//Shows the test case name
def showDetails() {
log.info context.testCase.name
}
//Sets a property value at given level. default is test case
def setProperty(name, value, level='testcase'){
switch(level){
case 'project':
context.testCase.testSuite.project.setPropertyValue(name, value.toString())
break
case 'suite':
context.testCase.testSuite.setPropertyValue(name, value.toString())
break
default:
context.testCase.setPropertyValue(name, value.toString())
break
}
}
}
//Using the library in groovy script of test step
def mylib = new Mylibrary(context: context, log: log)
mylib.showDetails()
//Set property at suite level
mylib.setProperty('MY_SUITE_PROPERTY', 'myvalue', 'suite')
//set property at test case level, level is optional if need to set at testcase
mylib.setProperty('MY_TEST_PROPERTY', 'testValue')
//Set project property
mylib.setProperty('MY_PROJECT_PROPERTY', 'projectValue', 'project')
@nmrao
Copy link
Author

nmrao commented Jul 1, 2021

How to create a library with context, log variables and use them in methods. And how to call that library in groovy test step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment