cancel
Showing results for 
Search instead for 
Did you mean: 

XML declaration in request disappears after property transfer

SOLVED
Community Hero

Re: XML declaration in request disappears after property transfer

Hi @Meisinotti you have no 'Properties' step.  The code I gave you requires a Properties step.

 

So your original script had you UC1.118 creating a request that returned a payload and you then transferred the XML content from that directly to UC1.116_init (via the Property Transfer step) - is that right?

 

The groovy bit I mentioned in my last requires a Properties step to work - it isn't absolutely necessary (I know Rao doesn't bother with Properties steps) but I found for me it's nice to be able to spot the data I'm manipulating - if there are any problems - it makes spotting them easier if you use a Properties step I find - hence I'm suggesting using a Properties step.

 

Follow these steps exactly to get it all to work.

 

Step 1.  Delete the '1.118_to_1.116_ini' Property Transfer step and the 'Groovy script step in your test hierarchy and follow the following instructions:

 

Step 2.  Create a Groovy Step and paste in the WHOLE groovy snippet I specified in my original post - this includes the bit at the bottom you didn't include at first - ALL the code needs to be present to get this to work! - e.g. the groovy snippet required is as follows (do NOT leave any out - otherwise this wont work):

//next line parses the Properties step and gets the value of the XML without the declaration
def XML = testRunner.testCase.getTestStepByName("Properties").getPropertyValue("XML")
log.info(XML)

//next line parses the Properties step and gets the value of the declaration
def declaration = testRunner.testCase.getTestStepByName("Properties").getPropertyValue("declaration")
log.info(declaration)

//concatenate the values together adding a <br> between them
def wellFormedXML = declaration +" \n" + XML
log.info(wellFormedXML)

//define the properties step and write the merged XML to the Properties step
def propertiesStep = context.testCase.testSteps["Properties"] 
propertiesStep.setPropertyValue("wellFormedXML", wellFormedXML)

Step 3. submit the UC1.118 teststep to generate the response with the XML you need to capture

Step 4. Via the outline tab in the response, select 'Transfer to' >> 'Add properties step', when dialogue appears ensure the properties step name is 'Properties' (this generates the Properties step)

Step 5. select the name of the target property to create - e.g. 'XML' 

Step 6. on the 'Transfer to Property' form, accept the defaults (target step, target property, etc.) and tick the 'Open Property Transfer editor to finish' checkbox and click 'Ok' to accept (this creates an empty 'XML' property in the Properties step)

Step 7. The Properties step might be created below every other step in the testcase hierarchy.  Move the Properties step so it's AFTER the Groovy Step

Step 8. Go into the Properties step - an empty XML property should be present. 

Step9.  Create 2 new empty properties entitled 'declaration' and 'wellFormedXML'

Step10. In the 'declaration' property, specify the value as your declaration - e.g. <?xml version="1.0" encoding="ISO-8859-15"?>

 

At this point you should have the following objects in your test case

UC1.118 request, property transfer, properties step, groovy step and UC1.116_ini

 

Step 11.  Move the objects sequence around so they appear in the following order in your testcase:

Meisinotti_testCase_object_hierarchy.PNG

 

Step12. Open the Property Transfer step (there is only 1 transfer specified).  Execute the transfer for the 'XML' transfer property - this will write your XML from the UC1.118 request's response to the Properties step's 'XML' property value

Step13. Execute the Groovy step - this will concatenate the values in the 'declaration' and 'XML' properties together, writing the merged value to the 'wellFormedXML' property

Step14. Within the Payload of the UC1.116_ini request, paste the value ${Properties#wellFormedXML} - see the next screenshot

FinalStepPayload.PNG

 

OK - if you followed the steps above exactly, you debugged your test as you created it - so it should work - run the testcase to be sure. 

The only way I could describe all the steps above was to actually do it - and it works fine this end - so if you follow the instructions exactly - it should be perfect.

 

Cheers!

 

rich

 

 

 

zx

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the title of the post to something more descriptive? This will help people when searching for problems.
Moderator

Re: XML declaration in request disappears after property transfer

Wow, what an investigation!

I can't wait to hear the results! @Meisinotti, Does this work?

 


Olga Terentieva
SmartBear Assistant Community Manager

Occasional Contributor

Re: XML declaration in request disappears after property transfer

So, alt least I got a way that worked for me - than you for you help!

 

//next line parses the Properties step and gets the value of the declaration
def declaration = testRunner.testCase.testSuite.getPropertyValue("prexml")
log.info(declaration)

 

//next line parses the Properties step and gets the value of the XML without the declaration
def XML = context.expand('${UC1.116_init#Request}')
log.info(XML)

 

//concatenate the values together adding a <br> between them
def wellFormedXML = declaration +" \n" + XML
log.info(wellFormedXML)

 

testRunner.getTestCase().getTestStepByName("UC1.116_init").getProperty('Request').setValue(wellFormedXML)

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2