Skip to content

Instantly share code, notes, and snippets.

@MarkZhangTW
Last active August 14, 2020 06:09
Show Gist options
  • Save MarkZhangTW/d7dadaad0adbca74f6ced722da817bcd to your computer and use it in GitHub Desktop.
Save MarkZhangTW/d7dadaad0adbca74f6ced722da817bcd to your computer and use it in GitHub Desktop.
Groovy script for SoapUI
// Random Request Script
def list = []
new File('C:/Users/HSChang/Documents/Work/AML/Requests').eachFile { list << it }
def filename = list[new Random().nextInt(list.size())]
log.info(filename)
def request = context.testCase.getTestStepByName('VaryRequest').getTestRequest()
request.setRequestContent(new File(filename.getPath()).getText("UTF-8"))
// Save Output Script
def filename = "C:/Users/HSChang/Documents/Work/AML/Responses/" + new Date().format("yyyyMMddHHmmssSSS") + ".xml"
def response = context.expand( '${VaryRequest#Response}' )
def f = new File(filename)
f.write(groovy.xml.XmlUtil.serialize(response), "UTF-8")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment