I have the following xpath match in my soapui test suite ,
//html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/#href[1]
Result :
http://shortness.com:101115/localnewsv1/info
I want the expected result as below (it should take the result from http to till the third /)
http://shortness.com:101115/
I have tried the following xpath combined with regular expression
tokenize(/html/body/div[2]/table/tbody/tr[td/b[text()='NewsV1']]//td[4]/a[1]/#href[1], ' ' )[matches(., 'http://+w[a-zA-Z0-9.]+d{*}+/')
This gives me an invalid expression in the result.if you have idea point the issue or suggest.
Screenshot for the issue
For this markup,
<a href="http://shortness.com:101115/localnewsv1/info"/>
this XPath 2.0 expression (make sure your library supports XPath 2.0),
concat(join(tokenize(/a/#href, '/' )[position() < 4],'/'),'/')
will return
http://shortness.com:101115/
as requested.
I guess that d{*} might have a meaning in some regex dialects but it has no meaning (and is invalid) in the XPath 2.0 regex dialect.
Related
this my xpath
//dns:tbody//dns:td[1][#rowspan="1"]/text()
I want to find a solution how can make the attribute rowspan #rowspan=" only number " accept just number
I'm looking for solution regular expression in XPath 1.0
Regexp =^[0-9]*$
my problem I don't know how to integrate the regex with XPath1.0 or any other solution
You can use a workaround that tests:
if the text is a number (with the number() function)
if the text doesn't start with - (with starts-with())
if the text doesn't contain the dot (with contains())
like that:
//dns:tbody//dns:td[1][string(number(#rowspan))!='NaN'][not(starts-with(#rowspan, '-'))][not(contains(#rowspan, '.'))]/text()
or
//dns:tbody//dns:td[1][not(string(number(#rowspan))='NaN' or starts-with(#rowspan, '-') or contains(#rowspan, '.'))]/text()
Try to use below solution instead of regex:
//dns:tbody//dns:td[1][number(#rowspan)<=0 or number(#rowspan)>0]/text()
This should match #rowspan with int value
Some XPath implementations allow you to supply your own functions. You will need to check the documentation on your XPath implementation.
Java: http://xml.apache.org/xalan-j/xpath_apis.html#functionresolver
I have solr field stored as -
record1 --> colorDimension : "Purple|91"
record2 --> colorDimension : "Purple|974|91"
record3 --> colorDimension : "Purple|974"
I need to facet on this colorDimension Field in a way such that term contains "Purple" and number "91".
The result I am targeting is -
Purple|91 = 2
I was looking out for facet.contains but did not get any examples that uses regular expressions.
You should expand these while indexing, so that you have a token for Purple|91 and Purple|974 separately. Faceting is quick because it can count tokens, without having to run a regex against each one to find the actual value.
You'll probably have to do this in your code, since I don't think you can make the pattern regex tokenizer spit out multiple tokens for a given prefix / group.
Try using this pattern:
Purple\|(?:\d+\|)*91(?:\||$)
Demo
If you actually need to make use of regular expressions, there is a parameter facet.matches, which can be used to specify a regular expression to restrict the facet results
This is getting generated in a request output in Jmeter and I need to capture the dynamic value.
<update id="javax.faces.ViewState"><![CDATA[-8480553014738537212:-8925834053543623028]]></update>
the - (hyphen) symbol coming in the output is also dynamic.
I have tried handling this using
<update id="javax.faces.ViewState"><![CDATA[(.+?)]]></update>
But this is not helping. Please suggest.
The correct way to grab the data is by using the XPath Extractor with the following XPath:
//update[#id='javax.faces.ViewState']/text()
It gets the update tags that have id attribute with the javax.faces.ViewState value and extracts the text from these nodes.
Your regex is not correct because the [ (and literal dots) must be escaped in the regular expressions, and can be fixed as <update\s+id="javax\.faces\.ViewState"><!\[CDATA\[([^\]<]+)]]></update>. See the regex demo.
I use a jmeter for REST testing.
I have made a HTTP Request, and this is the response data:
{"id":11,"name":"value","password":null,"status":"ACTIVE","lastIp":"0.0.0.0","lastLogin":null,"addedDate":1429090984000}
I need just the ID (which is 11) in
{"id":11,....
I use the REGEX below :
([0-9].+?)
It works perfectly but it will be a problem if my ID more than 2 digits. I need to change the REGEX to :
([0-9][0-9].+?)
Is there any dynamic REGEX for my problem. Thank you for your attention.
Regards,
Stefio
If you want any integer between {"id": and , use the following Regular Expression:
{"id":(\d+),
However the smarter way of dealing with JSON data could be JSON Path Extractor (available via JMeter Plugins), going forward this option can be much easier to use against complex JSON.
See Using the XPath Extractor in JMeter guide (scroll down to "Parsing JSON") to learn more on syntax and use cases.
I suggest using the following regular expression:
"id":([^,]*),
This will first find "id": and then look for anything that is not a comma until it finds a comma. Note the character grouping is only around the value of the ID.
This will work for ANY length ID.
Edit:
The same concept works for almost any JSON data, for example where the value is quoted:
"key":"([^"]*)"
That regular expression will extract the value from given key, as long as value is quoted and does not contain quotes. It first finds "key": and then matches anything that is not a quote until the next quote.
You can use the quantifier like this:
([0-9]{2,}.+?)
It will catch 2 or more digits, and then any symbol, 1 or more times. If you want to allow no other characters after the digits, use * instead of +:
([0-9]{2,}.*?)
Regex demo
The response data in my test has this line:
<head><title>
My Title
</title><meta charset
I checked this regex in the inbuilt regex tester in Jmeter and it found the title.
(?m)(?is)<title>\n\tMy Title\n</title>
However, when I use it as a response assertion, the assertion always fails.
I have tried all settings in "Apply to" section. "Text Response" is selected for "Response Field to Test". I selected "Contains" for "Pattern Matching Rules".
I have a very similar issue with a regular expression extractor as well - the selected expression passes in the tester, but fails with regular expression extractor.
I believe it may have something to do with the multi-line nature of the response.
Any pointers?
try use:
(?<=<title>\s*)(\S.+\S)(?=\s*</title>) for find any title
(?<=<title>\s*)(My Title)(?=\s*</title>) for find 'My title'
Try the following:
Regular Expression: <title>(.+?)</title>
Template: $1$
Match: 1
Try to use xpath instead.
Use expression like //title/text() along with XPath Extractor - to extract title value, - and expression like //title[text()='My Title'] along with XPath Assertion.
In both the cases you have to ensure that that Use Tidy (tolerant parser) option is CHECKED - since you are parsing HTML (not XML!..) response.