Forum Discussion

Manoj's avatar
Manoj
Contributor
14 years ago

Passing XPATH from porperty with variable involved

Hi,

I am trying to pass the XPATH expression from a property like below in my groovy
for(i in counter..5)
{
String exp = "//Contracts/Contract[$i]/Member"
...
....
}
I want the exp to be passed from property - // exp = props.getPropertyValue("expression") (Where expression is a property with value=//Contracts/Contract[$i]/Member) , But it fails as it can not get the value of the i when brought from property.
Please let me know if anything I am doing wrong...

Thanks,
Manoj
  • Hi ,

    Please let me know if any luck on this.

    Thanks,
    Manoj
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Change the property value to 'i' so you don't have to deal with $'s:

    //Contracts/Contract[i]/Member

    then use

    for (i in count..5)
    {
    String exp = props.getPropertyValue("expression").replaceAll('i',"$i")
    }
  • Hi,

    I have a scenario where I was to get the XPATH values from properties then pass on to the groovy to find the node values. But I am getting no response... Please guide

    Property contains value aa = *.CelciusToFahrenheitResult
    ------------------------------ below is the groovy where I am trying to fetch the value from the response----------------
    def props=testRunner.testCase.getTestStepByName("Properties")
    value = props.getPropertyValue("aa")
    log.info ("This is value" + "$value" ) // This displays the correct value in log ( *.CelciusToFahrenheitResult)

    globalAuthTransfer =context.expand('${CelciusToFahrenheit#Response#value}')

    log.info ("This is response" + globalAuthTransfer) // This gives a blank response insted it should give the value from the result.

    Note;- I have also tried using $value as well in the above step but no luck. Please guide.

    Thanks,
    manoj
  • Hi,

    Thanks for the response. However I have tried all the combinations.

    if I use the below code then i am getting the desired response.

    globalAuthTransfer =context.expand('${CelciusToFahrenheit#Response#${Properties#aa}}') // this returns the actual value from response

    but when i save or get the values in a variable i am not getting the response.

    value1 = props.getPropertyValue("aa")

    globalAuthTransfer =context.expand('${CelciusToFahrenheit#Response#${value1}}') // this returns null

    Please suggest

    Thanks,
    manoj


    Thanks,
    Manoj
  • Hi Team,

    Appreciate any help on this.

    Thanks,
    manoj