Saturday 18 May 2013

Enable and Disable Test Cases in SoapUI using Groovy

Hi,

If you require to get the list of of test cases of a test suite under SoapUI project, use the below code with in groovy step:


// **** Test case list
// Create testSuite object

def oTestSuite = testRunner.testCase.testSuite;

// Get the array of test cases
def iTotalTestCases = oTestSuite.getTestCaseList().name

// Fetch list of test case and their name
for(testCaseCounter in (0..(iTotalTestCases.size-1)))
{    
log.info iTotalTestCases[testCaseCounter]
}




// **** Below Code is on the basis of  index value
// Create testSuite object
def oTestSuite = testRunner.testCase.testSuite;

// Get the count of test cases in a testSuite
def iTotalTestCases = oTestSuite.getTestCases().size();

// List down the name of each test Case with in a test suite
for(testCaseCounter in (0..iTotalTestCases-1))
{  
def sTestCaseName = oTestSuite.getTestCaseAt(testCaseCounter).name
log.info sTestCaseName
}

SnapShot:



** Note: Result in sequential order as shown in above snapshot

## Disable Test Cases in SoapUI using groovy
// ***** Code to disable test step using its name:
def oTestSuite = testRunner.testCase.testSuite;
oTestSuite.getTestCaseByName("TestCase 1").setDisabled(true)

if require to disable all cases within a test suite in one go then use below code:


// Create testSuite object

def oTestSuite = testRunner.testCase.testSuite;

// Get the array of test cases
def iTotalTestCases = oTestSuite.getTestCaseList().name

// Fetch list of test case and their name
for(testCaseCounter in (0..(iTotalTestCases.size-1)))
{    
oTestSuite.getTestCaseByName(iTotalTestCases[testCaseCounter]).setDisabled(true)
}



## Enable test cases in SoapUI using groovy


// ***** Code to enable test step using its name:
def oTestSuite = testRunner.testCase.testSuite;
oTestSuite.getTestCaseByName("TestCase 1").setDisabled(false)


if require to enable all step in one go then use below code:

// Create testSuite object

def oTestSuite = testRunner.testCase.testSuite;

// Get the array of test cases
def iTotalTestCases = oTestSuite.getTestCaseList().name

// Fetch list of test case and their name
for(testCaseCounter in (0..(iTotalTestCases.size-1)))
{    
oTestSuite.getTestCaseByName(iTotalTestCases[testCaseCounter]).setDisabled(false)
}



Point to be remember:  Above code will work only when call with in groovy step of a test case because it is using SoapUI predefined variable i.e. "testRunner" which works only under Groovy Test Step of a Test Case.

No comments:

Post a Comment