Friday, September 23, 2016

SoapUi: Reusable methods , functions

Reusable methods , functions

https://community.smartbear.com/t5/SoapUI-NG/How-to-write-a-reusable-script-Library/td-p/29499

Reusable methods:


Create project as  :- Library(TestSuite-disabled) > module-name(TC) >Example(groovy Script)

In Example file(groovy Script) copy paste:
context.setProperty( "example", new Example( log, context, testRunner) )
class Example{
 def log
 def context
 def testRunner
 public  Example(logIn,contextIn,testRunnerIn){
  this.log=logIn
  this.context = contextIn
    this.testRunner = testRunnerIn
 }
 public String execute(message) { 
       return message
 }
}

Create another testsuite >testcase>groovyscript and paste below code and Run:

library = testRunner.testCase.testSuite.project.testSuites["Library"]
module = library.testCases["module-name"].testSteps["Example"]
module.run(testRunner, context)

// get the instance of example from the context.
def example = context.example
log.info(example.execute("hi"))