Sunday, October 6, 2013

How to Add or Delete/Comment xml node or tag in SoapUI Request at Runtime

This is my new post after long gap, sorry for that. I am going to post this topic as everyone need this as I faced so many trouble while doing adding deleting or commenting tags ,I hope this will surely help you.

Here I go….

Add Tag:-

Staring with Add tag or node, to the SoapUI request xml. This case only works when the tag which you want to add should be present in “XSD” or say WSDL file, by chance you deleted tag and you want to add the same in request at runtime then this will help you.

As you all know SoapUI tool provide so many features for testing webservice, in that one of the outermost feature is Datasource, which helps us to do Datadriven testing, as I mentioned in my previous post same one.
Consider your wsdl file has below xml content (this is just for example).

Here I am using WeatherForecastService for my post purpose

(My sincere thanks to restful services)

<soapenv:Envelope xmlns:soapenv="" xmlns:ns="">

Considering above request xml, I want to add “City” after the “Country” node. (But make sure this only works when the City field present in XSD or WSDL file.)
To test the above service you have created some testdata as below

 In above screenshot as you can see SI.No 1 to 4 you want to add city tag and its values, in 5 case if you don’t want to enter any value in City tag so you have keep it blank, so I have used CityTagBlank column.

Now move on to SoapUI import your test data into SoapUI DataSource and follow the steps as below.
Step 1 :-
Once After importing the test data into DataSource, now go to your request, if your using SoapUI Pro version you will 4 tabs in request as ‘Form’, ‘Outline’, ‘Raw’ and ‘XML’. Click on XML tab you will see xml tags, in the xml file you can see “<ns:Country>” tag. Just after this tag Right Click and Click on GetData sele ct ‘Step1 DataSource’ and Click on Property CityTagOpen.

After selecting above property from Datasource do it same process for CityTagClose and CityTagBlank

Once done all your xml will look like same as below.

Just now you have created the dynamic tag in your request xml, now you have to provide the data into this tag, so now click or place cursor at between as shown below 

Once you place the cursor Right Click and select the City property from DataSource as shown in below screen shot.

Just now you have provided the value to the your newly created dynamic city xml tag it will look like as below,

Now you all set to run the request for all your test data.

Once you run this you will see your request xml look same as below.

In the above screenshot as you can see we have provided the dynamic tag and value as “Delhi” remember, above we have created the test data. The same value populated in “City” Tag.
Now we will see what value for second test case.

See above screenshot in second test case we have provided “Mumbai” as value for City tag.
Now time to see for Blank value in City tag how it will look like.

Remember in above test data for test case number 5 we have not set any value hence the “City” tag is balnk as per XSD schema.
Now we are done with adding the dynamic tag to the request at run time.

NOTE :-  This will work only when the tag is defined in the xsd schema otherwise it will not work.

Commenting  Tag:-

   Now we know how to add node at run time. Now it’s time to do reverse. You may this issue so many time while doing WebService testing as commenting or deleting the tags which is not necessary. For that my post will surely help you,

Let’s consider “GetForecastByCity” sample 

WebService( in this request you will find two fields as “City” and “Country”. In test case where you want to comment the “City” or “Country” tag based on your test cases.

I have prepared some sample test cases where I am commenting tags based on my test data as below.

Here in above screenshot test case from 1 and 2 am I commenting “City” tag and for test case 4 and 5 I am commenting “Country” tag.

Import this test data into SoapUI DataSource, as described in my previous post. It will look like as below.

Now go to your request and click on the XML tab there you will see xml tags as below

Here I am going to insert the DataSource property for commenting the tags according to my tets cases at run time.
Put cursor in between <ns:GetForecastByCity> and <ns:City>, Right click and click on Get Data, select Datasource and click on “CityTagOpen” Datasource property as shown in blow screenshot.

And now put the cursor in between <ns:City> and <ns:Country> again Right click and got to GetData select DataSource and click on “CityTagClose” property.

Repeat the same process for Country, put the cursor after the “${DataSource#CityTagClose}”  property and in between <ns:City> and <ns:Country> again Right click and got to GetData select DataSource and click on “CountryTagOpen” property.

Now put cursor in between </ns:Country> and </ns:GetForecastByCity> Repeat the same same process to select the “CityTagClose” property from DataSource.

After all property set your xml will looks like

Above screenshot shows all xml tag open and tag close property set now, these property will read the value from DataSource and inserts actual value.

In above screenshot I have manually entered the value for City and Country, now I am going to insert these values also from datasource(mapping the datasource property to the field I have explained clearly in my previous post),  now the xml will look like below.

This is how actual xml looks like.

Now we all set to execute the request. When you run the request you will see the City tag and Country Tag will be commented as per test cases.

Here is sample how the xml will look after execution.
For test case 1 and 2 I have commented the City tag the same you can see in xml at run time.

Test Case 1

Test Case 2

And for test case 3 and 4 I have commented Country tag see below screenshot for Country tag commented at run time.

Now we all are done with Adding or Deleting/Commenting the soap request xml tags at run time.

Happy WebService Testing……

That’s all Folks.