Forum Discussion

HEATConsultant's avatar
HEATConsultant
Occasional Contributor
6 years ago
Solved

Data Import from CSV or XML

SOAP Newbie here.

 

Successfully created my first SOAP Project and request to create a record.

 

Now how can I do a mass import by getting the data from a csv/xml source file and then loop through my soap request?

 

Thanks in advance!

  • Hi HEATConsultant

     

    There's lots of different ways to do this - some of other lads on this site will provide alternatives - but the way I would do this is as follows:

     

    If it's SOAP - did you create the project from a .wsdl file?  Cos that'll make this easier. 

     

    I save the test data files to an appropriate directory (call it c:\testdata\test1\whatevs.xml)

    I use a datasource (directory type)

    SOAP POST request (the body of the request will populated with the testdata file)

    Datasource loop

     

    so my test case's test step hierarchy is as follows:

     

    Datasource 
    SOAP POST request 
    Datasource Loop

    OK - low level instructions to do the above are as follows:

     

    Create the test suite object within your project

    Create the test case objecct within your project

    Right click and click on the 'Add Step' - this launches the 'Add Step' form, click on 'OK' to accept the Datasource step name.

    A 'Generate Properties' dialogue launches, I always click 'No' at this point and I come back to this later.

    On the 'Datasource' step, click on the 'Data Source' dropdown and select 'Directory'

    Click on the 'Select directory' 'Browse' button to navigate to the directory in which your testdata files reside (e.g.c:\testdata\test1)

    In the 'Filename Filter' field, input '*.xml'

    Within the 'Properties' frame on the Datasource step, click on the green plus ('Add Property') - an 'Add Property' form launches - input 'fileContents'.

    Click on the green right arrow, which launches a form entitled 'Test data source' - the field auto populates with '10' - you need to alter this to '1'

    Within the test case hierarchy, right click on the 'Datasource' object within the test case in the 'Navigator' frame.

    Right click and click on the 'Insert Step' and select 'SOAP Request' - 'Add Step' form launches, click on 'OK' to accept the name for the SOAP test step, this launches a 'New Request' form to select the SOAP request - click on 'OK', this launches an 'Add Request to TestCase' form - click on 'OK' button - this adds the SOAP request to the test case.

    Within your test case hierarchy, highlight the SOAP request test step, and within your 'Request' frame, you have 4 vertical tabs (Form, Outline, Raw, XML).

    Click on the 'Outline' tab, identify the SOAPBody tag (which equates to the operation name tag in your .wsdl) - the SOAPBody tag is the tag the should contain your .xml payload

    Right click and select 'Get Data' - this launches a 'Get Data' form which is split vertically into 4 columns (Test Suite, Test Case, Test Step, Properties)

    Click on the 'Datasource' in the 'Test Step' column which auto populates the 'Properties' column with the 'fileContents'.

    Click on the 'fileContents' within the 'Properties' column and click on the 'Add' button to accept the changes and close the 'Get Data' form.

     

    Within the test case hierarchy, right click on the 'SOAP Request' object within the test case in the 'Navigator' frame.

    Right click and click on the 'Insert Step' and select 'Datasource Loop' - 'Insert Step' form launches, click on 'OK' to accept the name for the Datasource Loop test step.

    Ensure the test step hierarchy is as I specify above (Datasource, then SOAP Request, then Datasource Loop)

    Double click on the 'Datasource Loop' object to launch the 'Configure Datasource Loop' form.

    Click on the 'Target Step' dropdown, select the 'SOAP Request' step and click on 'OK' to accept the changes and close the form.

     

     

    That's it - you should be good to go - this test case will execute once thhrough all the .xml files saved in the directory specified.  Don't forget - you'll need to specify the appropriate authorisation on the SOAP Request step before the SOAP request will POST successfully.

     

    Hope this helps,

     

    Cheers,

     

    richie

     

     

     

5 Replies

  • richie's avatar
    richie
    Community Hero

    Hi HEATConsultant

     

    There's lots of different ways to do this - some of other lads on this site will provide alternatives - but the way I would do this is as follows:

     

    If it's SOAP - did you create the project from a .wsdl file?  Cos that'll make this easier. 

     

    I save the test data files to an appropriate directory (call it c:\testdata\test1\whatevs.xml)

    I use a datasource (directory type)

    SOAP POST request (the body of the request will populated with the testdata file)

    Datasource loop

     

    so my test case's test step hierarchy is as follows:

     

    Datasource 
    SOAP POST request 
    Datasource Loop

    OK - low level instructions to do the above are as follows:

     

    Create the test suite object within your project

    Create the test case objecct within your project

    Right click and click on the 'Add Step' - this launches the 'Add Step' form, click on 'OK' to accept the Datasource step name.

    A 'Generate Properties' dialogue launches, I always click 'No' at this point and I come back to this later.

    On the 'Datasource' step, click on the 'Data Source' dropdown and select 'Directory'

    Click on the 'Select directory' 'Browse' button to navigate to the directory in which your testdata files reside (e.g.c:\testdata\test1)

    In the 'Filename Filter' field, input '*.xml'

    Within the 'Properties' frame on the Datasource step, click on the green plus ('Add Property') - an 'Add Property' form launches - input 'fileContents'.

    Click on the green right arrow, which launches a form entitled 'Test data source' - the field auto populates with '10' - you need to alter this to '1'

    Within the test case hierarchy, right click on the 'Datasource' object within the test case in the 'Navigator' frame.

    Right click and click on the 'Insert Step' and select 'SOAP Request' - 'Add Step' form launches, click on 'OK' to accept the name for the SOAP test step, this launches a 'New Request' form to select the SOAP request - click on 'OK', this launches an 'Add Request to TestCase' form - click on 'OK' button - this adds the SOAP request to the test case.

    Within your test case hierarchy, highlight the SOAP request test step, and within your 'Request' frame, you have 4 vertical tabs (Form, Outline, Raw, XML).

    Click on the 'Outline' tab, identify the SOAPBody tag (which equates to the operation name tag in your .wsdl) - the SOAPBody tag is the tag the should contain your .xml payload

    Right click and select 'Get Data' - this launches a 'Get Data' form which is split vertically into 4 columns (Test Suite, Test Case, Test Step, Properties)

    Click on the 'Datasource' in the 'Test Step' column which auto populates the 'Properties' column with the 'fileContents'.

    Click on the 'fileContents' within the 'Properties' column and click on the 'Add' button to accept the changes and close the 'Get Data' form.

     

    Within the test case hierarchy, right click on the 'SOAP Request' object within the test case in the 'Navigator' frame.

    Right click and click on the 'Insert Step' and select 'Datasource Loop' - 'Insert Step' form launches, click on 'OK' to accept the name for the Datasource Loop test step.

    Ensure the test step hierarchy is as I specify above (Datasource, then SOAP Request, then Datasource Loop)

    Double click on the 'Datasource Loop' object to launch the 'Configure Datasource Loop' form.

    Click on the 'Target Step' dropdown, select the 'SOAP Request' step and click on 'OK' to accept the changes and close the form.

     

     

    That's it - you should be good to go - this test case will execute once thhrough all the .xml files saved in the directory specified.  Don't forget - you'll need to specify the appropriate authorisation on the SOAP Request step before the SOAP request will POST successfully.

     

    Hope this helps,

     

    Cheers,

     

    richie

     

     

     

    • HEATConsultant's avatar
      HEATConsultant
      Occasional Contributor

      Thanks Richie. that worked pretty well. A few snags along the way but got it working.  That interface sure isn't userfriendly or all to intuitive so kudos to you for figuring it out!

      • richie's avatar
        richie
        Community Hero
        Hey man....i only know this stuff due to the help from all the other people who participate on the forum....I wouldnt know how to do anything without all their help!
  • aaronpliu's avatar
    aaronpliu
    Frequent Contributor

    Hi HEATConsultant,

     

    ReadyAPI provided various data source to import. I think you'd better to try each one and try to know about which one is suitable for you. As for you mentioned csv/xml, Of course, you would take advantage of them to import massive data and maintain them in external data source. csv is easy to process with comma, and xml process depends on your data structure. You can search from community to find some useful solutions if you needs. and some guys who have provided some good approaches, for example:

    https://community.smartbear.com/t5/SoapUI-Pro/Sharing-is-caring-how-to-modify-xml-files-using-ReadyApi/m-p/168661#M38181