how to change the comma operator into semicolon in response - scripting

hi my response is having a list of values I can capture that but I need to pass those list with semicolon operator in my next request. how to do that in jmeter .
response is
user defined:
{ 1234, 4568, 7890 }
I have to pass those values in my next request as
user defined:
{ 1234; 4568; 7890 }
like this.
how do I can ? can any one help.

Add JSR223 PostProcessor as a child of the 1st request
Put the following code into "Script" area
vars.put('changedResponse',prev.getResponseDataAsString().replace(",",";"))
where:
vars is a shorthand for JMeterVariables class instance, it provides read/write access to JMeter Variables
prev is a shorthand for SampleResult
So you will be able to access amended value where commas will be changed to semicolons as ${changedResponse} where required.
See Apache Groovy - Why and How You Should Use It article for more information on using Groovy scripting in JMeter tests

Related

Ability to use environmental variables in Feature and Scenario Names

How to append Configuration variable in Feature name or in Scenario name. For Instance need to provide Info in reports based on environment run.
I saw there is an option available to add the Examples variable in Scenario outline name. on a similar note, do we have option to append Environment variable in Feature name?
Yes, in 1.0 onwards - if a variable exists in scope, it will be substituted in the Scenario name using the JS string interpolation syntax.
For example if your karate-config.js is like this:
function fn() {
return { test: 'foo' };
}
It means that the variable test will be available when the Scenario is processed. If not, note that the test will fail.
So if your feature is like this:
Feature:
Scenario: ${test}
* print test
You will see this in the report:
So it is up to you how you set up variables in the configuration init.

How to stop a test after finding specific word in jmeter response?

How can we stop a jmeter test after finding a specific word from json response:
{"code":12345,"data":{"mylist":[{"myid":111,"secId":2,"TypeId":1,"name":"one two three" ,"description":"thats the value"}]}
Put your request under the While Controller
Use the following __jexl3() function as the condition:
${__jexl3("${value}" != "thats the value",)}
Add JSON Extractor as the child of the request and configure it as follows:
Names of created variables: value
JSON Path Expressions: $.data.mylist[0].description
That's it, the While Controller will loop until "description" fields becomes thats the value
Demo:

Can we append URL parameters to an endpoint based on values in a test case?

Is it possible to send input parameters to the chatbot from test cases, both with and without user input? What I have in mind is that I should be able to do this in the test cases:
Test case 1
#me
Hello
INPUT_PARAMETER sttConfidence : 0.58
INPUT_PARAMETER callerCountry : GB
#bot
Hi human! I see that you sent some input parameters. Thank you!
...
...
The input parameters need to be appended to the endpoint, so the URL would look like this:
https://MyChatBotsEndpoint.com/?userinput={{msg.messageText}}&sttConfidence=0.58& callerCountry=GB
The values that we send need to be of type string.
Is this possible to achieve in Botium? And if yes, are there any native tools in Botium that can achieve this, or do we need to develop our own function?
Edit:
This is what happens when I added the piece of code:
Example of how input parameter merges with input message
Ideally I would like it to look like this:
This is what it looks like if I manually send &countryCaller=GB to our endpoint
There is nothing like that included, but with the right combination of a logic hook and the HTTP/JSON request hook it is possible.
The UPDATE_CUSTOM logic hook will copy the parameters from the convo file to the internal Botium message object:
Test case 1
#me
Hello
UPDATE_CUSTOM QUERY_PARAM|sttConfidence|0.58
UPDATE_CUSTOM QUERY_PARAM|callerCountry|GB
#bot
Hi human! I see that you sent some input parameters. Thank you!
...
The SIMPLEREST_REQUEST_HOOK capability will then use the parameters to adapt the request url accordingly with a little Javascript code:
...
"SIMPLEREST_REQUEST_HOOK": "if (msg.QUERY_PARAM) requestOptions.uri = requestOptions.uri + '&' + Object.keys(msg.QUERY_PARAM).map(key => key + '=' + msg.QUERY_PARAM[key]).join('&')",
...
Alternative Approach
If you don't like the SIMPLEREST_REQUEST_HOOK Javascript code, you could also use Mustache templates to add the query parameters to the URL:
...
"SIMPLEREST_URL": "https://MyChatBotsEndpoint.com/?userinput={{msg.messageText}}&sttConfidence={{msg.QUERY_PARAM.sttConfidence}}&callerCountry={{msg.QUERY_PARAM.callerCountry}}"
...
(you will have empty parameters, but you can tune this mustache template as you want to exclude empty parameters).

How to use Global Property name in my JSON input request using SoapUI?

I have a SoapUI project which contains around 60 plus services. Each service requires some input which will be changed for every execution. So I have created certain Global Properties and assign some values to that properties.
I have to use these properties values in my SoapUI request ( i.e. JSON Format request ).
If it is groovy script means, I will use like this.
String HTiC_Username = com.eviware.soapui.model.propertyexpansion.PropertyExpansionUtils.globalProperties['HTiC_Username'].value;
But, how to get the value of the Global Property in the request?
Hope you understand my question. Please provide proper guidance.
Thanks
To dynamically "expand" (i.e. substitute) the value of a property into a test step, the following syntax is used: ${#scope#propertyName}
...where 'scope' refers to the level at which the property has been defined (e.g. Global, Project, TestSuite, TestCase).
So to expand a property named username defined as a Global property, for example, the following code can be used directly within a Request Test Step (e.g within a JSON body, or header value, etc):
${#Global#username}
To access the same property value within a Groovy Test Step, you can use the following syntax:
context.expand('${#scope#propertyName}')
...as in the following example:
context.expand('${#Global#username}')
What we did was the following:
created a test data file to store all the specific input data for the different services (testdata.properties)
Example content of testdata.properties:
Billing_customerID=1234567
OtherService_paymentid=12121212
....
create a SoupUi global parameter (File/Preferences/Global properties): testdata_filepath=C:\...
For specific services we added a Properties test step. You can specify the "Load from" field to our new global parameter: ${#Global#testdata_filepath} Now you can use the Load button to load parameters.
Finally you can reference the parameter in your xml in the following format: ${Properties#Billing_customerID}
Example content of a service with parameter:
...
<BillingCustomerIdentification>
<BillingCustomerID>${#Properties#Billing_customerID}</BillingCustomerID>
</BillingCustomerIdentification>
...
To set up your projects in this manner also helps to automate service tests eg. using Hudson (see my previous SO answer).
If it is too heavy and automation is not a target, you can simply use ${#Global#someinputvariable} format in your xml ;-)

where to see xPath Extractor results in Jmeter

I am new to Jmeter, I want to see the Xpath Extractor generated results.
I have
Reference Name : pt_idx
Xpath query : //patientList/patient/idnetifierList/identifier/text()
Default Value : 0
Please clarify my doubts, can i use Xpath query generated results in Http Request?
Is those result will store in pt_idx variable?
Finally, where can i see the results?
Yes, you can use it in an Http Request, I have previously used several XPath Extractors and been able to use them as variables in subsequent http request using the placeholder notation ${varname} (for you it would be ${pt_idx})
To verify the value of the variable, I could do it via the report by looking at the HTTP Request (as I used the variable to fill a request parameter).
Hope it helps.
Finally, where can i see the results?
Add a Debug sampler by going to the thread group and right clicking Thread group -> add -> sampler -> debug sampler. The debug sampler will give the values that the XPath Extractor retrieves. Simple add a View Results Tree and select the debug sampler and view the Response data tab and the info should be all there.