Ask a Question

[Res] JDBC-datasource and XPATH, problems comparing []...

MERKSEN
New Contributor

[Res] JDBC-datasource and XPATH, problems comparing []...

The jdbc-datasource I use sometimes contains null values, like in this simplified example:

Id Name Email
123 Carl carl@test.com
124 Steve (null)

When called, the SOAP-service I am testing returns empty elements, like this:
->
ReadPerson(124)
<-
<ReturnValue>
<Id>124</Id>
<Name>Steve</Name>
<Email/>
<ReturnValue>

I want to treat this as the expected result, but my XPATH-match:

declare namespace ns1='http://test.com/Person;
//ns1:GetPersonResponse[1]/ns1:GetPersonResult[1]/ns1:ReturnValue[1]/ns1:Email[1]

says:

XPathContains comparison failed, expecting [], actual was [null] ([] [null] seems backwards to me, but it's what it says)

I want [] to equal [null], how can I do this?
7 REPLIES 7
SmartBear_Suppo
SmartBear Alumni (Retired)

Maybe you could try:
exists(//ns1:GetPersonResponse[1]/ns1:GetPersonResult[1]/ns1:ReturnValue[1]/ns1:Email[1])
and as the results put
true
.
This will check the the element exists, even though it's empy.

Does this make sense to you? Or do you want to explicitly test that it's empty?

--
Regards

Erik
SmartBear Sweden

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
MERKSEN
New Contributor

No, it doesn't help me, it's not the empty elements as such I'm interested in.

I'm doing datadriven testing, and need my assertions to work for entries that do and do not contain optional data, email in the example.

Datasource: (The database the service is using)
Select PERSON.ID As PERSON.ID, PERSON_NAME As PERSON_NAME, PERSON.EMAIL As PERSON_EMAIL From PERSON

Id Name Email
123 Carl carl@test.com
124 Steve (null)

Assertion:
${database#PERSON_EMAIL}

1. Correct response
ReadPerson(123)
<ReturnValue>
<Id>123</Id>
<Name>Carl</Name>
<Email>carl@test.com</Email>
<ReturnValue>

2. Correct response (no email supplied)
ReadPerson(124)
<ReturnValue>
<Id>124</Id>
<Name>Steve</Name>
<Email/>
<ReturnValue>

3. Incorrect response (incorrect email)
ReadPerson(123)
<ReturnValue>
<Id>123</Id>
<Name>Carl</Name>
<Email>24 Carl Street</Email>
<ReturnValue>

So, I do want the assertion to test the content of Email and conclude that 1 is correct and 3 is not, but I don't want it to give me an error for 2:
XPathContains comparison failed, expecting [], actual was [null]

Not sure if I make sense, this all seems so very basic to me and still I can not make it work.
SmartBear_Suppo
SmartBear Alumni (Retired)

Then I believe you have to combine an match for existance and a mach for the format of the e-mail adress you want like this:

not(exists(//ns:GetPersonResponse[1]/ns1:GetPersonResult[1]/ns:ReturnValue[2]/ns1:Email/text())) or matches(//ns:GetPersonResponse[1]/ns1:GetPersonResult[1]/ns:ReturnValue[2]/ns1:Email/text(), '<INSERT REGULAR EXPRESSIONS FOR DESIRED EMAIL FORMAT HERE>')

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
MERKSEN
New Contributor

Thank you, that's it.
CPP_Plc_Support
Not applicable

I have a similar problem, but when using an assertion in a JDBC request.

I am testing a PUT service which contains multiple fields that I'm wanting to check the results in the database after the update. Some of the fields contain a null value.

In my assertion I have got the following in my XPath Expression:

//Results[1]/ResultSet[1]/Row[1]/SECOND_SURNAME[1]

and the following in my Expected Result:

${DataSource#secondSurname} - the values for all of the fields are coming from a Datasource that links to an excel spreadsheet and in Excel the value for the field secondSurname is null

all of which have been populated using the relevant drop downs in SOAPUI Pro.

My problem is that I get the following result against my assertion:

XPathContains comparison failed for path [//Results[1]/ResultSet[1]/Row[1]/SECOND_SURNAME[1]], expecting [], actual was [null]

So how do I do something similar to the above solution within a JDBC request?
SmartBear_Suppo
SmartBear Alumni (Retired)

Hi,

You can set you JDBC TestStep assertion as follows:
exists(//Results[1]/ResultSet[1]/Row[1]/SECOND_SURNAME[1])
and the Expected result will be "true".
Since the node exists, the assertion will pass even if the value is null.

Regards,

Giscard

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

I have the result: 

<Results>
<ResultSet fetchSize="128">
<Row rowNumber="1">
<MODEL_ID>Deposit</MODEL_ID>
<VALUE1>1</VALUE1>
<VALUE2/>
<VALUE_SET/>
<SCORE>1.00</SCORE>
</Row>

not sure how to say i am expecting to null in VALUE2?

If i am declaring the expected result null i am getting failue

expected null actual null. 

cancel
Showing results for 
Search instead for 
Did you mean: