Forum Discussion

UnitTesters's avatar
UnitTesters
Contributor
11 years ago

[Res] DataSoruce with mandatory and non mandatory fields

Hi

I have a large data source of approx 1000 records which I would like to read and submit in one test cycle, my problem is that my WSDL has some mandatory and non-mandatory fields and when the XML is built it includes blanks for the non-mandatory which returns errors.

It is not possible to have the non-mandatory fields set with an expected value of "0".

Is there any way in SOAP UI to read in the data from the excel ignoring the blank columns or to not include the values in the XML that is built.

Apologies if I am explaining this very well.

An example of this would be I have field addressline1 (mandatory), addressline2 (non-mandatory). In some cases on the excel addressline2 is provided and for other not in the cases where addressline2 is not populated the insert test step is failing.

I am using SoapUI Pro 4.5.1.

Any help with this issue would be greatly appreciated.

Thank you

14 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    I've definitely tested the event handler script before posting it. As long as you have valid XML in your request, the script can parse it and remove empty nodes.

    Are you all set now with the custom Groovy script?

    Thanks,
    Michael Giller
    SmartBear Software
  • URN123's avatar
    URN123
    Occasional Contributor
    I am good for now with the custom groovy script.

    Thanks for your help.
  • Hi Michael,

    I have taken the groovy script route with my original issue but I am having one issue with the script I have produced in that it I have one empty node and the script is moving its position on the XML being generated which is causing error once the XML is submitted

    Apologies if this is not 100% clear but any help would be greatly appreciated

    Groovy script below
    //Groovy Script to filter the empty elements and the empty Parent Nodes

    import com.eviware.soapui.support.xml.XmlUtils

    //Reading the Request from Properties
    def request = context.expand( '${Properties#Request}' )

    request = XmlUtils.prettyPrintXml(request)

    def parsedXml = new XmlParser().parseText(request)
    def buffer = new StringWriter()
    new XmlNodePrinter(new PrintWriter(buffer)).print(parsedXml)
    def filteredRequest = buffer.toString()
    filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)

    //Removing all the xml elements that have a value of "--N/A--"
    filteredRequest = filteredRequest.replaceAll( "<(.+)>N/A<(.+)>", "")
    filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)

    request = filteredRequest


    //Removing all the empty elements and parent nodes
    for(i=0;i<6;i++)
    {
    parsedXml = new XmlParser().parseText(request)
    buffer = new StringWriter()
    new XmlNodePrinter(new PrintWriter(buffer)).print(parsedXml)
    filteredRequest = buffer.toString()
    filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)

    //Removing all the xml elements that have a value of ""
    filteredRequest = filteredRequest.replaceAll( "<(.+)><(.+)>", "")
    filteredRequest = filteredRequest.replaceAll( "<(.+)/>", "")
    //filteredRequest = XmlUtils.prettyPrintXml(filteredRequest)
    request = filteredRequest
    }

    //Will pass this fully filtered request into the Application test step for submission using property transfer
    return filteredRequest
  • Hi

    Does anyone have an ideas on this please?

    The basic structure of my xml is below
    <App>
    <Address1>
    <Name>Unit</Name>
    </Address1>
    <Address2>
    <Name>Unit2</Name>
    </Address2>
    <Address3>
    <Name>Unit3</Name>
    </Address3>
    </App>
    but where my issues lies is that for example if I am only provided with Address1 and Address2 the Groovy script is taking the Address3 block an moving before Address1 so I end up with the below I am not sure if the issue is with the groovy script I am using or lies elsewhere
    <App>
    <Address3/>
    <Address1>
    <Name>Unit</Name>
    </Address1>
    <Address2>
    <Name>Unit2</Name>
    </Address2>
    </App>

    any help would be greatly appreciated