SoapUI XPath assertion - wildcard string with Excel dataSource - xpath

I want to use an assertion "expected result" that uses both some form of "contains" function or wildcard AND gets the text to test against from an Excel dataSource. The SoapUI 'contains' function has no way to use a dataSource that I've found, and I cannot figure out how to use an XPath function like contains with a dataSource. Can someone please explain how that works?
--
I've been asked for more detail.
In SoapUI, if I add an assertion and choose the request/response as the source, I then have a choice of assertions. One of them is "XPath Match". I can use that to designate a specific field in the response, in this case, which value I want to test.
Having chosen the "XPath expression" in the top half of the "XPath Match Configuration", I can then choose my Excel dataSource as the content for the lower half "Expected Result". I have used this to test an error code against an error code from the Excel spreadsheet.
What I don't know how to do is determine, in this assertion, that the error message returned contains the value in Excel. I figure something special goes into "Expected Result" in the "XPath Match Configuration" box, but I don't know what.

The Expected Result of the XPath assertion is only a "dumb" string. The best that you can do in this field is property expansion ... which does not help your cause.
Instead you will need to use the top portion, where you can enter XPath Expression, that provides the logic you are looking for. Your XPath expression will need to look something like:
contains(//*:some/*:node, '${data_source#property}')
and your Expected Value will be simply:
true
Convenient reference, in case you need it.

Related

Proper way to assert text in Selenium Webdriver/RSpec

So im writing a framework in pure selenium-webdriver and am curious what the proper way to assert text exists (Such as in an alert message for instance on an invalid login for example). Specifically with RSpec.
I can think of two ways that comes to mind. Doing something like so:
text_to_check = driver.find_element(locator).text and then doing something like expect(text_to_check).to be("Bad Login text") The locator in this case would probably be xpath or css locator I guess? Although I feel like xpath would probably make more sense (Im not super familiar with xpath tbh though)
Use the driver.page_source() and then check against that....but that seems brittle if that text exists somewhere else on the page. Also it seems unnecessary to do that and pull in the whole page source to check what is essentially one element.
String expected = “abc.com;
String actualURL= “abc.com”;
Assert.assertEquals(expected, actualURL);
message – Message to be displayed in case of an Assertion Error.
condition – Condition against which the assertion needs to be applied.
Assert.assertTrue(“Assert True test message”, true);

Xpath Error: Can not convert #STRING to a NodeList

In one of the API solution, incoming request is in XML format, and i need to fetch first child node tag name to make decision to run the logic. I am using xpath to get the tag name, when in am running xpath i am getting error "Can not convert #STRING to a NodeList"
I have tried with local-name and name, but both are giving same error.
my xml is as below
<p:Check xmlns:p="http://amarwayx.com.cu/WCSXMLSchema/creptonium">
<AttributeChnageLocal>
<TaskID>17723</TaskID>
<BatchID>12345</BatchID>
<Expiry>2022-12-06</Expiry>
<TimeStamp>2019-07-20T22:45:48</TimeStamp>
</AttributeChnageLocal>
</p:Check>
and Xpath i used are
local-name(/p:Check/*)
name(/p:Check/*)
local-name(/p:Check/*[1])
name(/p:Check/*[1])
how ever is some online xpath evaluator has evaluated correct name(AttributeChnageLocal), i am not getting where the xpath syntax is wrong.
below is my tool snapshot.
same kind of expression works fine
You have ticked a box labelled "store the string value of the selected node as text", which suggests that the XPath evaluation tool you are using expects your XPath expression to select a node; but it doesn't, it selects a string.
I don't know what this tool you are using is, but unfortunately all its options seem to assume that you are selecting nodes.

Compare Assertion in Jmeter

I am new to J meter. Please look into the following body data in Http request
{
"groupBy":"${groupBy}",
"offset":0,
"limit":10
}
I need to check whether limit value is above 10 in the above content. Is it can be done by using Compare Assertion.
Thanks in advance.
You have to extract the value "10" in to variable using "Regular Expression Extractor" after that use "Response Assertion" by choosing "Jmeter Variable" option under "Apply to" choosing "Equals" option under "Pattern Matching Rules"
and add 10 under "Pattern to test"
There is a special Test Element - JSON Path Assertion available via JMeter Plugins which is designed for working with JSON data.
The relevant JSON Path expression to match your "limit" will be as simple as:
$.limit
Try to avoid Compare Assertion where possible as it consumes very much resources.
References:
JSONPath - XPath for JSON
How to Use JMeter Assertions in Three Easy Steps

Can I get the information at which node or element or attribute the xpath failed while evaluating it against an xml

I have some xpath and I am evaluating against an XML.
//view/section/row
[(cell/data[#value='Other Roles']) and
(cell/data[contains(#value,'336')]) and
(cell/data[contains(#value,'0')]) and
(cell/data[contains(#value,'320')]) and
(cell/data[contains(#value,'16')]) and
(cell/data[contains(#value,'0')]) ]
While doing so, the xpath might not be available say row does not have the cell with data 336 , can I get that piece of information where it failed
Any code/utils that gives this information
In general, No.
Even if the result set is empty, it does not mean it fails. It is just an empty result set, which is a valid result. So as a matter of fact, your assumption is wrong, because the XPath did not fail.
If you want to check whether your XPath yiels an empty sequence, you can check using fn:empty(), e.g. empty(cell/data[contains(#value,'336')]).
Using XPath 2.0 you can also raise your own errors, using the fn:error() function. However, I do not see how you want to apply that in this specific example in a useful manner.
I've not seen any tools that automatically do this, but manually performing such sanity checks can be very useful:
First check that you're matching views:
//view
then sections:
//view/section
then rows:
//view/section/row
then specific rows:
//view/section/row[(cell/data[#value='Other Roles'])]
...until you get to a point where reality deviates from your expectations. You'll then know where an adjustment must be made.

JMeter does not replace ${SUBPANEL_RELATE_MODULE_g1} with its value

It's a long story, but I will try make it simple:
I generated MeterMaid XML files with SugarMMM; I chose only the Accounts module:
I converted above files to JMeter format with MeterMaid (I consolidated the tests into one file and named it "filename.xml"):
ruby GenMeter.rb --inputfile=filename.xml --outputfile=filename.jmx
I did the necessary CSV setup. All the CSV file contains is the login details (usr,pwd) for testing concurrent user logins. This part works well indeed.
When I run the test, I can see that a whole bunch of ${} variables are converted into corresponding values. Sadly, ${SUBPANEL_RELATE_MODULE_g1} doesn't get resolved... here's what the GET url (from View Results Tree Listener component) looks like:
http://localhost/sugarcrm/index.php?module=${SUBPANEL_RELATE_MODULE_g1}&action=Popup&hide_clear_button=true&mode=MultiSelect&create=true&metadata=undefined
Note that it's not the only variable that isn't resolved. The following screenshot shows the other tests that fail, all also caused by other variables not replaced by their corresponding values:
Here's how this variable is set up (which is well before the time it's used):
Here's what Debug Sampler says:
JMeterVariables:
CAMPAIGN_ID=CAMPAIGN_ID_ERROR
CAMPAIGN_NAME=CAMPAIGN_NAME_ERROR
CONTACT_ID=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_ID_g=4
CONTACT_ID_g0=onclick="send_back('Contacts','997a3171-aa60-b2d6-a457-4e0ba8b0052b');">Prof
CONTACT_ID_g1=onclick="send_back('Contacts','
CONTACT_ID_g2=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_ID_g3=');">
CONTACT_ID_g4=Prof
CONTACT_NAME=Prof
CONTACT_NAME_g=4
CONTACT_NAME_g0=onclick="send_back('Contacts','997a3171-aa60-b2d6-a457-4e0ba8b0052b');">Prof
CONTACT_NAME_g1=onclick="send_back('Contacts','
CONTACT_NAME_g2=997a3171-aa60-b2d6-a457-4e0ba8b0052b
CONTACT_NAME_g3=');">
CONTACT_NAME_g4=Prof
FOUND_ID=1
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#3c1635
MEMBER_OF_ID=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_ID_g=4
MEMBER_OF_ID_g0=onclick="send_back('Accounts','d7c26344-cad8-0503-b02a-4e0cb4db3985');">searchSearchForm
MEMBER_OF_ID_g1=onclick="send_back('Accounts','
MEMBER_OF_ID_g2=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_ID_g3=');">
MEMBER_OF_ID_g4=searchSearchForm
MEMBER_OF_NAME=searchSearchForm
MEMBER_OF_NAME_g=4
MEMBER_OF_NAME_g0=onclick="send_back('Accounts','d7c26344-cad8-0503-b02a-4e0cb4db3985');">searchSearchForm
MEMBER_OF_NAME_g1=onclick="send_back('Accounts','
MEMBER_OF_NAME_g2=d7c26344-cad8-0503-b02a-4e0cb4db3985
MEMBER_OF_NAME_g3=');">
MEMBER_OF_NAME_g4=searchSearchForm
OPPORTUNITY_ID=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_ID_g=4
OPPORTUNITY_ID_g0=onclick="send_back('Opportunities','864e402f-0d76-ab6e-b54f-4e0cb42f0249');">value
OPPORTUNITY_ID_g1=onclick="send_back('Opportunities','
OPPORTUNITY_ID_g2=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_ID_g3=');">
OPPORTUNITY_ID_g4=value
OPPORTUNITY_NAME=value
OPPORTUNITY_NAME_g=4
OPPORTUNITY_NAME_g0=onclick="send_back('Opportunities','864e402f-0d76-ab6e-b54f-4e0cb42f0249');">value
OPPORTUNITY_NAME_g1=onclick="send_back('Opportunities','
OPPORTUNITY_NAME_g2=864e402f-0d76-ab6e-b54f-4e0cb42f0249
OPPORTUNITY_NAME_g3=');">
OPPORTUNITY_NAME_g4=value
RANDOM_CHAR=o
RANDOM_CHAR_g=1
RANDOM_CHAR_g0=o
RANDOM_CHAR_g1=o
RANDOM_STRING=value
RANDOM_STRING_g=1
RANDOM_STRING_g0=value
RANDOM_STRING_g1=value
RECORD_NAME=NOT_FOUND
RECORD_NUMBER=3250317d-6c79-b20d-5e36-4e0cb4746e84
RECORD_NUMBER_g=2
RECORD_NUMBER_g0=javascript:lvg_nav('Accounts', '3250317d-6c79-b20d-5e36-4e0cb4746e84
RECORD_NUMBER_g1=javascript:lvg_nav('Accounts', '
RECORD_NUMBER_g2=3250317d-6c79-b20d-5e36-4e0cb4746e84
SEARCH_FIELD=SEARCH_FIELD_ERROR
START.HMS=190308
START.MS=1309453388621
START.YMD=20110630
SUBPANEL_RELATE_MODULE=Accounts
TEAM_ID=seed-Teams8
TEAM_ID_g=4
TEAM_ID_g0=onclick="send_team_to_form('Teams','seed-Teams8');">Ball
TEAM_ID_g1=onclick="send_team_to_form('Teams','
TEAM_ID_g2=seed-Teams8
TEAM_ID_g3=');">
TEAM_ID_g4=Ball
TEAM_NAME=Ball
TEAM_NAME_g=4
TEAM_NAME_g0=onclick="send_team_to_form('Teams','seed-Teams8');">Ball
TEAM_NAME_g1=onclick="send_team_to_form('Teams','
TEAM_NAME_g2=seed-Teams8
TEAM_NAME_g3=');">
TEAM_NAME_g4=Ball
TESTSTART.MS=1309455500088
pwd=user1
usr=user1
UPDATE:
Here's after changing Template to $1$$2$$3$$4$:
And here's the Debug output (the Sampler is put just after regex Controller):
JMeterVariables:
JMeterThread.last_sample_ok=true
JMeterThread.pack=org.apache.jmeter.threads.SamplePackage#18fde89
RANDOM_CHAR=t
RANDOM_CHAR_g=1
RANDOM_CHAR_g0=t
RANDOM_CHAR_g1=t
RANDOM_STRING=Tanzania
RANDOM_STRING_g=1
RANDOM_STRING_g0=Tanzania
RANDOM_STRING_g1=Tanzania
RECORD_NAME=NOT_FOUND
RECORD_NUMBER=DOCTYPE
RECORD_NUMBER_g=1
RECORD_NUMBER_g0=DOCTYPE
RECORD_NUMBER_g1=DOCTYPE
START.HMS=100932
START.MS=1312531772599
START.YMD=20110805
SUBPANEL_RELATE_MODULE=Accounts
TESTSTART.MS=1312542237235
pwd=user1
usr=user1
Verify in your CSV dataset config, all variables are declared correctly (no typos, no omissions, no spaces before variable names, etc.)
I would also suggest putting a debug sampler high in your tree, as it will show you every variable and its value and can save a lot of time.
Edit:
It looks like your regex is setup incorrectly for creating multiple groups. If you look in your Debug sampler, you have SUBPANEL_RELATE_MODULE=Accounts but not SUBPANEL_RELATE_MODULE_g1= . This implies you don't have GROUPS setup.
In looking at your regex, the line template: $0$ is saying "only give me one group", whereas it looks like you want 4. Thus, you should try template: $1$$2$$3$$4$ the first match should be _g1 the second _g2 and so on. Check out the manual for details.
make judicious use of the ${SUBPANEL_RELATE_MODULE_g1} variable throughout the script after it gets defined by the Regular Expression Extractor. Verify it exists. Use it in Controller titles, test headings, at the beginning of tests, and at the end of tests.
That will help narrow it down
This way you can follow it along in the script to make sure it exists just before the moment it is used, and find where it's breaking down. Basically print statement debugging.
I don't know about sugar CRM or metermaid but for jmeter I had a similar problem with variable that were not resolve.
Check if this variable is declared somewhere or maybe you need to write a reg ex to extract that value from the previous request.
The problem I got It was that I extracted the variable from a CSV files
the variable name was CONTRACTNO, CLIENTNO
my URL : /SomeURL/bla?eventId=contractSelected&contractNoSelected=${CONTRACTNO}&applicationID=BLa
And it wasn't working so I changed the variable name in the csv file to :
CONTRACTNO,CLIENTNO (look that I removed a space)
Jmeter tend to be very picky with space in name and variable definition.
You are expecting the following values
${SUBPANEL_RELATE_MODULE_g1}
but you have configured the Regular Expression Extractor reference name as
"SUBPANEL_RELATE_MODULE"
There two options you can get the values
You have to change the ${SUBPANEL_RELATE_MODULE_g1} into ${SUBPANEL_RELATE_MODULE}
You have to change the Regular Expression Extractor reference name as "SUBPANEL_RELATE_MODULE _g1" to "SUBPANEL_RELATE_MODULE"
After this your values will be replaced properly.
It looks like your regular expression isn't picking up a match, your default value is set to "Accounts" and in your debug output that's the value of the variable. You'll only get match groups if the regular expression matches.
The View Results Tree listener now has a RegExp tester, so you can go to the request that you're trying to extract the variable SUBPANEL_RELATE_MODULE from the result in the results tree and choose RegExp Tester from the dropdown where it says "Text".
You can then run your regular expression on the response data in the RegExp tester and probably find that it doesn't match and then hone your regular expression so that it matches and update it in your Regular Expression Extractor.

Resources