In my config file I've set the url rule like this :
<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>
And what happens is:-
controller/action/123 (work)
controller/action/hello (not work)
But it accepts only digit as the parameter.
What I want is that both digit and string should be accepted.
Please help!!!!
The d+ pattern matches numbers 0-9, so it is working as expected. Change the regex pattern to match strings. Try w+.
Change:
<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>
To:
<controller:\w+>/<action:\w+>/<id:\w+>' => '<controller>/<action>
Related
when i try to typetext as string on an input with type=number the browser display different value
var items = ["15300", "06500", "15400","24500","30580","77104","92730"];
const zipcode =items[Math.floor(Math.random()*items.length)];
console.log(zipcode);
return String(zipcode)
}
.typeText(AddressesLocators.txt.txtZipcode,await Utils.getRandomZipcode(),{ replace: Boolean })
This is because when setting the "type" attribute of an HTML input element to "number", the browser expects the entered value to be a valid number and therefore may attempt to convert the entered value to a number.
If you enter a string like "15300" in an input with type="number", the browser will try to convert the string to a number, in which case the resulting value will be 15300. However, if you enter a string like "06500 ", the browser will interpret the value as an octal number and then convert it to decimal, which will result in 3328 instead of 6500.
To avoid this behavior, you can use an input with type="text" instead of type="number" if you want the entered value to be treated as a string. Or, if you need to use type="number", make sure the value you enter is a valid number and does not start with a leading zero, such as "6500" instead of "06500".
I hope this helps.
I have a request that I make in an API using GET
LWP::UserAgent,
the data is returned as JSON, with up to two results at most as follows:
{
"status":1,
"time":1507891855,
"response":{
"prices":{
"nome1\u2122":{
"preco1":1111,
"preco2":1585,
"preco3":1099
},
"nome2":{
"preco1":519,
"preco2":731,
"preco3":491
}
}
}
}
Dump:
$VAR1 = {
'status' => 1,
'time' => 1507891855,
'response' => {
'prices' => {
'nome1' => {
'preco1' => 1111,
'preco3' => 1099,
'preco2' => 1585
},
'nome2' => {
'preco3' => 491,
'preco1' => 519,
'preco2' => 731
}
}
}
};
What I would like to do is:
Take this data and save it in a variable to make a comparison using if with another variable that already has the name stored. The comparison would be with name1 / name2 and if it is true with the other variable it would get preco2 and preco3 to print everything
My biggest problem in the case is that some of these names in JSON contain characters like (TradeMark) that comes as \u2122 (some cases are other characters), so I can not make the comparison with the name of the other variable that is already with the correct name
nome1™
If I could only save the JSON already "converted" the characters would help me with the rest.
Basically after doing the request for the API I want to save the contents in a variable already converting all \u2122 to their respective character (this is the part that I do not know how to do in Perl) and then using another variable to compare them names are equal to show the price
Thanks for the help and any questions please tell me that I try to explain again in another way.
If I understand correctly, you need to get the JSON that you receive in UTF8 format to an internal variable that you can process. For that, you may use JSON::XS:
use utf8;
use JSON::XS;
my $name = "nome1™";
my $var1 = decode_json $utf8_encoded_json_text;
# Compare with name in $name
if( defined $var1->{'response'}->{'prices'}->{$name} ) {
# Do something with the name that matches
my $match = $var1->{'response'}->{'prices'}->{$name};
print $match->{'preco1'}, "\n";
}
Make sure you tell the Perl interpreter that your source is in UTF8 by specifying use utf8; at the beginning of the script. Then make sure you are editing the script with an editor that supports that format.
The function decode_json will return a ref to the converted value. In this case a hash ref. From there you work your way into the JSON.
If you know $name is going to be in the JSON you may omit the defined part. Otherwise, the defined clause will tell you whether the hash value is there. One you know, you may do something with it. If the hash values are a single word with no special characters, you may use $var1->{response}->{prices}->{$name}, but it is always safer to use $var1->{'response'}->{'prices'}->{$name}. Perl gets a bit ugly handling hash refs...
By the way, in JSON::XS you will also find the encode_json function to do the opposite and also an object oriented interface.
I want to import many informations from a CSV file to Elastic Search.
My issue is I don't how can I use a equivalent of substring to select information into a CSV column.
In my case I have a field date (YYYYMMDD) and I want to have (YYYY-MM-DD).
I use filter, mutate, gsub like:
filter
{
mutate
{
gsub => ["date", "[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]", "[0123456789][0123456789][0123456789][0123456789]-[0123456789][0123456789]-[0123456789][0123456789]"]
}
}
But my result is false.
I can indentified my string but I don't how can I extract part of this.
My target it's to have something like:
gsub => ["date", "[0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789][0123456789]","%{date}(0..3}-%{date}(4..5)-%{date}"(6..7)]
%{date}(0..3} : select from the first to the 4 characters of csv columns date
You can use ruby plugin to do conversion. As you say, you will have a date field. So, we can use it directly in ruby
filter {
ruby {
code => "
date = Time.strptime(event['date'],'%Y%m%d')
event['date_new'] = date.strftime('%Y-%m-%d')
"
}
}
The date_new field is the format you want.
First, you can use a regexp range to match a sequence, so rather than [0123456789], you can do [0-9]. If you know there will be 4 numbers, you can do [0-9]{4}.
Second, you want to "capture" parts of your input string and reorder them in the output. For that, you need capture groups:
([0-9]{4})([0-9]{2})([0-9]{2})
where parens define the groups. Then you can reference those on the right side of your gsub:
\1-\2-\3
\1 is the first capture group, etc.
You might also consider getting these three fields when you do the grok{}, and then putting them together again later (perhaps with add_field).
I'm trying to construct json text as show below. But the variables such as $token, $state, $failedServers are not been replaced with its value. Note- I don't want to use any module specifically for this to work, I just want some plain string to work. Can anyone help me ?
my $json = '{"serverToken":"$token", "state":"$state","parameters" :"$failedServers"}';
current output was:
{"serverToken":"$token", "state":"$state","parameters" :"$failedServers"}
needed output format:
{"serverToken":"1213", "state":"failed","parameters" :"oracleapps.veeralab.com,suntrust.com"}
Your variables are not being replaced, because they are inside of a single-quoted string--that is, they are inside a string quoted by ' characters. This prevents variable substitution.
You will also be much better off creating JSON using a JSON library, such as this one. Simply using a quoted string is very dangerous. Suppose your one of your variables ends up containing a special character; you will end up with invalid JSON.
{"serverToken":"123"ABC", "state":"offline", "paramameters":"bugs"}
If your variables come from user input, really bad things could happen. Imagine that $token is set to equal foo", "state":"online", "foo":"bar. Your resulting JSON structure would be:
{"serverToken":"foo", "state":"online", "foo":"bar", "state":"offline" ...
Certainly not what you want.
Possible solutions:
The most blatantly obvious solution is simply not to the ' quote character. This has the drawback of requiring you to escape your double quote (") characters, though, but it's easy:
my $json = "{\"serverToken\":\"$token\", \"state\":\"$state\",\"parameters\" :\"$failedServers\"}";
Another option is to use sprintf:
my $json = sprintf('{"serverToken":"%s", "state":"%s", "parameters":"%s"}', $token, $state, $failedServers);
But by far, the best solution, because it won't break with wonky input, is to use a library:
use JSON;
my $json = encode_json( {
serverToken => $token,
state => $state,
paramaters => $failedServers
} );
I have a problem to extract a value from an HTML response of HTTP request using jmeter.
This source html code to extract from:
<input type="text" name="ifu" size="32" value="1600553" class="champ_texte">
I'm using the following regular expression:
name of reference = ifu
regular expression = //input[#type="text"][#name="ifu"][# size="32"][#value="1600553"][#class="champ_texte"]
There is any problem in my expression.
NB: my html response is an response of an Action struts.
If you are using XPath Extractor to parse HTML response ensure that Use Tidy (tolerant parser) option is CHECKED.
Your xpath query should return value you want to extract.
So to get e.g. 'value' of your 'input' you have to use query like:
//input[#type="text"][#name="ifu"][#class="champ_texte"]/#value
Extracted value (if any) will be stored in jmeter variable pointed in 'Reference Name' field (${ifu} in your case).
You can first test your xpath query using any other tool - Firefox addons at least:
XPath Checker
XPather
XPath Finder
The regular expression could be
input type=\"text\" name=\"ifu\" size=\"32\" value=\"(\\d+)\" class=\"champ_texte
In more details,
String x ="<input type=\"text\" name=\"ifu\" size=\"32\" value=\"1600553\" class=\"champ_texte\">";
Pattern p = Pattern.compile("input type=\"text\" name=\"ifu\" size=\"32\" value=\"(\\d+)\" class=\"champ_texte");
Matcher m = p.matcher(x);
if (m.find())
System.out.println(m.group(1));
If what you want to extract is the value property it is way better to use Css/Jquery Extractor:
http://jmeter.apache.org/usermanual/component_reference.html#CSS/JQuery_Extractor
With config:
Css/Jquery expression : input[name=ifu]
Attrbute: value