Forum Discussion
- groovyguy7 years agoChampion Level 1
Without getting into the nitty gritty details (which can be found here), an assert statement is like an assertion on a Soap/REST Test Step. It is verifying a certain piece of information and making the groovy test step pass or fail accordingly.
- richie7 years agoCommunity Hero
I gotcha - the groovy step will go 'red' if it fails - right?
I don't know if you noticed, but I had a second 'failed' option (VenueSyncIgnore as well as the VenueSyncError) within the cdata - I've altered your script as follows (totally ripping off what you've already done) and the results appear to work - script is below:
import com.eviware.soapui.support.XmlHolder def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ); // get the response, specifically the //RETURN element that contains DATA tags. This may need to be adjusted to fit your own project, but you want to collect the //return element def response = context.expand( '${SOAP Request#Response#declare namespace NS1=\'urn:CSMVenueSyncServicesIntf-ICSMVenueSyncServices\'; //NS1:SyncVenueResponse[1]/return[1]}' ) // remove the CDATA tags response = response.replaceAll( "<!\\[CDATA\\[", "" ) response = response.replaceAll( "]]>", "" ) // Parse the response into XML def holder = groovyUtils.getXmlHolder( response ) log.info((holder["exists(//Responses/VenueSyncSuccesses/VenueSyncSuccess)"])); log.info(holder["count(//Responses/VenueSyncErrors/VenueSyncError)"]); log.info(holder["count(//Responses/VenueSyncIgnores/VenueSyncIgnore)"]); def successExists = (holder["exists(//Responses/VenueSyncSuccesses/VenueSyncSuccess)"]); def errorCount = (holder["count(//Responses/VenueSyncErrors/VenueSyncError)"]).toInteger(); def ignoreCount = (holder["count(//Responses/VenueSyncIgnores/VenueSyncIgnore)"]).toInteger(); assert (successExists && errorCount == 0 && ignoreCount ==0);
OK - if you're feeling in a helpful mood I have 1 more point and all I'll stand by all previous conversations
I need to be able to extract the VenueID attribute value from within the cdata string to pass this onto a subsequent JDBC test step. Essentially, once the successful request has been posted, I need to run a query to retrieve the record from within the DB to verify certain attributes have been updated.
I should highlight - the VenueID attribute will 'move' in the response, relative to whether the request is successful or is ignored (for certain error scenario) or is a failure (most severe failed options).
Obviously I only care about when the request has been successful as only successful requests will write to the DB.
I can extract the value and pass it onto the JDBC test step that'll be me very happy!
Cheers!
richie
- groovyguy7 years agoChampion Level 1
The first question I have is whether or not there will be more than one VenueID in the response, or if it will be singular? I can probably whip something up in a bit.
Related Content
- 4 years agomehdisinger
- 3 months agoStoplight
- 3 years agoprekar