I am using jmeter for testing the performance of a mobile appication which is using IBM Worklight. I am getting 3 dynamic values which comes as a string and i need to handle these values. i trie reular expression extractor but it didnt work. Can any one help me to find out a solution. Dyanamic values are
["{\"jsessionid\":\"0000Mhn7GqWMU1P7Xi9dpJ7mgFb\",\"mbparam\":\"ZjurDsggbg9CZBgd5miAIHMIH%2B5oC7XdSukctItof7AJnpe8UNhlBsgM%2F8w%3D\",\"MP-AUTH-TOKEN\":\"leXozMVUXFYixuYwxgV58EXuRg1Vd0xtpZeouAMQtk6Pd0I1D618motg\"}"]
Updated
I tried the regular expression you provided but it's also not working.
These are the steps i have performed. Please guide me if i have done anything wrong.
Updated
This is the response i am getting is
{
: "customerName":"abc",
: "homeEmail":"",
: "profileDebitAcc":"01234567",
: "sessKey":"0000V3EgdxpY937GTWQ3yogRLGq",
: "mbParam":"hDurAxWHjPT%2BtB7xEyz7Huu51oDOAH8gyNSWIBnHmA9UWuF0lcHGiOy82S0%3D",
: "responseHeaders":
: {
: : "Content-Language":"en-AU",
: : "Date":"Thu, 12 Nov 2015 05:59:50 GMT",
: : "Content-Length":"6759",
: : "Expires":"0",
: : "Content-Type":"text/html; charset=ISO-8859-1",
: : "X-Powered-By":"Servlet/3.0",
: : "Cache-Control":"no-cache",
: : "Pragma":"no-cache"
: },
: "AuthToken":"AHWXZlUt6Rupm1FeBWGu2TEVHZemZwVGbmwmpVxXJR7TMhCA8pWN96ae",
: "statusCode":200,
:
I need to extract sesskey, mbParam and AuthToken values and send them as list in the next request body.
In the request these values are displayed as
["{\"jsessionid\":\"0000gPQCV4FJ1NQvB8d4Ifd_P9I\",\"mbparam\":\"hDu7DhU%2FjA81TEjwbREmytgqIItmUS4b6rhEojYtcalv0PUs6iaewmtZu6U%3D\",\"MP-AUTH-TOKEN\":\"4fU7Bg20sRRUikHnzmZKcC4ZPyCjVxJnmm7QMnSm6mfT7GlqnySQS2YP\"}"]
How to handle these values?
Use the following Regular Expression Extractor configuration:
Reference Name: anything meaningful, i.e. dynamicvalues
Regular Expresssion:
\["\{\\"jsessionid\\":\\"(.+?)\\",\\"mbparam\\":\\"(.+?)\\",\\"MP-AUTH-TOKEN\\":\\"(.+?)\\"\}"\]
Template: $1$$2$$3$
Refer Extracted values as:
${dynamicvalues_g1} - for jsessionid
${dynamicvalues_g2} - for mbparam
${dynamicvalues_g3} - for MP-AUTH-TOKEN
While developing your regular expression remember that you need to escape the following characters with a backslash:
[
{
\
}
]
Other special characters which need escaping are: .^$*+?()|
References:
Regular Expressions page of JMeter's User Manual
PCRE Regex Cheatsheet
Using RegEx (Regular Expression Extractor) with JMeter
jMeter - Regular Expressions
Related
I am trying to bulk edit one entity called issues, I call GetIssues API and via json extractor, get all issueId's in variable "issueIds"
json extractor to extract issueIds
Now I want to pass these Ids in other api bulk edit issues, If I directly use these array in next API, I get below error:
{"details":"Unexpected token $ in JSON at position 19","metadata":{}}
So I used to below code in Beanshell Post processor:
var mylist;
props.put("mylist", new ArrayList());
log.info("Detected " + vars.get("issueIds_matchNr") + " issueIds");
for (int i=1; i<= Integer.parseInt(vars.get("issueIds_matchNr")); i++) {
log.info("IDs # " + i + ": " + vars.get("issueIds_" + i));
props.get("mylist").add('"' + vars.get("issueIds_" + i) + '"' );
}
log.info(props.get("mylist").toString());
var issueIdList;
vars.put("issueIdList", props.get("mylist").toString());
log.info(vars.get("issueIdList"));
In my next api call if I pass issueIdList variable, then this works fine in jmeter.
sample variable values in debug sampler are like:
issueIdList=["555bcfc2", "33974d2c", "e58db1d6"]
issueIds_1=555bcfc2
issueIds_2=33974d2c
issueIds_3=e58db1d6
issueIds_matchNr=3
Problem I am facing if I convert my jmx2yaml and tried to run this file with
bzt issues.yml
then while executing above shell script, these issueIds_matchNr, issueIds_3 are not detected, I get below error;
2022-05-29 08:26:10,785 INFO o.a.j.e.J.JSR223PostProcessor: Detected null issueIds
2022-05-29 08:26:10,795 ERROR o.a.j.e.JSR223PostProcessor: Problem in JSR223 script, JSR223PostProcessor
javax.script.ScriptException: Sourced file: eval stream : Method Invocation Integer.parseInt : at Line: 4 : in file: eval stream : Integer .parseInt ( vars .get ( "issueIds_matchNr" ) )
Target exception: java.lang.NumberFormatException: null
in eval stream at line number 4
at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:87) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
My Yaml script is:
- extract-jsonpath:
issueIds:
default: NotFound
jsonpath: $..id
follow-redirects: true
jsr223:
- compile-cache: true
execute: after
language: beanshell
parameters: issueIds
script-file: script.bsh
label: Get Issue Id's
method: GET
url: https://${BASE_URL1}/${PROJECT_ID}/issues?limit=5&sortBy=-displayId&filter%5Bvalid%5D=true
You're missing one important bit: setting the Match Nr in your Taurus YAML
The correct definition of the JSON Extractor would be something like:
extract-jsonpath:
issueIds:
jsonpath: $..id
match-no: -1 #this is what you need to add
Also be informed that starting from JMeter 3.1 it's recommended to use Groovy as the scripting language so consider migrating, it will be as simple as removing the first line from your script.bsh
I have the follow Json:
{
"tipopersona": "M",
"regimen": "36",
"periodicidad": "Y",
"ejercicio": "2020",
"periodo": "035",
"periodoDesc": "Del Ejercicio",
"tipoDeclaracion": "001",
"tipoDeclaracionDesc": "Normal",
"tipoComplementaria": "",
"tipoComplementariaDesc": "",
"cmbISSIF": "1",
"obligaciones": [ "0101", "0192" ],
"preguntasPerfil": { "178": "1" },
"rfc": "AAC920317CM8",
"rechazopropuesta": false,
"fechaVencimiento": "2021-03-31T00:00:00",
"errores": true,
"xmldeclaracion": ""
}
I need to remove the blanks and newlines from the Json like the following example in JSR223 or Beanshell:
{"tipopersona":"M","regimen":"36","periodicidad":"Y","ejercicio":"2020","periodo":"035","periodoDesc":"DelEjercicio","tipoDeclaracion":"001","tipoDeclaracionDesc":"Normal","tipoComplementaria":"","tipoComplementariaDesc":"","cmbISSIF":"1","obligaciones":["0101","0192"],"preguntasPerfil":{"178":"1"},"rfc":"AAC920317CM8","rechazopropuesta":false,"fechaVencimiento":"2021-03-31T00:00:00","errores":true,"xmldeclaracion":""}
I'm using the follow code:
String data = vars.get("json");
data = data.replaceAll(" ", "");
data = data.replaceAll(System.getProperty("line.separator"),"");
vars.put("data", data);
But in the Debug Sampler it still shows the spaces:
enter image description here
Since JMeter 3.1 you should be using JSR223 Test Elements and Groovy language for scripting
Groovy has built-in JSON support
Assuming above points you can achieve your goal using the following one-liner:
vars.put('data', (new groovy.json.JsonBuilder(new groovy.json.JsonSlurper().parseText(vars.get('json'))).toString()))
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It
Easiest way is to use a JSON extractor on json variable as a child to the sampler.Your code might replace all the spaces in json key and value also.
came across a similar question here which wasn't truly addressed - https://github.com/nightwatchjs/nightwatch/issues/1911
You cannot do what #beatfactor suggested with the above example, the port is in the middle i.e. "selenium_host" : "us1.appium.testobject.com:443/wd/hub",
I'm facing a similar problem right now, how do I provide arguments so it attempts to hit a host like the above? Currently, my failing options are providing no port which defaults to 4444 or providing a port which results in attempting to hit us1.appium.testobject.com/wd/hub:443
The desired result is :
"selenium_host" : "us1.appium.testobject.com:443/wd/hub",
TLDR - How do you provide a port in the middle of your selenium host argument given the port is always appended to the end and if you don't provide one, a default is used?
Just define your selenium_port upstream, in the declaration section and use a Template Literal:
const selenium_port = '443';
"test_settings" : {
"default" : {
"launch_url" : "http://test.com",
"selenium_port" : selenium_port
"selenium_host" : `us1.appium.testobject.com:${selenium_port}/wd/hub`,
"silent" : true,
"screenshots" : {
"enabled" : true,
"path" : "screenshots"
}
},
Hope I understood correctly. Cheers!
I get the impression that there might be a way to write to the systemd journal, json data directly without first converting it to the format the sd_journal* functions expect. Is this possible or not?
My suspicion is because of some comments about an inbuilt json parser. However the man pages suggest otherwise.
Also, I note that if your write to stdout in the format
<priority> message
The priority will end up in the PRIORITY="priority" field and message will end up in MESSAGE="message" field. But can other structured field data be input?
Note: The man pages do not talk about the last feature I mention. So I wouldn't be surprised if they are slightly out of date which is why I am asking.
journald doesn't accept arbitary JSON. Just Key/Value pairs. So it's not possible to send nested data structures. You can send data directly via the Unix Domain socket:
echo -e "MESSAGE=Hello\nFOO=BAR\nMY_ID=12345\n" |socat - UNIX-SENDTO:/run/systemd/journal/socket
results in:
{
"__CURSOR" : "s=46dc1bd66d0e4a48a6809e45228511e2;i=84cc;b=fd9144999d6846c8827d58f56c2635db;m=850161136;t=55669a307fdd6;x=887a021a37840789",
"__REALTIME_TIMESTAMP" : "1502386590318038",
"__MONOTONIC_TIMESTAMP" : "35703361846",
"_BOOT_ID" : "fd9144999d6846c8827d58f56c2635db",
"_TRANSPORT" : "journal",
"_UID" : "1001",
"_GID" : "1001",
"_CAP_EFFECTIVE" : "0",
"_SYSTEMD_OWNER_UID" : "1001",
"_SYSTEMD_SLICE" : "user-1001.slice",
"_SYSTEMD_USER_SLICE" : "-.slice",
"_MACHINE_ID" : "6e7b40640bf6473189165f19f8be2536",
"_HOSTNAME" : "samson",
"_SYSTEMD_UNIT" : "user#1001.service",
"_SYSTEMD_INVOCATION_ID" : "e5ed32fbb1004545b1ddf73a0d928d87",
"_SYSTEMD_CGROUP" : "/user.slice/user-1001.slice/user#1001.service/gnome-terminal-server.service",
"_SYSTEMD_USER_UNIT" : "gnome-terminal-server.service",
"_COMM" : "socat",
"_EXE" : "/usr/bin/socat",
"_CMDLINE" : "socat - UNIX-SENDTO:/run/systemd/journal/socket",
"FOO" : "BAR",
"MESSAGE" : "Hello",
"MY_ID" : "12345",
"_PID" : "19868",
"_SOURCE_REALTIME_TIMESTAMP" : "1502386590317991"
}
libxml2 (for C) is not preserving empty elements in their original form on a save. It replaces <tag></tag> with <tag/> which is technically correct but causes problems for us.
xmlDocPtr doc = xmlParseFile("myfile.xml");
xmlNodePtr root = xmlSaveFile("mynewfile.xml", doc);
I've tried playing with the various options (using xlmReadFile) but none seem to affect the output. One post here mentioned disabling tag compression but the example was for PERL and I've found no analog for C.
Is there an option to disable this behavior?
Just found this enum in the xmlsave module documentation:
Enum xmlSaveOption {
XML_SAVE_FORMAT = 1 : format save output
XML_SAVE_NO_DECL = 2 : drop the xml declaration
XML_SAVE_NO_EMPTY = 4 : no empty tags
XML_SAVE_NO_XHTML = 8 : disable XHTML1 specific rules
XML_SAVE_XHTML = 16 : force XHTML1 specific rules
XML_SAVE_AS_XML = 32 : force XML serialization on HTML doc
XML_SAVE_AS_HTML = 64 : force HTML serialization on XML doc
XML_SAVE_WSNONSIG = 128 : format with non-significant whitespace
}
Maybe you can refactor your application to use this module for serialization, and play a little with these options. Specially with XML_SAVE_NO_EMPTY.
Your code may look like this:
xmlSaveCtxt *ctxt = xmlSaveToFilename("mynewfile.xml", "UTF-8", XML_SAVE_FORMAT | XML_SAVE_NO_EMPTY);
if (!ctxt || xmlSaveDoc(ctxt, doc) < 0 || xmlSaveClose(ctxt) < 0)
//...deal with the error