Forum Discussion

PaulDonny's avatar
PaulDonny
Regular Contributor
12 years ago

Building a Test Step from a WSDL

For my current project I need to systematically build projects solely from the WSDLs. I have the project, WSDL imported and TestSuite, TestCase and TestStep built with both the WsdlTest* and Test*Config made for each respectively. So I should what I think is full access to the Test's data.


How can I get the information from the WSDL to the Test Steps is the question I have. I am rather familiar with SoapUI so if I am just led in the right direction I should be able to figure it out.

Some things to note:

I am not within SoapUI itself but I have it fully imported into my Java project. I have full access to the WSDLs as well, their interface is imported. I will need to make edits to the XML either before or after adding it to the testStep but for now I am just trying to build a proof of concept for this.

Thanks in advance!
  • PaulDonny's avatar
    PaulDonny
    Regular Contributor
    I should have posted a follow up here to explain that I had accomplished it. Here is the code I used:


    WsdlProject project = new WsdlProject();
    project.setName("Test");
    WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, "MyWsdlPath", true)[0];
    String host = "MyHostPath";
    String endpoint = iface.getEndpoints()[0].replaceAll("http.*?//.*?/",host);
    iface.changeEndpoint(iface.getEndpoints()[0],endpoint);
    WsdlOperation operation = (WsdlOperation) iface.getOperationByName("OperationIamBuilding");
    WsdlTestSuite TS = project.addNewTestSuite("Test");
    TS.setName("Test");
    TestStepConfig TStepC = WsdlTestRequestStepFactory.createConfig(operation, "Test");
    WsdlTestCase TC = TS.addNewTestCase("Test");
    WsdlTestStep TStep = TC.addTestStep(TStepC);
    String rawRequest = TStep.getPropertyValue("Request");
    TStep.setPropertyValue("Username", properties.get("username").trim());
    TStep.setPropertyValue("Password", properties.get("password").trim());
    NodeList nodes = XmlUtils.parseXml(operation.getRequestAt(0).getRequestContent()).getChildNodes();
    String XML = XmlUtils.prettyPrintXml(XmlUtils.createXmlObject(nodes.item(0).getParentNode()));
    XML = XML.replaceAll( "(?s)<!--.*?-->","");
    //Data parsing would go here.
    TStep.setPropertyValue("Request", XML);
    project.saveAs("Test.xml");



    (Again, this is in Java, not SoapUI itself. I am building something to build SoapUI project files). This snippet will essentially build a SoapUI request for the single operation currently.