Jmeter 2.9
I am using Regex Extractor to extractor to extract a list of ids from a response message and write them to a variable idList.
Using beanshell, I want to extract multiple random items from the list.
If n is my random position in the list, then I am trying to extract the value from the idList using
String id = "${idList_" + n + "}";
s = ${__V(id)};
If n is 7 then this returns ${idList_7} rather than the value at idList_7.
I have also tried
String id = "idList_" + n;
s = ${__V(id)};
but this returns idList_7 rather than the value.
I have also tried using *__eval*.
Can yo help please?
You need to call a pre-defined variable vars
For example if you have a variable called idList_7 which contains some value you can access the value using following Beanshell code
String s = vars.get("idList_7");
or if you want to use concatenation
int seven = 7;
String s = vars.get("idLst_" + seven);
See How to use Beanshell guide for more detailed explanation on JMeter components which are exposed to Beanshell.
Related
Whatever may to the total number of matching outcomes
If your variable is a use __V for getting last occurrence using
${__V(a_${a_matchNr})}
or __evalVar
${__evalVar(a_${a_matchNr})}
a_matchNr return last number
refName_matchNr - the number of matches found; could be 0
As per Regular Expression Extractor documentation:
If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:
refName_matchNr - the number of matches found; could be 0
refName_n, where n = 1, 2, 3 etc. - the strings as generated by the template
refName_n_gm, where m=0, 1, 2 - the groups for match n
refName - always set to the default value
refName_gn - not set
So the total number of matches is being stored in ${refName_matchNr} JMeter Variable
If you want to get the last match dynamically you can use __V() function like:
${__V(refName_${refName_matchNr})}
Replace refName with your own JMeter Variable reference name
More information: Here’s What to Do to Combine Multiple JMeter Variables
I need to evaluate the output to see if it starts with a specific sequence.
For example if Cat1 = (A)
I want to verify that the entry begins with the value of Cat1 and can contain any text after it. If so then to output that entry.
I don't exactly know how to use wildcards in conjunction with the variable to allow entries such as
(A) First assignment
(A) Second assignment
to be selected and then to be transferred.
The portion that is in question is the following in my code:
if(assign.title == ){
SpreadsheetApp.openByUrl(url).getSheetByName(shet).appendRow([assign.title, marks.assignedGrade,
assign.maxPoints]);}
}
Your issue can be solved by using Regular Expressions which essentially are special text strings used to describe a search pattern.
Therefore, if you want to search for the entries which begin with (A) and appendRow() like you mentioned above, you should use the following code snippet:
function theFunction() {
var ss = SpreadsheetApp.openByUrl("YOUR_URL").getSheetByName("YOUR_SHEET_NAME");
var regEx = /((A)).*/;
//Getting the assign & marks variables
if (assign.title.match(regEx))
appendRow([assign.title, marks.assignedGrade, assign.maxPoints]);
}
The regular expression here is represented by the var regEx = /((A)).*/; which searches for a string to see if it starts with the (A) string.
Furthermore, I suggest you take a look at these links since they might be of help:
Syntax for Regular Expressions;
Regular Expressions Tester.
My Json response is:
"return":"/info?booking=KD6YGS4L8I"
Now I want to extract value after "=" (ex:"KD6YGS4L8I").
I used Regular Expression extractor:
- Regular Expression: "return":"(.+?)"
- Template: $1$
- Match No: -1
And output is:
"return":"/info?booking=KD6YGS4L8I"
Now I want to get string KD6YGS4L8I.
You can use the following regular expression: booking=(.+?)", with template $1$. Match Number (n) depends on your needs:
n > 0: matches the given occurence number,
n == 0: matches a random occurence,
n < 0: matches all occurences, and organizes them with subvariables.
See Regular Expression Extractor on JMeter website.
I suggest you to take a look at the following guides:
Regular Expressions,
how to use JMeter Regexp Extractor.
Add a Beanshell sampler as a sibling to your Regular Expression Extractor with the below code:
//Assuming your regular expression extractor variable is RegExpResult
String regExpResponse= ${RegExpResult};
String[] result= regExpResponse.split("=");
result[1].replaceAll("\"", "");
vars.put("BookingValue",result[1]);
Now BookingValue variable contains - KD6YGS4L8I
You can find the same issue been resolved in stackoverflow:
JMeter - using substring on a user variable
Hope this helps! :)
I have an SSIS package which loops over an array of dates. On each iteration I would like to append the current date to a string to get a full string of all the dates iterated.
What I did was to make an expression where: dateconcatvariable + ", " +currentdatevariable
However, dateconcatvariable is resetting on every iteration of the for loop and so in the end I end up with the last date iterated over instead of all the dates.
the variable is a package level variable.
Any ideas on how to get a concatenation to happen on SSIS?
Thanks!
1. Create a string variable #User::var
2. Use an Expression component and set the expression to #User::var = #User::var + (WSTR, 15)#User::yourdatevar
This should give you the general idea.
I am using selenium and I am using xpath in target value .
I have a table and I need to count the number of rows.
For example I have an X path starting from //tr[2]/td/span/input to //tr[10]/td/span/input. Now I want to count the number of X path count by VerifyXpathCount.
I need to supply a regex in the Target field of Selenium like //tr[(*)]/td/span/input
I am not able to apply such regex so I need to add some regex.
How do I do this?
int cnt = selenium.getXpathCount("//tr[/td/span/input]");
//to deal with all element
for(int i=0;i<cnt;i++){
String loc = "//tr["+i+"]/td/span/input";
//use loc
}
in case if you want to find unique element than you can use other conditions with //tr[/td/span/input] instead of looping
try //tr[./td/span/input] or //tr[//td/span/input] to get/verify xpath count