Forum Discussion

LennSar's avatar
LennSar
Contributor
2 years ago
Solved

Run entire TestSuite from groovy

Hi there,

 

I generated a customizable TestSuite which I would like to run in different setups from a groovy script. I found many extremely complex script suggestions to do this but couldn't get to run any of them. I therefore wanted to ask whether anyone could come up with an idea of how to achieve either running an entire testSuite from groovy or just a single testCase in ReadyApi 3.4.

 

Thanks a lot!

  • Hi LennSar ,

     

    Here you go:

     

    def targetTestSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("yourTargetTestSuiteName")
    def targetTestCase = targetTestSuite.getTestCaseByName("yourTargetTestCaseName")
    targetTestSuite.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
    //targetTestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)

     

     Hint: You can use the Objects available by default (see "i" info in the groovy test step on top right).

    Based on these you can use the auto-complete while you write stuff. So for instance "testRunner.testCase.testSuite.project." and then press control+space you will see a list of useful commands. 

    It's a bit tricky somtimes to know what exactly is expected, example the  ".run" shows you need 2 pass on 2 arguments, the StringToObjectMap and a Boolean. 

    I know for your use case these arguments (new com.eviware.soapui.support.types.StringToObjectMap(), false)  do the trick, but don't ask me what exactly these mean 🙂

     

    When you want to run another test step in the same test case as your groovy test step, the below will work: testRunner.testCase.getTestStepAt(0).run(testRunner, context)

    This will run only the first test step and then continue your script.

    If you want to repeat multiple test steps, you could use the below (but watch out you don't get stuck in an endless loop!).

     

    I once reported a feature request to improve these javaDoc documentation, so it would be more straightforward to script, feel free to upvote 😉 :

    https://community.smartbear.com/t5/Feature-Requests/Script-library-interoperability-javaDoc-refactoring-search-amp/idi-p/224062

5 Replies

  • JoostDG's avatar
    JoostDG
    Frequent Contributor

    Hi LennSar ,

     

    Here you go:

     

    def targetTestSuite = testRunner.testCase.testSuite.project.getTestSuiteByName("yourTargetTestSuiteName")
    def targetTestCase = targetTestSuite.getTestCaseByName("yourTargetTestCaseName")
    targetTestSuite.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)
    //targetTestCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)

     

     Hint: You can use the Objects available by default (see "i" info in the groovy test step on top right).

    Based on these you can use the auto-complete while you write stuff. So for instance "testRunner.testCase.testSuite.project." and then press control+space you will see a list of useful commands. 

    It's a bit tricky somtimes to know what exactly is expected, example the  ".run" shows you need 2 pass on 2 arguments, the StringToObjectMap and a Boolean. 

    I know for your use case these arguments (new com.eviware.soapui.support.types.StringToObjectMap(), false)  do the trick, but don't ask me what exactly these mean 🙂

     

    When you want to run another test step in the same test case as your groovy test step, the below will work: testRunner.testCase.getTestStepAt(0).run(testRunner, context)

    This will run only the first test step and then continue your script.

    If you want to repeat multiple test steps, you could use the below (but watch out you don't get stuck in an endless loop!).

     

    I once reported a feature request to improve these javaDoc documentation, so it would be more straightforward to script, feel free to upvote 😉 :

    https://community.smartbear.com/t5/Feature-Requests/Script-library-interoperability-javaDoc-refactoring-search-amp/idi-p/224062

    • LennSar's avatar
      LennSar
      Contributor

      Hi JoostDG,

       

      thanks for the script! That was exactly what I was looking for. And I was so close!!! 

      new com.eviware.soapui.support.types.StringToObjectMap()

       seems to be what I was missing. The auto-complete does work in this case. In many cases it doesn't when you access named things in between such as someCommand('customTestStepName').<Ctrl + space>. But that's probably a different story. The issue is exactly what you mentioned: You have no idea what thos arguments in the function call are supposed to be and even if they would I strongy disagree that the functionality of an auto complete can replace a complete documentation. I will gladly upvote your issue!

       

      Thanks for the help!

    • LennSar's avatar
      LennSar
      Contributor

      Hi Charlie69,

      I've seen that link before but it didn't really helped me. Probably due to my lag of experience with groovy. 

      The project linked in the solution uses a Setup Script to showcase running a test case from groovy but if I copy the content from the setup script to a groovy test step it doesn't work anymore. 

       

      Sha1's suggestion also doesn't work but might simply be an importing issue?

      import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCaseRunner 
      
      def targetTestCase=testRunner.testSuite.project.testSuites["TestSuite"].testCases["TestCase"]
      def targetContext= new WsdlTestRunContext(targetTestCase)
      targetTestCase.run(testRunner,targetContext)

       

      This gives me an "unable to resolve class WsdlTestRunContext" error. When I add the import like so:

      import com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext 

      I get the error:
      Could not find matching constructor for: com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(com.eviware.soapui.impl.wsdl.WsdlTestCasePro)

      Any suggestions?