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.2KViews0likes4CommentsSetup and Tear down, as well as Try Catch questions.
Hello, I am fairly new to TestComplete, so please bear with me. I am using TestComplete to test a windows application. I am more used to the NUnit side of things. In NUnit, you can have setup and teardown functions that will run before any test as well as after any test, even if there is an failure in that test. Does TestComplete have this kind of functionality? If it does not, is there any easy work around to always be in a consistent state for each test? Also, I am trying a try catch block using JavaScript in TestComplete. Basically to try to close my app, and if it cannot, catch by writing to the log. My problem is, if inside the try look, there is an error, the test just stops. So, I am unsure why it just doesnt kick to the catch, and move on like nothing is wrong. Is this expected, and if so, what is the point of try catches in TestComplete. Thanks for all of your time.3.1KViews0likes8Comments