Skip to content

Instantly share code, notes, and snippets.

@gerbrand
Last active April 7, 2016 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerbrand/9681875 to your computer and use it in GitHub Desktop.
Save gerbrand/9681875 to your computer and use it in GitHub Desktop.
A SOAPUI-project file contained a testsuite. The testsuite consisted of (xml) requests to a certain rest-service. I wanted to extract all those request-messages to use them in my own test. Doing that by hand was a bit cumbersome and boring. I decided to write a small script for do that in Scala. Writing the script was a lot easier then doing it …
import scala.xml._
import java.io._
/**
* Small script to extract the request-xml-messages from a soapui project
*/
object SoapUIExtractor extends App {
def writeTestStep(teststep:Node) {
val requestContent = (teststep \ "config" \ "restRequest" \ "request").head.child(0).text
val testCaseName = (teststep \ "@name").head.text
val filename = testCaseName+".xml"
println(filename)
val writer = new PrintWriter(new File( filename ))
writer.write(requestContent)
writer.close()
println(requestContent)
}
val soapUI = XML.loadFile("my_soapui-project.xml")
//extract all test cases and write the request-xml that's contained in each test-case
(soapUI \\ "soapui-project" \ "testSuite" \ "testCase" \ "testStep" ).foreach ( r => writeTestStep(r) )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment