Contributions
Re: How to use a defined variable elsewhere in a Groovy script?
Thank you for the reply, aaronpliu. My Groovy code is iterating through my multiple test step results using... for(stepResults in testRunner.getResults()) { // Retrieve Test Suite name def testSuite = testRunner.testCase.testSuite.name; // Retrieve Test Case name def testCase = testRunner.testCase.name; // Retrieve Test Step def testStep = stepResults.getTestStep(); // Retrieve Test Step name def testStepName = testStep.name // Retrieve Test Step type def type = testStep.config.type // Retrieve Test Step status def status = stepResults.getStatus() ... I had noted in a previous post (https://community.smartbear.com/t5/SoapUI-Pro/Output-Response-time-via-groovy/td-p/3500) that the following could be used to get response time: testRunner.testCase.testSteps["Request 1"].testRequest.response.timeTaken Since I've identified the test step name in my Groovy code as a variable called "testStepName", I'd like to create a new definition that replaces "Request 1" with the testStepName variable. Something like... def respTime =testRunner.testCase.testSteps["$testStepName"].testRequest.response.timeTaken The script, however, doesn't like how I'm trying to use the variable in that line. How should I invoke that variable within the brackets?1.2KViews0likes0CommentsHow to use a defined variable elsewhere in a Groovy script?
I am using Groovy scripting to create output files containing test execution results from SoapUI for a given test case. My test case contains several test steps, so I'm using the following logic to iterate through each test step and collect specific information (this is a snippet from the script): ... for(stepResult in testRunner.getResults()) { // Retrieve Test Suite name def testSuite = testRunner.testCase.testSuite.name; // Retrieve Test Case name def testCase = testRunner.testCase.name; // Retrieve Test Step def testStep = stepResult.getTestStep(); // Retrieve Test Step name def testStepName = testStep.name; // Retrieve Test Step type def type = testStep.config.type; // Retrieve Test Step status def status = stepResult.getStatus(); // Retrieve response time def respTime = testRunner.testCase.testSteps["Request 1"].testRequest.response.timeTaken; ... The question I have revolves around the line that I've highlighted in green (the last "def" statement). Since my script will process a number of test steps, I'd like to replace "Request 1" with a variable that reflects the test step name in order to get that particular test step's response time. So, I'm trying to use "$testStepName" (defined earlier in my snippet) in place of "Request 1", but I'm not getting anything as a result. Here's how I'm trying to apply it: def respTime = testRunner.testCase.testSteps["$testStepName"].testRequest.response.timeTaken; Am I referencing the variable correctly in my "respTime" definition? Or, is there a different approach I should take to get the response time for each of my steps? Thank you!1.3KViews0likes2Comments