Forum Discussion

agupta1's avatar
agupta1
Contributor
16 years ago

Set properties in a Soap test step from a groovy script

I am trying to set properties in the request xml of a test step from a groovy script as following:

def propertiesStep = testRunner.testCase.getTestStepByName( "GetVoiceItem" );
assert(propertiesStep != null);
def voiceItemHolder = groovyUtils.getXmlHolder( "GetVoiceItem#Request" )

voiceItemHolder.declareNamespace("voic", "http://www.adomo.com/VoiceItem");
voiceItemHolder.setNodeValue("//voic:identifier","Hello");

However, when I go in the GetVoiceItem test step, the identifier property in the request xml is not set to 'Hello'.

Can anyone suggest, what I am doing wrong here.

Thanks

Anshu

5 Replies

  • summer's avatar
    summer
    New Contributor
    Thank you for this post. Very helpful!

    I am wondering where I should put the request modification script. In my situation, I have a test step (let's call it test step 1) which is a soap request and is a step that I would like to loop. I want to change the request before this test step is run. Where should I put the request modification groovy script?

    Thanks in advance!
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Are you sure you need a Groovy script? You can use property expansions directly in the request, for example:

    ...
    <SomeElement>
    <SomeOtherElement>${PropertiesStepName#MyProperty}</SomeOtherElement>
    <SomeElement>
    ...

    How do you intend to execute the loop back over the request?
  • summer's avatar
    summer
    New Contributor
    Yes. you are right. Property expansion works fine in this situation.

    Thank you very much!