You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by ohaya <oh...@yahoo.com.INVALID> on 2022/07/26 02:55:00 UTC

How to replace a string in a variable that came from a CSV Data Config?

Hi,

In my JMeter test plan, I have two CSV Data Config elements.  

- CSV Data Config-element-requestBodies: variables: requestBody

- CSV Data Config-element-subject: variables: subjectDn

The requestBody variable contains an XML request, with a placeholder string and I want to replace that placeholder with the contents of the subjectDn variable, and then use the modified requestBody variable in the HTTP Request element.  In other words:

1) Replace the placeholder string in the ${requestBody} with the value in the ${subjectDn}, then

2) Use the ${requestBody} in the HTTP Request

How can I do that?  What is the easiest/least overhead way of doing that?

Thanks,
Jim





---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org


Re: SOLVED was Re: How to replace a string in a variable that came from a CSV Data Config?

Posted by Dmitri T <gl...@live.com>.
Wrap your *|${requestBody}|* into __eval() function 
<https://jmeter.apache.org/usermanual/functions.html#__eval>, it will 
allow JMeter to resolve JMeter Functions and Variables 
<https://jmeter.apache.org/usermanual/functions.html> which are present 
as "placeholders" in the CSV file to their respective values.

|*${__eval(${requestBody})}* |

Also if you consider scripting to accomplish your requirements be 
informed that starting from JMeter 3.1 it's recommended to use JSR223 
Test Elements and Groovy language 
<https://jmeter.apache.org/usermanual/best-practices.html#bsh_scripting>. 
More information: Apache Groovy: What Is Groovy Used For? 
<https://www.blazemeter.com/blog/apache-groovy>

On 7/26/2022 6:52 AM, ohaya wrote:
>   I was able to get this woring by using a Beanshell pre-processor and some Java code that does var.get() and then Java String replaceall() and then var.put().
>
>
>       On Monday, July 25, 2022, 11:29:41 PM EDT, ohaya<oh...@yahoo.com>  wrote:
>   
>    I tried using __evalVar:
>
> https://am.net/lib/tools/NetworkManagement/apache-jmeter-2.8/printable_docs/usermanual/functions.html
>
> where I had the following in the string from the CSV Data Config-element-requestBodies:
>
> <Request ...>{name=${subjectDn}+...
>
> But it looks like the __evalVar is NOT replacing the ${subjectDn} variable with the value from the CSV Data Config-element-subject: variables :(...
>
> Jim
>
>
>       On Monday, July 25, 2022, 10:55:10 PM EDT, ohaya<oh...@yahoo.com>  wrote:
>   
>   Hi,
>
> In my JMeter test plan, I have two CSV Data Config elements.
>
> - CSV Data Config-element-requestBodies: variables: requestBody
>
> - CSV Data Config-element-subject: variables: subjectDn
>
> The requestBody variable contains an XML request, with a placeholder string and I want to replace that placeholder with the contents of the subjectDn variable, and then use the modified requestBody variable in the HTTP Request element.  In other words:
>
> 1) Replace the placeholder string in the ${requestBody} with the value in the ${subjectDn}, then
>
> 2) Use the ${requestBody} in the HTTP Request
>
> How can I do that?  What is the easiest/least overhead way of doing that?
>
> Thanks,
> Jim
>
>
>
>
>      

SOLVED was Re: How to replace a string in a variable that came from a CSV Data Config?

Posted by ohaya <oh...@yahoo.com.INVALID>.
 I was able to get this woring by using a Beanshell pre-processor and some Java code that does var.get() and then Java String replaceall() and then var.put().


     On Monday, July 25, 2022, 11:29:41 PM EDT, ohaya <oh...@yahoo.com> wrote:  
 
  I tried using __evalVar:

https://am.net/lib/tools/NetworkManagement/apache-jmeter-2.8/printable_docs/usermanual/functions.html

where I had the following in the string from the CSV Data Config-element-requestBodies:

<Request ...>{name=${subjectDn}+...

But it looks like the __evalVar is NOT replacing the ${subjectDn} variable with the value from the CSV Data Config-element-subject: variables :(...

Jim


     On Monday, July 25, 2022, 10:55:10 PM EDT, ohaya <oh...@yahoo.com> wrote:  
 
 Hi,

In my JMeter test plan, I have two CSV Data Config elements.  

- CSV Data Config-element-requestBodies: variables: requestBody

- CSV Data Config-element-subject: variables: subjectDn

The requestBody variable contains an XML request, with a placeholder string and I want to replace that placeholder with the contents of the subjectDn variable, and then use the modified requestBody variable in the HTTP Request element.  In other words:

1) Replace the placeholder string in the ${requestBody} with the value in the ${subjectDn}, then

2) Use the ${requestBody} in the HTTP Request

How can I do that?  What is the easiest/least overhead way of doing that?

Thanks,
Jim




    

Re: How to replace a string in a variable that came from a CSV Data Config?

Posted by Felix Schumacher <fe...@internetallee.de>.
The __evalVar should work. How are you calling it?

Given two variables with the following content (YAML like syntax)

body: "Hello, ${subject}!"
subject: "World"

you can render $body as "template" by using ${__evalVar(body)}, which 
should result in "Hello, World!".

Felix

Am 26.07.22 um 05:29 schrieb ohaya:
>   I tried using __evalVar:
>
> https://am.net/lib/tools/NetworkManagement/apache-jmeter-2.8/printable_docs/usermanual/functions.html
>
> where I had the following in the string from the CSV Data Config-element-requestBodies:
>
> <Request ...>{name=${subjectDn}+...
>
> But it looks like the __evalVar is NOT replacing the ${subjectDn} variable with the value from the CSV Data Config-element-subject: variables :(...
>
> Jim
>
>
>       On Monday, July 25, 2022, 10:55:10 PM EDT, ohaya<oh...@yahoo.com>  wrote:
>   
>   Hi,
>
> In my JMeter test plan, I have two CSV Data Config elements.
>
> - CSV Data Config-element-requestBodies: variables: requestBody
>
> - CSV Data Config-element-subject: variables: subjectDn
>
> The requestBody variable contains an XML request, with a placeholder string and I want to replace that placeholder with the contents of the subjectDn variable, and then use the modified requestBody variable in the HTTP Request element.  In other words:
>
> 1) Replace the placeholder string in the ${requestBody} with the value in the ${subjectDn}, then
>
> 2) Use the ${requestBody} in the HTTP Request
>
> How can I do that?  What is the easiest/least overhead way of doing that?
>
> Thanks,
> Jim
>
>
>
>
>    

Re: How to replace a string in a variable that came from a CSV Data Config?

Posted by ohaya <oh...@yahoo.com.INVALID>.
 I tried using __evalVar:

https://am.net/lib/tools/NetworkManagement/apache-jmeter-2.8/printable_docs/usermanual/functions.html

where I had the following in the string from the CSV Data Config-element-requestBodies:

<Request ...>{name=${subjectDn}+...

But it looks like the __evalVar is NOT replacing the ${subjectDn} variable with the value from the CSV Data Config-element-subject: variables :(...

Jim


     On Monday, July 25, 2022, 10:55:10 PM EDT, ohaya <oh...@yahoo.com> wrote:  
 
 Hi,

In my JMeter test plan, I have two CSV Data Config elements.  

- CSV Data Config-element-requestBodies: variables: requestBody

- CSV Data Config-element-subject: variables: subjectDn

The requestBody variable contains an XML request, with a placeholder string and I want to replace that placeholder with the contents of the subjectDn variable, and then use the modified requestBody variable in the HTTP Request element.  In other words:

1) Replace the placeholder string in the ${requestBody} with the value in the ${subjectDn}, then

2) Use the ${requestBody} in the HTTP Request

How can I do that?  What is the easiest/least overhead way of doing that?

Thanks,
Jim