0

I've encountered a wierd behaviour of a groovy script when running the whole suite. I have a script which orders my testcases alphabetically before they run and it seems to be running forever even when the whole test suite finishes.

enter image description here

After I click on it to see details and immediately go back to test suite it shows that it's finished and no longer running.

Is there something wrong with my script please? I don't see any infinite loops or anything like that. Is it just a bug in the ReadyAPI? Thanks for advice.

My sorting script:

ArrayList<String> testCaseList = new ArrayList<String>();
for (testCase in testRunner.testCase.testSuite.getTestCaseList()) {
 testCaseList.add(testCase.getName());
}
testCaseList.sort();
int i = 0;
for (tCase in testCaseList) {
 def curCase = testRunner.testCase.testSuite.getTestCaseByName(tCase);
 curIndex = testRunner.testCase.testSuite.getIndexOfTestCase(curCase); 
 testRunner.testCase.testSuite.moveTestCase(curIndex,i-curIndex);
 i++; 
}
Rao
  • 20,781
  • 11
  • 57
  • 77
Dropout
  • 13,653
  • 10
  • 56
  • 109

1 Answers1

2

Currently, looks you have separate test case for sorting. But actually, that is not a valid test case of yours.

So, the first change to be made is that the script should be moved from test case to Setup Script of test suite.

Here is the Test Suite's Setup Script which does it alphabetical order. Should be paid special attention in case if the test case names have numbers in it, have to do natural order. Otherwise, it should be ok.

Please follow the in-line comments.

//Get the sorted order of the test case which is expected order
def newList = testSuite.testCaseList.name.sort()
log.info "Expected order of test cases: ${newList}"

//Get the current index of the test case
def getTestCaseIndex = { name -> testSuite.getIndexOfTestCase(testSuite.getTestCaseByName(name))}

//Closure definition and this is being called recursively to make the desired order
def rearrange
rearrange = {
    def testCaseNames = testSuite.testCaseList.name
    if (testCaseNames != newList) {
        log.info testCaseNames
        newList.eachWithIndex { tc, index ->
            def existingIndex = getTestCaseIndex(tc)
            if (index != existingIndex) {
                testSuite.moveTestCase(index, existingIndex-index)
                rearrange()
            }
        }
    } else {
        log.info 'All cases sorted'
    }
}

//Call the closure
rearrange()

With that Setup Script, when test suite is executed, automatically the test cases are moved alphabetically. Hence, no separate test case required for just ordering.

Now, the suite gets executed with desired test cases and the current issue mentioned in the question should not be there at all.

Rao
  • 20,781
  • 11
  • 57
  • 77
  • For some reason this turned out to be too messy and made the ReadyAPI bug out and forced me to reload my project. It may be a problem on my side though. Anyway, as you stated having my script as a setup script works perfectly and solves my problem. Thank you very much for your help! – Dropout Dec 05 '17 at 10:14