Forum Discussion

OceanMachine's avatar
OceanMachine
New Contributor
15 years ago

Command line or batch option for loading request XML?

Hi All,

Firstly, I have tried to search the forums for answers to this already, but I am not sure I am describing what I mean in the correct terminology, and have not managed to find an answer to my problem.  Apologies if this has already been answered!

You will have to bear with me, as I am quite new using soapUI.

I have a project file that I can open in soapUI 3.0.1, and a binding set up already with a request underneath that.  All the endpoints have been setup so that I can just paste an XML request (SOAP envelope) into the request window, run it and get a response.  This is working fine.  I am using this to manually send requests to a specific endpoint when required after editing the XML accordingly.

However, I am now in the situation whereby I have lots of requests to run (about 1000+) where I have the SOAP Envelope XML already generated with the correct values in it (in both separate files per-request, and also all in one big file).  I am wondering if there is a way to send all of these individual requests without having to manually copy-and-paste each one individually into the request editor and click the 'submit' button?

I don't mind if this is via the command line, or via the GUI, but I can't work out how to achieve this...

I have tried putting multiple requests in the request editor window (one after another), but only the first request seems to be processed each time (looking at the results pane anyway).

Is there a way to specify multiple requests to run in this way?  Or can I pass a parameter to one of the command line tools that either has a file name (containing my request XML to submit) or contains the actual XML to run in a string, or something like that?

Sorry for all the questions, but it seems like there must be a way to process requests in a batch, but I just can't find it.

The other thing I have tried is to set up a parameterised test-case with a CSV file supplying the data... the only problem is that there can be multiples of certain elements within the requests, and I am not sure how I can tell the test case what I want to do (i.e. for each x in y, generate another chunk of xml)...

I am hoping my question/plea for help is worded correctly and that you can tell what I am wanting to do.

Sorry if this has been answered a million times, but I did search and couldn't find it.

Thanks in advance!
  • Thanks for the reply.  I spent quite a bit of time looking at this, and found I understood what I was trying to achieve a little bit better.

    I wrote a groovy script (which I'm sure isn't the most elegant code, and I'm sure there is probably a better way to do this) and I thought I would share it.

    This script is designed to pull XML from a file, copy it into a Request, and submit the request.  It will then loop through the whole file doing the same until it reaches the end.

    The XML file should have requests with blank lines between whole requests (blank lines denote the end of the request).  The script will concatenate lines together until it reaches a blank line in the file, then it will submit that concatenated string via the request inside the test case, clear the variable, and start concatenating again, etc.

    For some reason this don't work using the "right click > Launch TestRunner" option, but it works if you open the Groovy Script editor for the test step and use the "Run this script in a separate thread using a mock testRunner and testContext" button.

    Obviously change the name of your Request step to match what you have.  I hope this helps someone else.

    import javax.swing.JFileChooser

    //create the file chooser object with prompt
    def fc = new JFileChooser(dialogTitle:"Choose input XML file")

    // create the filter for "*.xml" files and set the default directory
    fc.addChoosableFileFilter(new fileFilter())
    fc.setCurrentDirectory(new File("C:\\"))

    // open the 'chooser'
    if (fc.showOpenDialog() == JFileChooser.APPROVE_OPTION)
    {
    // get the chosen file and path
    File file = fc.getSelectedFile()
    filename = file.getAbsolutePath()

    // init some vas
    xmlLine = ""
    number = 1
    totalnumber = 0

    // count the total number of lines in the file
    file.eachLine{totalnumber++}

    // for debugging
    log.info("total number of lines in " + filename + " is " + totalnumber)

    // concatenate the lines until a blank line is found and then run the XML
    file.eachLine
    { line ->
    log.info("processing line " + number + " of " + totalnumber)
    if ( line ) // if the line was not blank
    {
    if ( xmlLine != "" )
    xmlLine += "\n"

    xmlLine += line // concatenate the line
    }
    else if (xmlLine) // as long as the concat string is not empty, run it
    {
    log.info("submitting request for line number " + number)
    testRunner.testCase.getTestStepByName("despatchShippingGroup - Request 1").getProperty("request").setValue(xmlLine)
    testRunner.runTestStepByName("despatchShippingGroup - Request 1")
    log.info("submit complete for line number " + number)
    xmlLine = "" // clear the concat var
    }

    number++ // keep track of current line being processed
    }

    // deal with the last line in the file (would not run in the above if last line was not blank)
    if ( xmlLine != "" )
    {
    log.info("submitting request for line number " + number)
    testRunner.testCase.getTestStepByName("despatchShippingGroup - Request 1").getProperty("request").setValue(xmlLine)
    testRunner.runTestStepByName("despatchShippingGroup - Request 1")
    log.info("submit complete for line number " + number)
    }
    }
    else // if user cancels the file choose dialog, do nothing.
    {
    log.info("File chooser cancel button clicked")
    return
    }

    // class for file filter
    class fileFilter extends javax.swing.filechooser.FileFilter
    {
    public boolean accept(File file)
    {
    if (file.isDirectory()) { return true }
    String filename = file.getName()
    return filename.endsWith(".xml")
    }

    public String getDescription() { return "*.xml" }
    }