Forum Discussion
Thanks for your response Rao,
I am using below groovy code as an assertion script for a test step.
//get the path of the project root
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectPath = groovyUtils.projectPath
log.info(" projectPath : "+projectPath)
//get the test suite name
def testSuiteName_appName = messageExchange.modelItem.testStep.testCase.testSuite.getName()
log.info(" testSuiteName_appName : "+testSuiteName_appName)
//get the test case name
def tcaseName_dashboardName = messageExchange.modelItem.testCase.getName()
log.info(" tcaseName_dashboardName : "+tcaseName_dashboardName)
//get the test step name
def testStepName = messageExchange.modelItem.testStep.getName()
log.info(" testStepName : "+testStepName)
if(execution_mode == "testExecution" ) {
File file = new File("/tmp/Assertion_Files/"+testSuiteName_appName+"/"+tcaseName_dashboardName+"/"+testStepName+".txt")
BufferedReader br = new BufferedReader(new FileReader(file));
String fileStatement;
def newString = "";
while ((fileStatement = br.readLine()) != null) {
newString = newString + fileStatement.toString();
}
def expected_data_in_file = newString.trim().replace(' ', '');
expected_data_in_file = expected_data_in_file.replace("\n", "").replace("\r", "");
def splunkRestApiResponse = context.response.toString().trim().replace(' ', '');
splunkRestApiResponse = splunkRestApiResponse.replace("\n", "").replace("\r", "");
log.info(" splunkRestApiResponse "+splunkRestApiResponse);
log.info(" fileResponse trimmed "+expected_data_in_file) ;
assert(splunkRestApiResponse.equals(expected_data_in_file));
log.info(" Assertion Passed ") ;
}
It is working fine. As this is a generic code and all of my teststeps have same groovy assertion script. Is there a way to put this script at one place and then call it from each assertion script. This will help me to reduce my effort whenever there is a change in groovy script.
It is definitely possible jayantjayant
There are two approaches.
1. ReadyAPI supports scripts libary where user can create classes for common tasks and re-use them whereever needed. The tool takes care of changes in the classes and compile and reload them and this does not require tool to be restarted.
See below documentation for more details.
https://support.smartbear.com/readyapi/docs/testing/scripts/library.html
2. For open source, there is no script library available However, similarity is that user creating the classes as above. The difference is that if there are any changes in the class, user have to take care of compiling, creating jar, replace the jar to SOAPUI_HOME/bin/ext directory. Most importantly, tool needs a restart.
Our community expertrupert_anderson created a blog with step by step procedure for the same. Please refer below:
http://rupertanderson.com/blog/1-how-to-develop-add-and-use-a-custom-groovy-library-in-soapui/
Either of the cases, one has to convert the current script into class / method so that it can be reused.
Related Content
- 2 years ago