Question

I'm very new to JMeter and that's my task:

I have some .xml files i intend to use as consecutive SOAP/XML Requests to a WebService in a single Test.

  1. Can I do this without adding n sampler where n is the number of files? (I can't manage to do this with CSVs)
  2. Is there a way to pass only the directory's name that contains those files?

Thanks in advance

Was it helpful?

Solution

I guess that you can use Module Controller to avoid samplers duplication.

In regards to reading xml file names, you can use Beanshell Sampler to load files into variables and ForEach Controller to iterate through them. Example Beanshell code to store file names in a directory into variables will look as follows:

import java.io.File;

File xmldir = new File("/path/to/your/directory");
{
    int counter = 1;
    for (File xmlfile : xmldir.listFiles())
    {
        if (xmlfile.getName().endsWith(".xml"))
        {
            vars.put("xmlfile_" + counter, xmlfile.getCanonicalPath());
            counter++;
        }
    }
}

It'll produce variables like:

xmlfile_1 = test1.xml
xmlfile_2 = test2.xml
xmlfile_N = testN.xml
etc.

which you will be able to iterate via ForEach Controller configured as follows:

  • Input variable prefix: xmlfile
  • Output variable name: anything meaningful, i.e. currentfile

So you should be able to refer your XML files as ${currentfile} or ${__V(currentfile)} in your SOAP requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top