Forum Discussion
PaulDonny
11 years agoRegular Contributor
Not sure if anyone else is following this or interested but it helps me if I write stuff down and I figure I can't be the only one who wants to be able to customize SoapUI to his application's exact needs.
So I was able to import SoapUI fully into my Java project. You can follow the steps at the link I provided or just navigate to your SoapUI lib folder (as mentioned in my previous post) and download the 2 SoapUI specific Jar files and import them as well. After that, you need to create your project and WSDL/XSD. My line of code looks like the following:
Next, I adjusted my endpoint to fit my test host
After that, the majority of stuff falls into the standard SoapUI groovy language. I will post a small demo to set up a test step
I use a config file and properties file in order to set the parameters for the test case. Currently I use a function called insertParams in order to make this work how I like. The config file is stored in a map (propReader) which is stored in a map (config) which uses the testName as a key. The properties themselves are also stored in a map. Here's my insertParams function
The majority of this is still in the testing phases but if your interested in a singular application that will allow you full control, this should do it. All you would have to do is create a GUI which builds the property files for your application and then set this to run the SoapUI project instead of just saving it. For more complex situations you will need to customize the code to build the XML properly. If anyone has any questions or suggestions please, please ask.
Note:
This is all built in Java, not within SoapUI itself. It uses a lot of the SoapUI functionality. I am not responsible if you accidentally wipe your HDD or something crazy. The code itself is safe and secure. It does need more optimization and such but as of now it does a decent job. I have only had about 3 days of work on it so far.
So I was able to import SoapUI fully into my Java project. You can follow the steps at the link I provided or just navigate to your SoapUI lib folder (as mentioned in my previous post) and download the 2 SoapUI specific Jar files and import them as well. After that, you need to create your project and WSDL/XSD. My line of code looks like the following:
WsdlProject project = new WsdlProject();
project.setName("Test");
WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, "//Path/to/my/WSDL", true)[0];
Next, I adjusted my endpoint to fit my test host
String host = "//My/Test/Host";
String endpoint = iface.getEndpoints()[0].replaceAll("http.*?//.*?/",host);
iface.changeEndpoint(iface.getEndpoints()[0],endpoint);
After that, the majority of stuff falls into the standard SoapUI groovy language. I will post a small demo to set up a test step
WsdlOperation operation = (WsdlOperation) iface.getOperationByName("nameOfOperation");
operation.setName("nameOfOperation");
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();
parseNodes(nodes,operation.getName());
String XML = XmlUtils.prettyPrintXml(XmlUtils.createXmlObject(nodes.item(0).getParentNode()));
XML = XML.replaceAll( "(?s)<!--.*?-->","");
XML = insertParams(XML,operation.getName());
TStep.setPropertyValue("Request", XML);
project.saveAs("Test.xml");
System.exit(0);
I use a config file and properties file in order to set the parameters for the test case. Currently I use a function called insertParams in order to make this work how I like. The config file is stored in a map (propReader) which is stored in a map (config) which uses the testName as a key. The properties themselves are also stored in a map. Here's my insertParams function
static String insertParams(String XML,String testName) {
System.out.println(testName);
Map<String, String> propReader = config.get(testName.toLowerCase());
for (String key:propReader.keySet()) {
System.out.println(key);
XML = XmlUtils.setXPathContent(XML, key, properties.get(propReader.get(key).toLowerCase()));
}
return XML;
}
The majority of this is still in the testing phases but if your interested in a singular application that will allow you full control, this should do it. All you would have to do is create a GUI which builds the property files for your application and then set this to run the SoapUI project instead of just saving it. For more complex situations you will need to customize the code to build the XML properly. If anyone has any questions or suggestions please, please ask.
Note:
This is all built in Java, not within SoapUI itself. It uses a lot of the SoapUI functionality. I am not responsible if you accidentally wipe your HDD or something crazy. The code itself is safe and secure. It does need more optimization and such but as of now it does a decent job. I have only had about 3 days of work on it so far.
Related Content
- 6 years ago
- 8 years ago
- 5 years ago
Recent Discussions
- 15 years ago