cancel
Showing results for 
Search instead for 
Did you mean: 

Validate assertion with XPath field null

SOLVED
New Contributor

Validate assertion with XPath field null

Hi all.

I am new with soap so please bear with me.

in the pro-version I created and assetion to match  "content" from a Datasource.

It match 100% if there are any details in the field. but when the api returns nothing "No phone number exist" then my test fails.

 

When I compare my results the datasource contains "Null" and the API returns Blank. which fails my assertion when it reads that line.

What regex can I write to ignore it when it is "blank"/"Empty" ?

Please see my screenshot :

The expath expression is as follow:

declare namespace typ='http://wowweb.miway.co.za/types/';
//typ:getLeadsResponseElement[1]/typ:result[1]/typ:leads[1]/typ:array[1]/typ:contactNumber[1]/text()

 

 Expected results:

${DataSource#PHONE_NO}

 

Xpath1.jpg

 

1 ACCEPTED SOLUTION

Accepted Solutions
New Contributor

Re: Validate assertion with XPath field null

i have similar issue but with JDBC and i got my Groovy script to work.  this is what i have so far. below is link to my post

 

https://community.smartbear.com/t5/SoapUI-Pro/Compare-EMPTY-TAGS-in-JDBC-response-to-NULL-in-DataSou...

 

 This groovy works. try it..

 

def ActualSourceCode = context.expand( '${ABC_XYZ#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/SOURCE_CODE[1]}' )
log.info "JDBCSourceCode= $ActualSourceCode"


def ExpectedSourceCode = context.expand( '${DataSource#SourceCode1}' )
log.info "EXCELSourceCode= $ExpectedSourceCode"


if(ActualSourceCode == 'NOVALUE')
{

ExpectedSourceCode = 'NOVALUE'
assert ExpectedSourceCode == ActualSourceCode
log.info "SourceCodeNotEntered = $ActualSourceCode"
}
else
{
assert ExpectedSourceCode == ActualSourceCode
log.info "SourceCodeEntered = $ActualSourceCode"
}

4 REPLIES 4
Community Expert

Re: Validate assertion with XPath field null

"Blank" and "Null" are not the same, so if you try to compare those the validation will fail.

 

A workaround is to concatenate these with some "keyword"; any keyword will do. So your XPath expression (slightly optimized) will be:

concat(//*:result/*:leads/*:array/*:contactNumber, "keyword")

And your expected result will be:

${DataSource#PHONE_NO}keyword
New Contributor

Re: Validate assertion with XPath field null

i have similar issue but with JDBC and i got my Groovy script to work.  this is what i have so far. below is link to my post

 

https://community.smartbear.com/t5/SoapUI-Pro/Compare-EMPTY-TAGS-in-JDBC-response-to-NULL-in-DataSou...

 

 This groovy works. try it..

 

def ActualSourceCode = context.expand( '${ABC_XYZ#ResponseAsXml#//Results[1]/ResultSet[1]/Row[1]/SOURCE_CODE[1]}' )
log.info "JDBCSourceCode= $ActualSourceCode"


def ExpectedSourceCode = context.expand( '${DataSource#SourceCode1}' )
log.info "EXCELSourceCode= $ExpectedSourceCode"


if(ActualSourceCode == 'NOVALUE')
{

ExpectedSourceCode = 'NOVALUE'
assert ExpectedSourceCode == ActualSourceCode
log.info "SourceCodeNotEntered = $ActualSourceCode"
}
else
{
assert ExpectedSourceCode == ActualSourceCode
log.info "SourceCodeEntered = $ActualSourceCode"
}

Moderator

Re: Validate assertion with XPath field null

Hi all,

 

Thanks everyone who participated in the discussion, your help is much appreciated!

@vissie1983 have you had a chance to try any of the suggestions above?
If your question is answered, do you mind clicking the Accept as Solution button below the reply that helped you? This way, other users will be able to easily find the solution in the future. 
Otherwise, do you have any additional information for us to consider?

 

We are looking forward to your reply,

 


Olga Terentieva
SmartBear Assistant Community Manager

New Contributor

Re: Validate assertion with XPath field null

Thank you I eventually wrote a script assertion and looks like this:

 

def response = context.expand( '${SOAP Request Get Lead#Response#declare namespace typ=\'http://wowweb.miway.co.za/types/\'; //typ:getLeadsResponseElement[1]/typ:result[1]/typ:leads[1]/typ:array[1]/typ:leadSource[1]/typ:leadSourceId[1]}' )
log.info response

def DatasourceValue = context.expand( '${DataSource#SOURCE_ID}' )
log.info "DatasourceValue= $DatasourceValue"


if (DatasourceValue=='null')
{
assert response==''
}

else
{
assert response==DatasourceValue
}

 

New Here?
Join us and watch the welcome video:
Watch the New Interview
7Mistakes
Join the exciting event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win