Forum Discussion

pricedgp's avatar
pricedgp
Contributor
10 years ago

Using properties in XPath match expressions

I'm trying to do an assertion on a block of text that's returned in a response, using regex expressions -- specifically, while also using property values. I'm using the XPath Match Configuration window to do this.

For example, I have a property value called "hcc_name", and I can do an assertion on an XPath expression like this, which DOES work:

matches( //ns2:realTimeTransactionResponse[1]/COREEnvelopeRealTimeResponse[1]/text(), '${hcc_name}' )

However, when I try to combine that property value with other text before and after that value in that line, it DOES NOT work. For example, I'd like to be able to match against ABC${hcc_name}.

I've tried various combinations, such as:

'ABC' + '${hcc_name}'
'ABC${hcc_name}'
'ABC' + ${hcc_name}
'ABC\${hcc_name}'
'ABC\$\{hcc_name\}'

Is concatenation not supported? If not, does anyone have a better way to do this?

Thanks.

3 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Why do you need to use the matches function? You can specify the XPath in the above window (you can also use the xpath editor icon which is next to the Declare button to create) and the result in the bottom window combing static text with your property expansion. Please see screen shot below.


    Regards,
    Marcus
    SmartBear Support
  • I was trying to simplify my example, but maybe therein lies the issue. Here's a typical block of text -- all of which is within a single element:

    <COREEnvelopeRealTimeResponse>ISA*00* *00* *ZZ*RECEIVERS.ID...*ZZ*SUBMITTERS.ID..*140902*1530*^*00501*493605191*0*P*\~
    GS*HN*RECEIVER CODE*SENDER CODE*20140902*153037*1*X*005010X212~
    ST*277*0001*005010X212~
    BHT*0010*08*1*20140902*153037*DG~
    HL*1**20*1~
    NM1*PR*2*PHIC*****PI*52-8070835~
    PER*IC*John Doe*TE*7812851300~

    I'm trying to assert the existence of (in this example), "PI*52-0870835", which as a property expansion, would be "PI*${hcc_id}". I figured I'd have better luck using regex than using a simple match.

    XPath match doesn't seem to work here -- probably due to the asterisks in the content. It will only work for something at the very beginning of the element, but once there's an asterisk in the text, it won't match. For example, I can match ISA if I turn on the wildcards option (by matching on "ISA*"), but I can't match on, say, ISA*00.

    Thanks.