[ACCEPTED]-SOAPUI: Validate response against xsd schema file-soapui
Accepted answer
I case you still need this (valid for SOAP 2 UI version 2.5.1): File, Preferences, Editor 1 Setting, Validate Response.
Use script assertion:
def project = messageExchange.modelItem.testStep.testCase.testSuite.project
def 4 wsdlcontext = project.getInterfaceAt(0).getDefinitionContext()
def 3 validator = new com.eviware.soapui.impl.wsdl.support.wsdl.WsdlValidator(wsdlcontext);
def 2 errors = validator.assertRequest(messageExchange, false)
assert 1 errors.length < 1
You can use the groovy script for validation 3 the response against the xsd file. Here 2 is the way to validate
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.SchemaFactory;
import javax.xml.XMLConstants;
//Read your xsd file and get the conten into a variable like below.
def xsdContent = "Some Schema Standard";
//Take the response into another variable that you have to validate.
def actualXMLResponse = "Actual XML Response ";
//create a SchemaFactory object
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
//Create a given schema object with help of factory
def schema = factory.newSchema(new StreamSource(new StringReader(xsdContent ));
//Create a validator
def validator = schema.newValidator();
//now validate the actual response against the given schema
try {
validator.validate(new StreamSource(new StringReader(actualXMLResponse )));
} catch(Exception e) {
log.info (e);
assert false;
}
I hope this will help 1 you :-)
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.