Ask a Question

Run script assertion without sending

Occasional Contributor

Run script assertion without sending

Hi All,


I copied an xml message into a request (part of a testcase using property transfer). Next I created a script assertion which will validate the content of the request. Is it possible to run the script assertion without sending the request? I only want to know if the message validates against the xsd...

Thanks in advance,




From my experience with assertion scripts, it depends on what your assertion is that you test for in that script. For simplicity, if you test for HTTP status code 200 without having any response in memory, it will fail the test. Take a look at your response window in SoapUI Pro. If it's empty (no JSON, no HTML, no XML, you cannot expect a PASS assertion on that content unless you test for no content!


But if you already ran the request and you have response data populated, sure, you can of course alter your assertion script and add new assertion tests. Then hit the green arrow button and it will be accurate.

Occasional Contributor

Hi Bill,


Thanks for your suggestion. Once the request is sent and I add extra assertions, they are automatically executed. In my situation that's not the case.

The request is a teststep in a testcase and the response is empty. When I leave the URL bar empty and execute the test I receive a message an url must be entered.

The script assertion consists of:

def project = messageExchange.modelItem.testStep.testCase.testSuite.project

def wsdlcontext = project.getInterfaceAt(1).getDefinitionContext()
def validator = new;

def errors = validator.assertRequest(messageExchange, false)

assert errors.length < 1


The message itself is first stored in a property and than transfered to the request via the property transfer step. The property is filled with the following setup script:

def myRequest=new File("c:\\temp\\bgtconnector\\test2.xml").getText()

testRunner.testCase.setPropertyValue( "Request", myRequest )

def xmltop = '''<soapenv:Envelope xmlns:soapenv="" xmlns:stuf="" xmlns:stuf1="" xmlns:xlin="" xmlns:gml="" xmlns:ns="">

def xmlbottom = '''   </soapenv:Body>

testRunner.testCase.setPropertyValue( "Bericht", xmltop+myRequest+xmlbottom )

By transferring the message in the property to an actual message I thought it would be easier to validate (xsd validation) the message. Maybe it's easier (if possible?) to directly validate the content of the property?


Community Hero

Here is the groovy script which validates an xml with xsd

Please see if you can leverage it.

Occasional Contributor



Thanks for sharing the script. I replaced the 'println' with '' so I can see what's going on. The script is now:

* this groovy script validates given xml file 
* with the given xsd file
import org.xml.sax.SAXException
import java.nio.charset.StandardCharsets
import javax.xml.XMLConstants
import javax.xml.validation.SchemaFactory

//Provide valid xml instance & and xsd file paths below
def xml = 'C://Temp//BGTConnector//test2.xml'
def xsd = 'C://SoapUI projecten//BGT Connector//imgeo0300//verticaal//imgeo0300_msg_verticaal.xsd'

//Not required to edit beyond this point

def isFileExists(String fileName) {
    def file = new File(fileName)
    def result = file.exists()
    if (result) { "$fileName exists"
    } else { "$fileName does not exist"

def isValid(String xsd, String xml) {
    def result = false
    if (isFileExists(xsd) && isFileExists(xml)) {
        def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
        try {
            def schema = factory.newSchema(new File(xsd))
            def validator = schema.newValidator()
            validator.validate(new StreamSource(new InputStreamReader(new FileInputStream(xml), StandardCharsets.UTF_8)))
   "$xml is valid."
            result = true
        } catch (SAXException ex) {
   "$xml is not valid because \n"
        } catch (FileNotFoundException ex) {
        } catch (IOException ex) {
        } finally {
            return result
    } else { "Can't validate file as one of the file is not found"

//Validate xml by calling above method
isValid(xsd, xml)

 When I run the groovy script it finds the xsd and xml but fails because it cannot resolve a name.





I searched for it and it's found in another xsd. I suspect the selected xsd has references to other xsd's which aren't loaded. Is it possible to load multiple xsd's? Can I refer to a property (which contains the message) instead of the xml file?

Thanks for helping out,



Occasional Contributor

Any ideas...?


It would have been helpful if you have posted the xml and xsd instead.

Anyways, that clearly says that xml does not conforms to xsd. Check your team or service provider.

Occasional Contributor

Hi Rao,


Thank for your reply. I added the xsd and the message I want to validate.

Have you checked with the respective team regarding the same?

Occasional Contributor

Hi Rao,


I spoke to the team and they provided another xsd. The validation is working now. There is one last question I have: When I run the script it passes even when the validation fails. What can I do to make it fail if the validation is not OK?




Showing results for 
Search instead for 
Did you mean: