Marwa Abdelgawad Marwa Abdelgawad - 3 months ago 13
Groovy Question

Excluding testcases from testsuite properties in Soapui

I want to disable certain test cases based on the value of some test suite properties (i.e if the property IsActive1 = false, then testcase1 will be disabled).

I used this code at test suite setup script but got an error:

def testSuite = context.testCase.testSuite;
def totalTestCases = testSuite.getTestCases().size();
for(n in (0..totalTestCases-1)) {
if(testSuite.getTestCaseAt(n).name == "${#TestSuite#IsActive}"){
testSuite.getTestCaseAt(n).setDisabled(true)
}
}


How can I do that?

Rao Rao
Answer

Here is how I would go to achieve this.

  • Assuming that there is a suite with test cases, namely TestCase1, TestCase2, TestCase3, TestCase4, TestCase5. Using this approach, it would be a simple change of the property value to include or exclude the test case name to be disable. I believe that this would be better to change things from one place(single property) instead of changing IsActive property for each test case. If you have more cases to handle this would be a burden (going to each case and modify true or false for IsActive)
  • Create a custom property at test suite level, say DISABLE_TESTS with value (comma separated list to disable) as TestCase1, TestCase5

Here is the Setup Script at Suite level which would achieve to selectively execute the test cases.

/**
* Test Suite Setup Script
* Enable or disable selected list of test cases
* Based on the test suite property DISABLE_TESTS value
**/
//Disables a Test case
def disableTestCase(testCaze) {
    log.info "Disabling test case : ${testCaze.name}"
    testCaze.disabled = true
}

//Enables a Test case
def enableTestCase(testCaze) {
    log.info "Enabling test case : ${testCaze.name}"
    testCaze.disabled = false
}

//Read the test case names to enable and convert it to list
def disableList = testSuite.getPropertyValue('DISABLE_TESTS')?.split(',')?.collect { it.trim()} ?: []
log.info "List of test for disable: ${disableList}"
//Loop thru the test cases and enable or disable
testSuite.testCaseList.each { kase ->
    //If the above list contains test case name disable, enable otherwise
    if (disableList && disableList.contains(kase.name)) {
        disableTestCase(kase)
    } else {
        enableTestCase(kase)
    }
}

Since some of the cases are disabled, it would be good to enable all the cases as part of Test Suite Teardown Script. It would look mostly same, but there wont be any condition.

/**
* Test Suite Teardown Script
* Which enables all the test cases after selective execution
**/
//Enables a Test case
def enableTestCase(testCaze) {
    log.info "Enabling test case : ${testCaze.name}"
    testCaze.disabled = false
}

//Loop thru the test cases and enable
testSuite.testCaseList.each { kase ->
    enableTestCase(kase)    
}