Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

No Nodes Found - XML Data Bank

ptlk6789
ptlk6789 Posts: 13

Hi,

On XML Data Bank step.. when i extract an element, and click on "Evaluate Path" - i see "No nodes found" result.

How do i get value? i need this values to perform string comparison assertion.

I also tried setting "Extract empty element as: [null]" - this did not work either.

Comments

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited April 2020

    on "Evaluate Path" - i see "No nodes found" result.

    The "Evaluate XPath" button executes the given XPath expression against an expected message. Is your Data Bank populated with an expected message? Typically you chain the Data Bank to a test and then run the test once to populate the Data Bank with a message. Otherwise, you can click the Tool Settings > Literal tab to manually provide an expected message.

    If you have an expected message and see "No nodes found" then your XPath expression simply didn't match anything in the expected message. This means your XPath expression might not be what you want. Alternatively, your XPath expression might be fine but simply doesn't match anything in whatever expected message you provided. At runtime, the XPath expression will always run against the actual message it receives, not the expected message.

    How do i get value? i need this values to perform string comparison assertion.

    Are you asking how to use the XML Assertor? You don't use a Data Bank since it is the XML Assertor that has a "String Comparison Assertion". However, similar to Data Banks, Assertors also work with an expected message. Typically you chain the Assertor to a test and then run the test once to populate the Assertor with a message. When you click the Configuration > Add button you will be asked to select your assertion type (one named "String Comparison Assertion") as well as the node in the expected message.

    The expected message acts like a sample of what the tool might receive to make configuring extractions and assertions easier. The value that is actually received at runtime is based on the actual message the Assertor or Data Bank tool receives.

    If you assert that a particular value is "abc" but is "xyz" then you will get a test failure indicating what actual runtime value did not match what expected value.

  • ptlk6789
    ptlk6789 Posts: 13
    edited April 2020

    Steps i followed:

    created test suite > added 1) XML Databank 2) XML Assertor
    Execute test suite.

    Once i got results, i populated XML Databank with the elements i wanted to test. (selected element from "Tree" tab > clicked on extract (Which moved it to window on the right) > then i clicked on Modify button > then "Evaluate XPath"....which gave me "No Nodes Found".

    Out of 3 elements > i got value for 1 and 2 are giving me "No nodes found".

    I am fimiliar with xml assertor where i have to compare string values.(this is the reason i fould out, those element did get picked up)

    FYI.. i was to trying to compare response values this with other service response...for other Service B, i am getting "null" value for that particluar element. .

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited April 2020

    Can you provide a example message and XPath that is giving you that message or steps for me or someone else to reproduce? Any XPath I have ever created from an expected/sample message always works. So, you would need to provide more information.

    Also, just so you know, the XML Assertor performs an extration to validate a value. So, you don't use an XML Data Bank to perform another extraction beforehand if you are just trying to use the Assertor,

  • ptlk6789
    ptlk6789 Posts: 13

    Yes, i am aware about Assertor and Data Bank,
    I should have mentioned this before - i find same issue in assertor step, when click on change elements.

    part of response:



    1234567890

    For above response. I am able to get value for ANumber element. rest 2 nothing.

    Xpath for EType (this gives me no nodes found) >> /:Envelope/:Body[1]/:retrieve[1]/:retrieveC[1]/:A_INFORMATION[1]/:AGMNTY[1]/EType[1]/text()

    Xpath for Anumber (this gives me result)
    /:Envelope/:Body[1]/:retrieve[1]/:retrieveC[1]/:A_INFORMATION[1]/:AGMNTY[1]/ANumber[1]/text()

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    The XML didn't come through. Can you try attaching it instead?

  • ptlk6789
    ptlk6789 Posts: 13
    edited April 2020

    < ns1:AGMNTY >
    < ENumber/ >
    < EType/ >
    < ANumber >123456789< /ANumber >
    < /ns1:AGMNTY >

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited April 2020

    Your XPath ends with "EType/text()" which is not going to match any node because ETypes is an empty element with no text node.

    My recommendation is to modify the XPath like this:

    string(/*:Envelope/*:Body[1]/*:retrieve[1]/*:retrieveC[1]/*:A_INFORMATION[1]/*:AGMNTY[1]/*:EType[1])
    

    This selects the EType element then passes it to the "string" function which returns the string value of a node. For empty elements that have no text nodes this will return empty string.

    Alternatively you could use the "Extract missing element as" option, since the text node being selected with "EType/text()" technically doesn't exist. However, I don't really recommend that. Using the above XPath is a bit more robust since it expects EType and its parent elements to exist then simply builds the node's string value.

  • ptlk6789
    ptlk6789 Posts: 13

    I tried with your recommended xpath, with string, and i got - Cannot evaluate. Not a valid XPath expression.

    Also "Extract missing element as" does not seem to work.

    I tried with more data and I get that missing element for some and missing for most.

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited May 2020

    I think you misunderstand me. My example was just an example based on limited and partial information you provided earlier. I can't say what might be wrong with your XPath unless I have the entire document you are evaluating it against. The XPath you need can vary based on a lot of things but you don't need to worry too much about that. Instead, I am recommending an approach. Let me state the approach a little differently in case this helps.

    Create a new extraction for the desired element. Next, click "Modify' to change the extraction and change "Content Only" to "Entire Element" which should remove "/text()" from the end of the XPath for you automatically. As mentioned, your element does not have content so we can't configure an XPath to select content, like a text node that does not exist. At this point, clicking "Evaluate XPath" should work as expected because the element exists. Next, simply wrap that XPath in a "string" function as in "string(put-xpath-for-element-here)". Clicking "Evaluate XPath" a final time should also work as expected.

  • ptlk6789
    ptlk6789 Posts: 13

    It kinda worked for me.
    I making mistake putting "String" and not "string". - this way it is giving me blank (no value).
    I was hoping to get "null" - for comparing with other service, where i get "null" as a response