Forum Discussion

fawad's avatar
fawad
New Contributor
8 years ago

Groovy script receives null instead of a TestStepStatus value in scripted call

I have a groovy script test step that calls other test steps in the test.

In cases where the groovy call to the test step succeeds I can do the following:

 

TestStepResult licensestep = context.getTestRunner().runTestStepByName(stepName)

return licensestep.getStatus() == TestStepResult.TestStepStatus.OK

 

and I get true returned, but where the runTestStepByName fails it returns null and licensestep.getStatus() results in a null pointer exception.

 

Is this by design or is it a bug?

 

5 Replies

  • Radford's avatar
    Radford
    Super Contributor

    I'm not sure what version you are using and or what the exact issue you are experiencing is, but in version 1.7 I use the following to run test cases from groovy script:

     

    import com.eviware.soapui.support.types.StringToObjectMap
    
    def testCase = testRunner.getTestCase().getTestSuite().getTestCaseByName('TestCase 2')
    def testCaseRunner = testCase.run(new StringToObjectMap(), false)
    def testStepResults = testCaseRunner.getResults()
    
    testStepResults.each{ testStepResult ->
    	log.info('TestStep "' + testStepResult.getTestStep().getName() + '" result = ' +  testStepResult.getStatus().toString())
    }

     

     

    My "Test Case 2" being called in the above example was just a test case that had two groovy test steps, one that succeeded, and one that failed (easily done with a couple of assert statements).

     

    This gave the output:

     

    Tue Oct 25 16:55:04 BST 2016:INFO:TestStep "Groovy Script 1" result = OK
    Tue Oct 25 16:55:04 BST 2016:INFO:TestStep "Groovy Script 2" result = FAILED

     

  • Radford's avatar
    Radford
    Super Contributor

    Just as a follow-up I quickly tried you method of running a test case and also got the following null pointer:

     

    Tue Oct 25 17:25:35 BST 2016:ERROR:java.lang.NullPointerException
       java.lang.NullPointerException
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:228)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStepByName(AbstractTestCaseRunner.java:212)
        at com.eviware.soapui.model.testsuite.TestCaseRunner$runTestStepByName$4.call(Unknown Source)
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
        at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
        at Script5.run(Script5.groovy:16)
        at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:92)
        at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:79)
        at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:156)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.runTestStep(AbstractTestCaseRunner.java:228)
        at com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner.runCurrentTestStep(WsdlTestCaseRunner.java:47)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:148)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestCaseRunner.internalRun(AbstractTestCaseRunner.java:1)
        at com.eviware.soapui.impl.wsdl.support.AbstractTestRunner.run(AbstractTestRunner.java:130)
        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)

     

    Being this is a NullPointerException I guess that you have hit a bug, might be good to report it to SmartBear support.

     

    Hopefully the code in my initial reply will let you work around the bug.

    • nmrao's avatar
      nmrao
      Champion Level 3
      Before doing so, it would be worth to check the line 16 of groovy script.
      • Radford's avatar
        Radford
        Super Contributor

        Yep, nmrao is correct, I misread your original post and didn't realise (I assume) you are calling another test step within the same test case. Appologies, my code is to run another test case, and please ignore my post about above about the null pointer.

         

        I tried running another step in the same case (your way) and it ran to completion regardless of the result status.