Forum Discussion

morciani's avatar
morciani
Occasional Contributor
15 years ago

programatically inserting Test Requests into an existing Test Case

Hello,

I have developed a suite of data driven test cases in soapUI that are working very nicely.  I'm able to push large volumes of requests to my service, and monitor the results to be sure things are behaving as expected.

On any given day, I may push through 15,000 service requests, and maybe for 14,950 of them, the expected response is returned.  There are maybe 50 or so that do not result in the expected response.  This is fine, and there is most likely a business reason for why the response has changed.  Here is what I would like to be able to do:

1.  Create a 'target' soapUI Test case, say 'TestCase_Target_UnexpectedResults_04-19-2010' that is empty / has no Test Steps.  This Test Case would be within the same TestSuite as my data driven test case. (I would create this test case manually)

2. Run my data driven Test Case, say 'TestCase_DataDriven' (this Test case references 3 operations within 1 WSDL).  As responses are returned, I would like to programatically insert Test Request Test Steps into the 'TestCase_Target_UnexpectedResults_04-19-2010' Test Case that I created in Step 1, for the 50 or so responses that did not contain the expected results. 

Basically, I would like to programatically insert Test Requests into an existing Test Case that contains these 50 or so troublesome requests from Step 2.  The idea is that I can pass off this 'TestCase_Target_UnexpectedResults_04-19-2010' test case to another person who will investigate the reasons for the unexpected / failed results.  I don't want the person to whom I am passing these requests to have to mess around with my data driven tests or anything like that- I just want to be able to quickly provide them with a list of requests that they can submit to the service individually as they troubleshoot. 

Note:  I do have the code below that works nicely.  This dumps out each request + response from my data driven test case to an external directory.  Essentially, I would like to do something very similar.  The only difference is that I want to dump the requests into a Test Case that I've already created.

Code snippet:

//Ouput the request and response to a local folder (${Properties#Location}
def name = context.expand( '${DataGen#CompanysQuoteNumber}' )
def location = context.expand( '${#TestCase#Location}' )

def getResponseFilename(name) {
  date = new Date()
  dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")
  shortDate = dateFormat.format(date)
  respFilename = name + "_Request1_TPPR_Rs_" + shortDate + ".xml"
}

def getRequestFilename(name) { 
  reqFilename = name + "_Request1_TPPR_Rq_" + shortDate + ".xml"
}
 
def file = new PrintWriter (location + getResponseFilename(name))
//def Response = testRunner.testCase.testSteps["TestRequest_TPPR"].testRequest.response.contentAsString
def Response = context.expand( '${TestRequest_TPPR#Response}' )

file.println(Response)
file.flush()
file.close()

def file2 = new PrintWriter (location + getRequestFilename(name))
def Request = context.expand( '${TestRequest_TPPR#Request}' )
file2.println(Request)
file2.flush()
file2.close()

2 Replies

  • morciani's avatar
    morciani
    Occasional Contributor
    Hello,,

    Me again....I've found this post to be useful:

    http://www.eviware.com/forums/index.php?topic=1304.0

    I am getting closer.  I used this methodology to "auto create" my target TestSuite and TestCase- I added the code to the Setup Script withn my data driven Test Case.  My soapUI project now looks like this:

    Project
        TestSuite_DataDriven
            TestCase_DataDriven_Scenario1
            TestCase_DataDriven_Scenario2
            TestCase_DataDriven_Scenario3
        TestSuite_Target_2010-04-19 (created by my setup script in TestCase_DataDriven_Scenario1 above)
            TestCase_Target_2010-04-19_15.09.11 (created by my setup script in TestCase_DataDriven_Scenario1 above)

    I have the following code within a script assertion (TestRequest) inside of 'TestCase_DataDriven_Scenario1':
    ________________
    //If we do indeed want to create a TestSuite, TestCase, and the individual TestSteps (requests), proceed
    if ( context.expand( '${#Project#TestSuiteName_ToCreate}' ) != "" ) {
    //Gather all the information we'll need to create the request
    def date = new Date()
    def dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")
    def shortDate2 = dateFormat.format(date)
    def name = context.expand( '${DataGen#CompanysQuoteNumber}' )
    def testStepName  = name + "_Request1_TPPR_Rq_" + shortDate2;
    def interfaceName  = context.expand( '${#Project#InterfaceName}' );
    def operationName = context.expand( '${#Project#OperationName_TPPR}' );
    def targetTestSuite = context.expand( '${Properties#TestSuiteName_AssignedByScript}' );
    def targetTestCase = context.expand( '${Properties#TestCaseName_AssignedByScript}' );
    def request = context.expand( '${TestRequest_TPPR#Request}' )
    def response = context.expand( '${TestRequest_TPPR#Response}' )

    // Get the WSDL operation name
    def op = testRunner.testCase.testSuite.project.interfaces[interfaceName].operations[operationName];

    //Gather what we'll need to create the request
    def config = com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory.createConfig( op, testStepName );

    //Add a new TestStep to the TestCase
    def newTestStep = testRunner.testCase.testSuite.project.testSuites["TestSuite_2010_04-19"].testCases["TestCase_2010-04-19_15.09.11"].addTestStep ( config );

    //set the request & response for the new TestStep
    newTestStep.setPropertyValue("request", "request");
    newTestStep.setPropertyValue("response", "response");

    // read and log the request
    def testStepRequest = newTestStep.getPropertyValue("request");
    log.info(testStepRequest);
    }
    _________

    No luck just yet.  Perhaps someone could provide an example of how to create a TestRequest type TestStep using a script assertion?
  • hi,
    I would like to know if instead of reading the response as a string (contentAsString) is there any way read the content as xml