I am new to SoapUI (v5.5) but I did, in a regular basis, send XML requests from my laptop to other systems via SoapUI. Our vendors supplied me with the WSDL as well as the actual requests.
Is there any way SoapUI can read a data file in my laptop and sends the same XML request to an external system one by one? More specifically, there are only one variable in the XML request and I have to send this request to update multiple records in an external table. So, one variable, same request to one destination.
Sorry if I am not using the right terminologies. I think the proper terminology for variables is “property”.
Apology of being confusing. I am sure I am not using the right terminologies.
Question1. You have some multiple testdata records helds in either a single file or multiple files (one record in each testdata file) on your laptop. Is that right?
[MIS3]
Yes. In my SoapUI, I have multiple API calls (XML scripts) to update tables in several external systems. Each API has it own endpoint. If there is a project which I have to update more than one external system, I would execute the XML scripts one after the other.
For now, I have a project which I have to send the same XML script to the same endpoint 1,000 times with only one variable (subscriber-ID). I am hoping there is a way so SoapUI will read a external file and sends the XML request 1,000 times.
Question2. You have a single api endpoint which you want to send the content in these testdata files. Is that right?
[MIS3] Yes, one single endpoint in this new project.
Question3. Youve been given a wsdl file to help you setup the required tests. Is that right?
[MIS3]
This is what I did. I created a new project in SoapUI, then enter the wsdl. SoapUI will then create all the API calls under this project. I would see a lot of "Request 1" in each API. I would modify the Request 1 for my purpose.
All these calls (mostly XML but a few are in JSONS) are working.
Question4.
You mention a wsdl, so this is a SOAP request. Is that right?
[MIS3] I think so. Please refer to my response of Question3 above.
Question5. The content of your testdata defined records. Is it whole xml instances (which youve been told is the payload for you SOAP requests) or have you just got a list of attribute values in your testdata that has been mapped to xml tags within a predefined payload?
[MIS3]
Not sure what is an instance. If you are referring to the payload (XML script), they are all working. I would just replace the variable (in this case, subscriber-ID) and click Send.
Question6. What level of setup and automation is required? Do you want a single testcase to loop through your testdata (which requires groovyscript) or is it acceptable for individual testcases, 1 testcase for each testdata permutation defined?
[MIS3]
Yes, a single testcase to loop through my testdata.
If there are 5 records I have to update, I would execute the XML script 5 times. However, this time I have to update 1000 records, so, I am hoping that there is a way (a loop) to do this more efficiently.
I will research on Groovyscript. Is there any online tutorial for this?
Thanks, Ritchie. This is GREAT HELP; I have something to start with!
I can see that the statement associates the 1st data field to SubscriberId:
groovyUtils.setPropertyValue("SOAPTestStepName", "SubscriberId", data[0])
How do you associate SubscriberId to this subscriberIdValue?
<SUBSCRIBERID>${subscriberIdValue}</SUBSCRIBERID>
Also, how about the type of property like Project level, Testsuite level, testcase level? Like ${#TestSuite#SubscriberId}
Thanks for your patient.
I did watch some Youtube videos on Groovy script but I was lost when they talked about Class/Object. As you can tell, I am not a Java developer.
1. The CSV file will be one subscriber per row. I am not sure if the row will contain other fields (not needed in the teststep) but for sure they will be separated by comma and for sure the 1st field will be SubscriberID.
2. I asked about saving off the property to a different scope/level because I thought the syntax calls for me to state the scope/level of this property. It is simpler if I do not have to do this. You are right, I just want to the script to read SubscriberId from a CSV file and sends the API call one by one.
3. Maybe I should add log.info to write out the SubscriberID so I can ensure the looping script reads all the SubscriberID.
4. Is there any way to write out the responses of the API calls? I know that if the API call is successfully, the status will be 0. If the SubscriberID does not exist, it will return status=306.
5. Is it complicated to write out the log to a file in my laptop?
THANKS.
I have not created the looping script yet. Frankly, I have to learn how and to enter the script.
I have attached a document containing the sample data file and a working XML request with successful and failed responses (errorCode=0 and errorCode=306).
1. In the CSV file, since there is only one parameter per row, should I still have to put in a comma?
2. Good I do not have to specify the level of the property. True that this property would not be used anywhere else. (BTW, the name of the property is MSISDN, not SubscriberID).
3. Agreed. With log.info, I can ensure that the script reads all the values in the CSV file.
4. I have included the responses (XML and RAW) of the request in the document. Not sure how to extract the errorCode to a log file.
Thanks.
I did some cut-paste from some groovy examples online. After a lot of trials-and-errors and with the help of log.info, I can see that my groovy can now read the input CSV file row by row.
However, somehow it would not plug into the value into the teststep. I am certain that the problem lies in the properties definition.
I probably overcomplicated things by using property. The purpose of this groovy is just to read the MSISDN from a file in my C-drive and plugs it into the API (in this case, getSubscriptionInformation).
Please take a look and point out if you see any errors.
Thanks.
--------------------------------------------------------------------------------------------------------------------------------------------
import java.text.SimpleDateFormat
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def csvFilePath = "C:\\PT-Groovy\\msisdn-list.csv"
def reportFile = "C:\\PT-Groovy\\Reports\\results-20.log"
context.fileReader = new BufferedReader(new FileReader(csvFilePath))
File report = new File(reportFile)
rowsData = context.fileReader.readLines()
int rowsize = rowsData.size()
report.text = "Timestamp|MSISDN|MESSAGE"
for(int i =0; i < rowsize; i++)
{
def date = new Date()
def sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss")
rowdata = rowsData[i]
String[] data = rowdata.split(",")
testRunner.testCase.setPropertyValue( "MSISDN", data[0] )
testRunner.runTestStepByName( "GetSubscriptionInformation")
tStep = testRunner.testCase.getTestStepByName("GetSubscriptionInformation")
def xmlResponse = tStep.getPropertyValue("Response")
def holder = groovyUtils.getXmlHolder(xmlResponse)
def MESSAGE = holder.getNodeValue("/S:Envelope/S:Body/ns2:getSubscriptionInformationResponse/resultData/msisdn")
log.info data[0]+"|"+MESSAGE
report << "\n"+sdf.format(date)+"|"+data[0]+"|"+MESSAGE
sleep(1000)
}
-------------------------------------------------------------------------------------------------------------------------------------------------
<soapenv:Body>
<api:getSubscriptionInformation>
<msisdn>${#TestSuite#MSISDN}</msisdn>
<!--
<iccid>${#TestSuite#ICCID}</iccid>
<imsi>${#TestSuite#IMSI}</imsi>
-->
</api:getSubscriptionInformation>
</soapenv:Body>
--------------------------------------------------------------------------------------------------------------------------------------
Subject | Author | Latest Post |
---|---|---|