Forum Discussion
Hi aaronpliu,
Well done! Thanks for sharing the script with the Community :smileyhappy:
This TechCorner script gives you 2 points to your score in API Summer 2018!
Hi aaronpliu,
We have asked our Customer Care team to review the script. And, NBorovykh has noted that it outputs names assigned to HTTP methods on the Projects tab. In the meantime, the original task was to log the names of functional REST Request Test Steps associated with those methods.
So, do you mind improving your script so that it could do the following?
- The script should iterate through all the TestSuites, TestCases, and TestSteps in the project, find the associations between functional steps (on the SoapUI tab) and the REST API methods (on the Projects tab), and output this info to the file.
- The script should produce a better output when names of Resources and Methods in ReadyAPI UI are empty. Currently, it produces this:
- aaronpliu7 years agoFrequent 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_T7 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
- 8 hours ago
- 5 days ago