Forum Discussion
aaronpliu
Frequent Contributor
Hi Olga_T,
I enhanced scripts and attached below.
the topic is to print project structure from test steps?
// print project strucutre based on endpoints def space = {num -> ' ' * num} def stringBuilder = new StringBuilder() testRunner.testCase.testSuite.project.getInterfaceList().each{p -> // interface name stringBuilder.append("${p.name}\n") p.getOperationList().each{m -> //operation name if(m.name.size() < 1) stringBuilder.append("${space(5)} ==>Resource name is empty\n") else stringBuilder.append("${space(5)}${m.name}\n") m.getRequestList().each{r -> //http method name stringBuilder.append("${space(10)}${r.getMethod()}\n") //rest method name if(r.getRestMethod().name.size() < 1) stringBuilder.append("${space(15)} ==>Rest method name is empty\n") else stringBuilder.append("${space(15)}${r.getRestMethod().name}\n") } } } def writeToFile(def directory, def filename, def extension, def content){ if(! content.trim().isEmpty()){ def folder = new File(directory) if( ! folder.exists()) folder.mkdirs() new File("$directory/$filename$extension").withWriter{out -> out << content } } } writeToFile("C:/temp", "project_structure", ".txt", stringBuilder.toString()) //---------------------------------------------------------------------- // print project strucutre from test steps def str2 = new StringBuilder() def interfaceNameList = [] testRunner.testCase.testSuite.project.getTestSuiteList().each{testsuite -> testsuite.getTestCaseList().each{testcase -> testcase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.class).each{teststep -> // interface name if(! (teststep.testRequest.getInterface().name in interfaceNameList)){ interfaceNameList << teststep.testRequest.getInterface().name str2.append("${teststep.testRequest.getInterface().name}\n") teststep.testRequest.getInterface().getOperationList().each{m -> //operation name if(m.name.size() < 1) str2.append("${space(5)} ==>Resource name is empty\n") else str2.append("${space(5)}${m.name}\n") m.getRequestList().each{r -> //request method name str2.append("${space(10)}${r.getMethod()}\n") //rest method name if(r.getRestMethod().name.size() < 1) str2.append("${space(15)} ==>Rest method name is empty\n") else str2.append("${space(15)}${r.getRestMethod().name}\n") } } } } } } writeToFile("C:/temp", "project_structure2", ".txt", str2.toString())
Olga_T
7 years agoSmartBear Alumni (Retired)
Hi aaronpliu,
You have significantly improved the original script, and you are pretty close to the final version, good job! :cathappy:
There is some additional work that should be done though. Please take a look at the screencasts. We've cited the desired and the actual results of the script execution.
Current results: https://www.screencast.com/t/VqGaDbDAF
Desired results: https://www.screencast.com/t/sddpc6QLIHo -the script needs to output a single file
I'm attaching a sample project our engineers worked with. You can use it to play with your script.
Have a great day!
Related Content
- 4 years ago
Recent Discussions
- 5 days ago