3PD_Inc__Suppor
14 years agoNew Contributor
How to asert that a bunch of node values are not null?
I am using soapUI Pro for testing REST web services. In a few web services, I am getting a bunch of nodes which have PKeys. I have to verify that these PKeys are not null in the response. I tried to add the following assertion via 'For existence with Script':
import com.eviware.soapui.support.XmlHolder
import java.io.*
def holder = new XmlHolder( messageExchange.responseContentAsXml )
int node = Integer.parseInt(holder["count(//Response/e/PKey)"])
for (int i = 0; i <= node-1; i++)
{
def nodeNotNull = holder.getDomNode( "//Response/e["+i+"]/PKey" )
String value = nodeNotnull.getNodeValue()
assert value != null
}
Here. I am taking a count of the no of PKey that come in the response and then in a for loop am traversing all to get the value and then check if it is NULL or not. I am getting an error that "can't apply getNodeValue on Null node".
Could you please let me know what is wrong in this code or is there some other way that I can traverse through all nodes and verify for not null values?
import com.eviware.soapui.support.XmlHolder
import java.io.*
def holder = new XmlHolder( messageExchange.responseContentAsXml )
int node = Integer.parseInt(holder["count(//Response/e/PKey)"])
for (int i = 0; i <= node-1; i++)
{
def nodeNotNull = holder.getDomNode( "//Response/e["+i+"]/PKey" )
String value = nodeNotnull.getNodeValue()
assert value != null
}
Here. I am taking a count of the no of PKey that come in the response and then in a for loop am traversing all to get the value and then check if it is NULL or not. I am getting an error that "can't apply getNodeValue on Null node".
Could you please let me know what is wrong in this code or is there some other way that I can traverse through all nodes and verify for not null values?