Query for getChildNodes() method ?
Hi,
I have a rest response as below here I want to assert that barometer element count is 6.
<Barometer>
<OneDay>
<MLCR>2</MLCR>
<MLGR>2</MLGR>
<MLVL>2</MLVL>
<MMCR>2</MMCR>
<MMGR>2</MMGR>
<MMVL>2</MMVL>
<MSCR>2</MSCR>
<MSGR>2</MSGR>
<MSVL>2</MSVL>
</OneDay>
<OneMonth>
<MLCRT>-2</MLCRT>
<MLGRT>-1</MLGRT>
<MLVLT>-3</MLVLT>
<MMCRT>-1</MMCRT>
<MMGRT>-1</MMGRT>
<MMVLT>-2</MMVLT>
<MSCRT>-2</MSCRT>
<MSGRT>-1</MSGRT>
<MSVLT>-2</MSVLT>
</OneMonth>
<OneWeek>
<MLCRT>-3</MLCRT>
<MLGRT>-2</MLGRT>
<MLVLT>-3</MLVLT>
<MMCRT>-2</MMCRT>
<MMGRT>-1</MMGRT>
<MMVLT>-2</MMVLT>
<MSCRT>-1</MSCRT>
<MSGRT>1</MSGRT>
<MSVLT>-2</MSVLT>
</OneWeek>
<OneYear>
<MLCRT>2</MLCRT>
<MLGRT>2</MLGRT>
<MLVLT>2</MLVLT>
<MMCRT>2</MMCRT>
<MMGRT>2</MMGRT>
<MMVLT>2</MMVLT>
<MSCRT>2</MSCRT>
<MSGRT>1</MSGRT>
<MSVLT>2</MSVLT>
</OneYear>
<ThreeMonth>
<MLCRT>1</MLCRT>
<MLGRT>1</MLGRT>
<MLVLT>-1</MLVLT>
<MMCRT>2</MMCRT>
<MMGRT>2</MMGRT>
<MMVLT>1</MMVLT>
<MSCRT>1</MSCRT>
<MSGRT>2</MSGRT>
<MSVLT>1</MSVLT>
</ThreeMonth>
<ThreeYear>
<MLCRT>2</MLCRT>
<MLGRT>2</MLGRT>
<MLVLT>2</MLVLT>
<MMCRT>2</MMCRT>
<MMGRT>2</MMGRT>
<MMVLT>3</MMVLT>
<MSCRT>2</MSCRT>
<MSGRT>2</MSGRT>
<MSVLT>2</MSVLT>
</ThreeYear>
</Barometer>
I got the script which gives me this assertion as below -
String xPath = "//*:Response/*:Barometer"
int expectedElementCount = 6
def responseNodes = holder.getDomNode(xPath).getChildNodes()
int responseElementCount = 0
for(int i = 0; i < responseNodes.getLength(); i++) {
def currentNode = responseNodes.item(i)
short nodeType = currentNode.getNodeType()
if(nodeType != currentNode.TEXT_NODE) {
responseElementCount++
}
assert responseElementCount == expectedElementCount
Now my question is -
Why responseNodes.getLength() = 13 ?
i.e. if I do log.info responseNodes.getLength() it gives me 13.
Why is that? and is there any other way to get barometer element count as 6
I do not want to count what is under OneMonth or oneYear just parent nodes under barometer which is 6.
pLEASE advise.