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.

Using XPath in Method

Options
LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in SOAtest
Hi,
From my response traffic, I am extracting a section using XML transformer and storing it into a variable. Now I want to use that variable in another method and need to use XPATH to extract some attributes for certain calculations and verification.

Example:
my variable will have data like:
<TEST1>
<CO A ="12" B= "23" D="ABC" >
<P AR="DEF" CR = "234" DR = "34" />
<P AR="EFG" CR = "123" DR = "12" />
<S HR = "TEST" CM = "T2" XR = "46" />
</CO>

<CO A ="13" B= "23" D="ABC" />
<P AR="DEF" CR = "234" DR = "35" />
<P AR="EFG" CR = "123" DR = "14" />
<S HR = "TEST" CM = "T2" XR = "49" />
</CO>

</TEST1>

Now, I want to verify that XR in each S element are sum of DR attributes from P elements within that CO.

I think this should be possible using Xpath within the method but suggest if there is anyother easy way.

Thanks,
Ash
Tagged:

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    edited December 2016
    Options
    Hi,

    You're correct that this can be done by using XPath and scripting (method tool). Fortunately, there may be another easier way to do this that will not require scripting at all. You can use and XML Assertion called Expression Assertion. Expression Assertion allows you to create expressions from the numeric content values of elements and attributes, and further assert a condition on one or more expressions, e.g. they must be equivalent, one is less than the other, etc.

    For example you can create an expression called XR_VALUE_EXPRESSION with an assigned value of attribute XR's value. Create another expression called DR_SUM_EXPRESSION equivalent to the sum of DR attributes from P elements (e.g DR[1] + DR[2]). Then assert that XR_VALUE_EXPRESSION is equivalent to DR_SUM_EXPRESSION.

    The wizard should be able to step you through on how to set up each expression. However, I've attached an example of this, for your reference using your segment of XML in the example. The catch is that you'll need to create n number of Expression Assertions, one for each paired instance of S and P elements.

    FYI, I created the .tst example project in SOAtest 5.5.1 SP 3.0.