How to use external groovy script to save code repetition in setup/teardown scrips
Hi all, Am new to ReadyAPI and just trying to get head around groovy scripting. I have a lot of duplication in my test suites - mostly on setup/tear down methods and would like to be able to refactor into a reusable external script, which I can call from each test case. Currently script is being used to pull in an external xml data file as a request for each test case (some xml are too large to save with project) : def suiteName = testRunner.testCase.testSuite.name def testcaseName = testRunner.testCase.name //use suite name to get path to xml files log.info("suite name: " + suiteName) def splitName = suiteName.split("_"); def declarationOrInvoice = splitName[0] def type = splitName[1] //URL of data files on server(Utilities is an external file - just holding constant values) def baseURL = new Utilities().getBaseUrl() def fileName = baseURL + declarationOrInvoice + "\\" + type + "\\" + testcaseName + ".xml" log.info(fileName) //get file and add to project property def myRequest = new File(fileName).getText() testRunner.testCase.testSuite.project.setPropertyValue("request", myRequest) This is copied/pasted across multiple test cases. Is there a way I could move this to an external script, so if I need to make a change, am only changing it in 1 place? I am aware that you can initialise scripts with a testrunner/log/context etc, just not really sure how! If I have an external script, how would it know what test case is calling it? Many thanks in advance for any advice DaveSolved2.2KViews0likes4Comments