Forum Discussion
Hi DavidSEM_Admin,
ChrisAdams is pointing something that I find really interesting.
As far as I understand, you could use some groovy code to dynamically generate your xml content depending on the values extracted form your excel file.
That is to say that you keep your data driven test step, and then use groovy code to add or not xml element to the request.
This should make the deal for you.
David.
Hi,
Yes, this exactly.
- richie4 years agoCommunity HeroHey DavidSEM_Admin
That just proves you should make sure you read everyones posts before responding to the last. I also suggested groovy using an event handler. Unfortunately i didnt notice everyone else suggested this too!
Cheers
Rich- DavidSEM_Admin4 years agoOccasional Contributor
Sorry richie
I saw the solution with a Groovy script and I tried it and it somehow did not work. If it helps i can provde the XML and the ExcelFile with the Data and the Script i found on the web. Maybe it is a simple mistake from my side. However, i am not very familiar with scripts and the groovy language (or any programming language). I also use SoapUI pro wîth ReadyAPI 3.3.1
This would be the XML Request:
<v1:Request>
<Document>
<v13:FamilyName>
<v13:PrimaryValue>${TestData_DataEntry#FamilyName}</v13:PrimaryValue>
</v13:FamilyName>
<v13:FirstName>
<v13:PrimaryValue>${TestData_DataEntry#FirstName}</v13:PrimaryValue>
</v13:FirstName>
<v13:DateOfBirth>${TestData_DataEntry#DateofBirth}</v13:DateOfBirth>
<v13:Nationality>
<v13:Code>${TestData_DataEntry#Nationality}</v13:Code>
</v13:Nationality>
<v13:Gender>
<v13:Code>${TestData_DataEntry#Gender}</v13:Code>
</v13:Gender>
<v13:DocumentNumber>${TestData_DataEntry#DocumentNumber}</v13:DocumentNumber>
<v13:DocumentType>
<v13:Code>${TestData_DataEntry#DocumentType}</v13:Code>
</v13:DocumentType>
<v13:ValidUntil>${TestData_DataEntry#ValidUntil}</v13:ValidUntil>
</Document>
</v1:Request>------------------------------------
This would be the ExcelSheet where the Data is taken:
FamilyName FirstName DateOfBirth Gender DocumentNumber ValidUntil DoumentType PETER 19760101 0109 E15687 2023-05-12 6001 ------------------------------------
This is the groovy Script i found:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def stepName = context.getCurrentStep().getLabel()
def holder = groovyUtils.getXmlHolder( stepName + "#Request")// Find nodes that only consist of whitespaces.
for( item in holder.getDomNodes( "//*[normalize-space(.) = '' and count(*) = 0]" )){
item.parent().removeXobj()
}
// Update the request and write the updated request back to the test step.
holder.updateProperty()
context.requestContent = holder.xmlI have implemented it under "projects>events>"projectRunListener.beforeRun" and "RequestFilter.filterRequest.
Sorry again for my little knowledge..Thank you guys
- ChrisAdams4 years agoChampion Level 3
Hi,
Based on the few nodes you have in your request, I wouldn't use the script you have below, I'd create it on the fly.
I'm assuming your test looks something like....
- Datasource Step
- SOAP Request Step
- Datasource Loop
My two cents, clone the test you have so far to create a new one. That way, if my suggestion doesn't help, you've not lost anything.
In the cloned copy of the test, insert a new Groovy step so test looks like...
- Datasource Step
- Groovy Script
- SOAP Request Step
- Datasource Loop
Don't forget to update the Datasource Loop to go to the Groovy script instead of the SOAP Request.
The idea here is that for each row in the datasource, we're going to build the body of the request in the Groovy Script. Then when SoapUI reaches the SOAP Request Step, it will 'pull' the body for this request from the groovy step.
Also, clear out that code to strip empty nodes from the SOAP Request step.
In the SOAP Request Step, you'll have the whole body in the request pane, which as posted above contains...
<v1:Request> <Document> <v13:FamilyName> <v13:PrimaryValue>${TestData_DataEntry#FamilyName}</v13:PrimaryValue> </v13:FamilyName> <v13:FirstName> <v13:PrimaryValue>${TestData_DataEntry#FirstName}</v13:PrimaryValue> </v13:FirstName> <v13:DateOfBirth>${TestData_DataEntry#DateofBirth}</v13:DateOfBirth> <v13:Nationality> <v13:Code>${TestData_DataEntry#Nationality}</v13:Code> </v13:Nationality> <v13:Gender> <v13:Code>${TestData_DataEntry#Gender}</v13:Code> </v13:Gender> <v13:DocumentNumber>${TestData_DataEntry#DocumentNumber}</v13:DocumentNumber> <v13:DocumentType> <v13:Code>${TestData_DataEntry#DocumentType}</v13:Code> </v13:DocumentType> <v13:ValidUntil>${TestData_DataEntry#ValidUntil}</v13:ValidUntil> </Document> </v1:Request>
Delete the nodes from this so it looks something like....
<v1:Request> <Document> ${Groovy Step#result} </Document> </v1:Request>
The bit ${Groovy Step#result} calls the Groovy script and replaces ${Groovy Step#result} with the result from script. Bit like a placeholder.
Here's the grind.... Edit the Groovy Step and start adding checks for each node...
// Initialise the variable we're going to add our nodes into. def returnString = ''; // Start with the first element FamilyName... // Get family name from the datasource... def familyName = ${TestData_DataEntry#FamilyName}; if (familyName.length() > 0) { // There is a family name in this datasource row. Let's use it. returnString = returnString + "<v13:FamilyName><v13:PrimaryValue>" + familyName + "</v13:PrimaryValue></v13:FamilyName>"; } // FirstName Element check... def firstName = ${TestData_DataEntry#FirstName}; if (firstName.length() > 0) { returnString = returnString + "<v13:FirstName>" + "<v13:PrimaryValue>" + firstName + "</v13:PrimaryValue></v13:FirstName>"; } // And so on and so on until you checked each element... // Finally, return what we have put together... return returnString;
Hopefully, that should then provide you with a request that is dynamic and doesn't contain any empty nodes.
- Datasource Step
Related Content
- 3 years ago
Recent Discussions
- 4 days ago