Forum Discussion

tlausg's avatar
14 years ago

Clone Test Cases, change global variables?

We're doing API testing on our REST services with SoapUI right now, and there are a few parameters for each test case that we want to change, then retest. For example, there is a parameter in all test steps called device which identifies a different mobile device for a specific response for each device. Right now, after we clone the test, we have to go to each step to change the parameter, and this can get tedious. Is there a way to automatically do this?
  • deepesh_jain's avatar
    deepesh_jain
    Frequent Contributor
    Hi tlausg,

    You can do this easily using groovy script. Access properties on a test case (or a test step) level like below:

     
    def project = testRunner.testCase.testSuite.project ;
    def tsuite = testRunner.testCase.testSuite ;
    def tcase = testRunner.testCase;
    test1 = project.testSuites["${tsuite.getName()}"].testCases["${tcase.getName()}"];
    test1.removeProperty("device");
    test1.addProperty("newProperty");
    test1.setPropertyValue("newProperty","newValue");


    If you don't need to update the property itself in each test case and just want to update the property value, remove lines 5 and 6 from the code above and update line 7 as required. You can have this code either from a test case at a suite level and update all the other test cases in that suite, by repating and modifying the lines 4-7 as required.

    Hope this helps.

    Thanks,
    Deepesh Jain