Forum Discussion

TesterNo1's avatar
TesterNo1
Contributor
10 years ago

Enabling and disabling test cases from test suite

I have excel with all test cases for the suite.My req is to disable all testcases from test suite start  up script when the test begins.Based on if the test case is set for run (one excel cloumn would read "yes" for run),i would be enabling the tets cases that are required to be run.

 

So,I am trying to Enable and Disable test case from Test Suite level.

 

From Test suite level start up script,
i am trying as below

isDisabled=runner.testSuite.getTestCaseByName(strLabel).isDisabled() 
if (isDisabled!=true) 
{runner.testSuite.getTestCaseByName(TestCaseLabel).disabled=true} 



throws error ---cannot invoke method on null object.

Scenario 2:
Trying to enable all disabled test cases from start up script.

runner.testSuite.getTestCaseByName(strExcelTestCase).disabled=false

again same error.Please help.This is stopping the framework development

  • nmrao's avatar
    nmrao
    10 years ago

    If you want to just enable  all the cases :

    testSuite.testCaseList.each { it.disabled = false }

    To disable:

    testSuite.testCaseList.each { it.disabled = true }

     

    To enable a test case by name:

    testSuite.testCases['TestCase 1'].disabled = false //you may change test case name.

    To disable:

    testSuite.testCases['TestCase 1'].disabled = true //you may change test case name.

     

    Does it help?

     

     

    EDIT: Was little confusing, after looking into details, then come to know the following:

    Are you using Test Case label in your script instead of Test Case name? There is a difference.

    log.info testSuite.testCases['TestCase 1'].name
    log.info testSuite.testCases['TestCase 1'].label

    Output:

    Wed Dec 09 07:15:07 IST 2015:INFO:TestCase 1
    Wed Dec 09 07:15:07 IST 2015:INFO:TestCase 1 (disabled)
  • nmrao's avatar
    nmrao
    Champion Level 3
    Did you try the below?

    testSuite.getTestCaseByName(strLabel).isDisabled()
    • TesterNo1's avatar
      TesterNo1
      Contributor

      Thanks Rao for responding.

       

      Tried  isDisabled=testSuite.getTestCaseByName(TestCaseLabel).isDisabled() and see same error

       

       

       

      Scenario 1.:When are test cases are enabled manually and script is run ,disabling works.Also,above statement works when all test cases enabled.returns False which is right.

      Scenario 2:When test cases are disabled and i use the above statement,it throws error.

       

      cannot invoke isdisabled() on null object.

       

      attached a snapshot.

      • nmrao's avatar
        nmrao
        Champion Level 3

        If you want to just enable  all the cases :

        testSuite.testCaseList.each { it.disabled = false }

        To disable:

        testSuite.testCaseList.each { it.disabled = true }

         

        To enable a test case by name:

        testSuite.testCases['TestCase 1'].disabled = false //you may change test case name.

        To disable:

        testSuite.testCases['TestCase 1'].disabled = true //you may change test case name.

         

        Does it help?

         

         

        EDIT: Was little confusing, after looking into details, then come to know the following:

        Are you using Test Case label in your script instead of Test Case name? There is a difference.

        log.info testSuite.testCases['TestCase 1'].name
        log.info testSuite.testCases['TestCase 1'].label

        Output:

        Wed Dec 09 07:15:07 IST 2015:INFO:TestCase 1
        Wed Dec 09 07:15:07 IST 2015:INFO:TestCase 1 (disabled)