Last active
July 1, 2021 15:07
-
-
Save nmrao/c489a485bbe3418cf49d8442f9fb92eb to your computer and use it in GitHub Desktop.
Passing arguments to class from Soapui groovy step
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to create a library with context, log variables and use them in methods. And how to call that library in groovy test step.