Am 23.12.20 um 16:05 schrieb Nikola Aleksic:
> Hello,
>
> I was trying to list all parameters in HTTP Sampler including ones in
> File upload tab using the following code and remove the desired one in
> File upload tab, but File upload tab parameters FrontsideImage and
> BacksideImage are not listed:
>
> import org.apache.jmeter.config.Arguments;
>
> Arguments args = sampler.getArguments();
> Iterator it = args.iterator();
>
> while (it.hasNext()) {
>     def argument = it.next();
>     if (argument.getStringValue().contains('somevalue')) {
>         args.removeArgument(argument.getName());
>     }
>     log.warn(argument.getName())
> }
>
> Code source: https://stackoverflow.com/a/40918642
>
> Can someone provide a corresponding method to list Files upload
> parameters as well and remove desired one as per its value? Check jmx
> example in the attachment. Set log level to WARN, Run test and check
> the logs.

The files are hidden away under sampler.getHTTPFiles() it returns an
array, so probably want to change it to a modern collection first. Then
remove the empty elements, or whatever you want to do. Last you convert
it back to an array and store it with sampler.setHTTPFiles().


In a JSR-223 PreProcessor with Groovy that would be

def files = new ArrayList(Arrays.asList(sampler.HTTPFiles))
log.info("files: " + files)

files.removeIf(f -> f.path == "something" && f.paramName == "nothing" ||
f.mimeType == "text/json")

log.info("files: " + files)

sampler.HTTPFiles = files.toArray()


The log.info(...) is added to show, what has been done by the pre-processor.

The stuff after 'f -> ' is the interesting part, as it is the predicate,
which decides, which files should be removed from the collection.

Felix

>
> Regards,
> Nikola
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]

Reply via email to