Forum Discussion

jkrier's avatar
jkrier
Regular Contributor
7 years ago

Creating TestCases and TestSteps dynamically in a Groovy step

We are trying to integrate with a project management software for test case development. We have a way of feeding the test results into this software so it will auto pass/fail the test case.

 

Some of our test cases are just configuration, 10's, 100's, 1000's permutations of the same method. We want the test case names in SoapUI to be unique, representing the values that are being sent in the operation. The only way I can think of doing this without having to manually create hundreds of test cases is to create them with a groovy script, run them, and delete them.

 

I found some code for creating a test case but no examples of adding a wsdl test step.

 

import  com.eviware.soapui.config.TestStepConfig
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestStepFactory

def newTestCase = suite.addNewTestCase("NewTestCase")
def newTestStep = newTestCase.addTestStep('testStep')

The problem is the addTestStep() wants a type from what I can tell here https://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/testcase/WsdlTestCase.html

 

I don't know what to put in the String type. I've found examples of other test step types being created so I tried to kinda copy that structure and nothing is working.

 

Also, I made the name of this thread a little off topic from the body because I am also interested if anyone has done this kind of thing before and maybe has a better solution or ideas.

 

Thanks!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • I think you're after a "request" from these:

     

    public static final String AMF_REQUEST_TYPE   "amfrequest"
    public static final String DELAY_TYPE         "delay"
    public static final String GOTO_TYPE          "goto"
    public static final String GROOVY_TYPE        "groovy"
    public static final String HTTPREQUEST_TYPE   "httprequest"
    public static final String JDBC_TYPE          "jdbc"
    public static final String JMS_STEP_ID        "JMS"
    public static final String MANUAL_TEST_STEP   "manualTestStep"
    public static final String PROPERTIES_TYPE    "properties"
    public static final String TRANSFER_TYPE      "transfer"
    public static final String RESTREQUEST_TYPE   "restrequest"
    public static final String RUNTESTCASE_TYPE   "calltestcase"
    public static final String MOCK_RESPONSE_TYPE "mockresponse"
    public static final String REQUEST_TYPE       "request"

    I got that from this page and section https://www.soapui.org/apidocs/constant-values.htl#com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory.GROOVY_TYPE

     

    But to be honest I never would have found that without looking through the source code.

     

    It looks like if you try creating it from just the type, you're going to get prompted every time for which Operation the request is going to be on. So you'll need to figure out how to call addTestStep and pass in the rest of the information it needs. (One idea: what about cloning an existing test step?)

  • JHunt's avatar
    JHunt
    Community Hero

    I think you're after a "request" from these:

     

    public static final String AMF_REQUEST_TYPE   "amfrequest"
    public static final String DELAY_TYPE         "delay"
    public static final String GOTO_TYPE          "goto"
    public static final String GROOVY_TYPE        "groovy"
    public static final String HTTPREQUEST_TYPE   "httprequest"
    public static final String JDBC_TYPE          "jdbc"
    public static final String JMS_STEP_ID        "JMS"
    public static final String MANUAL_TEST_STEP   "manualTestStep"
    public static final String PROPERTIES_TYPE    "properties"
    public static final String TRANSFER_TYPE      "transfer"
    public static final String RESTREQUEST_TYPE   "restrequest"
    public static final String RUNTESTCASE_TYPE   "calltestcase"
    public static final String MOCK_RESPONSE_TYPE "mockresponse"
    public static final String REQUEST_TYPE       "request"

    I got that from this page and section https://www.soapui.org/apidocs/constant-values.htl#com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory.GROOVY_TYPE

     

    But to be honest I never would have found that without looking through the source code.

     

    It looks like if you try creating it from just the type, you're going to get prompted every time for which Operation the request is going to be on. So you'll need to figure out how to call addTestStep and pass in the rest of the information it needs. (One idea: what about cloning an existing test step?)

  • JHunt's avatar
    JHunt
    Community Hero

    As for the opinion-based part of the question... personally I probably would avoid trying to create that many test cases, and just have a script that repeatedly calls a request based on some input data (from file or from CSV etc), and just output to log file or output data file.

     

    But from what you've said, you need the test cases generated for the sake of this other program reading the output. So I guess there's nothing wrong with your current approach.

    • jkrier's avatar
      jkrier
      Regular Contributor

      Yeah, I hear you. I am not happy with this either, to be honest. This is going to be our long term approach for building and automating tests.

       

      The problem is I need individual test cases for any iteration of a request. I can't really think of a better way to do this.

       

      While I have your attention; it looks like I will want to use

       

      public static final String REQUEST_TYPE       "request" 

       

      Do you have any ideas on how I can pull in an existing operation from an interface in the project?

       

      In the link I provided in my initial post I see

       

      WsdlTestStepaddTestStep(String type, String name, String endpoint, String method) 

       

      do you think the "method" input can be used or am I misunderstanding it's purpose?

  • jkrier's avatar
    jkrier
    Regular Contributor

    And to be even more of a pain. Those types are throwing an error

     

    • Wed Mar 21 12:34:45 MDT 2018:ERROR:An error occurred [No such property: REQUEST_TYPE for class: Script3], see error log for details
    • Wed Mar 21 12:35:06 MDT 2018:ERROR:An error occurred [No such property: PROPERTIES_TYPE for class: Script4], see error log for details
    • Wed Mar 21 12:35:19 MDT 2018:ERROR:An error occurred [No such property: HTTPREQUEST_TYPE for class: Script5], see error log for details

     

    This is the code I am running, am i doing something wrong?

     

    import  com.eviware.soapui.config.TestStepConfig
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
    import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestStepFactory
    
    def suite = testRunner.testCase.testSuite
    def newTestCase = suite.addNewTestCase("NewTestCase")
    def newTestStep = newTestCase.addTestStep(REQUEST_TYPE, "NewTestStep" )
  • jkrier's avatar
    jkrier
    Regular Contributor

    So I decided to try

     

     

    import  com.eviware.soapui.config.TestStepConfig
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
    import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestStepFactory
    
    def suite = testRunner.testCase.testSuite
    def newTestCase = suite.addNewTestCase("NewTestCase")
    def newTestStep = newTestCase.addTestStep("request", "NewTestStep" )

     

    I used REQUEST_TYPE because I had found some examples where people used HTTPREQUEST_TYPE and PROPERTIES_TYPE

     

    That worked, kind of. It gave me a prompt to pick the operation. So then I tried doing something like this

     

     

    import  com.eviware.soapui.config.TestStepConfig
    import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase
    import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestStep
    import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestStepFactory
    
    def suite = testRunner.testCase.testSuite
    def newTestCase = suite.addNewTestCase("NewTestCase")
    def newTestStep = newTestCase.addTestStep("request", "NewTestStep", "https://myendpoint.com", "myOperation")

     

    This created the new test case but without a test step, it threw no error. So I guess if you got any ideas, I need to pull in an existing operation from whatever interface it exists in. I'm going to look around and see if I can figure it out. If I do I will reply back to let you know. If you can help that would be great.