Forum Discussion

saurabhsharma09's avatar
saurabhsharma09
Contributor
11 years ago

[Res]Run DataSink from Script Assertion

Hello,

I have test steps in sequence as below:-
Groovy Script
POST request
Property DataSink
Groovy script reads multiple files one by one,attach it to the POST request and run POST Request.
I need to save response parameters to DataSink after each POST request and so i want to run Datasink from Script assertion step.
I was able to reach to the DataSink through below statement but couldn't run it:-
def dataSink = context.testCase.testSteps["DataSink"]

Could you please provide me the details how can i run the datasink step as testRunner is not available inside script assertion and i don't know how to run datasink from script assertion through context ?

Thanks,
Saurabh

6 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    You can call the request in the script assertion, try the following script,

    def testStep = context.testCase.testSteps["DataSink"]
    testStep.run( testRunner, context )



    I believe this should work.

    Thanks,
    Jeshtha
  • hello Jeshtha,

    after running below groovy snippet in script assertion I am getting Error as "No such property: testRunner for class: script6":-
    def dataSink = context.testCase.testSteps["DataSink"]
    dataSink.run( testRunner, context )

    Am I doing something wrong?

    Thanks,
    Saurabh
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    I am sorry since you are using script assertion we have to define the testRunner object,

    def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
    def testCase = context.testCase;
    //def testStep = context.getTestStepAt(1);
    def testStep = testCase.getTestStepByName("TestStep name");
    //def testStep = testCase.testSteps["Delay"];
    testRunner = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner(testCase, null);
    testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);
    testStep.run(testRunner, testStepContext);


    Thanks,
    Jeshtha
  • Hello,

    I was able to run DataSink Step from script assertion through the groovy script provided by you but now I am getting NullPointerException exception.
    Please refer below Error logs:-

    Tue May 20 10:44:24 IST 2014:ERROR:java.lang.NullPointerException
    java.lang.NullPointerException
    at com.eviware.soapui.impl.wsdl.teststeps.datasink.PropertyDataSink.save(SourceFile:208)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSinkTestStep.write(SourceFile:313)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlDataSinkTestStep.run(SourceFile:131)
    at com.eviware.soapui.model.testsuite.TestStep$run.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
    at Script1.run(Script1.groovy:27)
    at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:96)
    at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SourceFile:89)
    at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.assertScript(GroovyScriptAssertion.java:120)
    at com.eviware.soapui.impl.wsdl.teststeps.assertions.basic.GroovyScriptAssertion.internalAssertResponse(GroovyScriptAssertion.java:137)
    at com.eviware.soapui.impl.wsdl.teststeps.WsdlMessageAssertion.assertResponse(WsdlMessageAssertion.java:161)
    at com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest.assertResponse(RestTestRequest.java:154)
    at com.eviware.soapui.impl.wsdl.teststeps.RestTestRequest.setResponse(RestTestRequest.java:139)
    at com.eviware.soapui.impl.support.panels.AbstractHttpRequestDesktopPanel.afterSubmit(AbstractHttpRequestDesktopPanel.java:628)
    at com.eviware.soapui.impl.wsdl.panels.teststeps.RestTestRequestDesktopPanel.afterSubmit(RestTestRequestDesktopPanel.java:282)
    at com.eviware.soapui.impl.wsdl.WsdlSubmit.run(WsdlSubmit.java:157)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

    The DataSink Step has become Red and no properties are getting saved.
    However if I run the datasink manually then the properties are getting saved.

    Thanks,
    Saurabh
  • Hello,

    I did some digging around and finally got it resolved.
    The catch was to add prepare at the start of the loop and finish at the end.
    testStep.prepare( testRunner, context )
    testStep.finish( testRunner, context )

    Thanks a lot for the help. You can mark this as resolved.

    Regards,
    Saurabh