cancel
Showing results for 
Search instead for 
Did you mean: 

Enabling and disabling test cases from test suite

SOLVED
Highlighted
Contributor

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

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Enabling and disabling test cases from test suite

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)


Regards,
Rao.
9 REPLIES
Community Hero

Re: Enabling and disabling test cases from test suite

Did you try the below?

testSuite.getTestCaseByName(strLabel).isDisabled()


Regards,
Rao.
Contributor

Re: Enabling and disabling test cases from test suite

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.

Community Hero

Re: Enabling and disabling test cases from test suite

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)


Regards,
Rao.
Contributor

Re: Enabling and disabling test cases from test suite

Perfect Rao!

 

 

What i tried was label but i was comparing the test case name from excel with the test label in test suite.It did not strike until i printed the testcaselist.

 

Thanks you for the help!

 

DisxlTestCase=testname+" (disabled)"
testSuite.getTestCaseList().each {
if (DisxlTestCase==it.getLabel().toString())
{it.disabled = false }
}

Contributor

Re: Enabling and disabling test cases from test suite

Basically, all would have worked.problem was the testcase label..

Frequent Contributor

Re: Enabling and disabling test cases from test suite

@nmrao is it possible to use the enable/disable scripts as part of even handler at project level to disable a particular TestCase/s by name in entire project?

Frequent Contributor

Re: Enabling and disabling test cases from test suite

at the project level if we need to disable a case for every suite, which handler is recommended

Frequent Contributor

Re: Enabling and disabling test cases from test suite

testsuiterunlistener.beforetestcase worked

Community Hero

Re: Enabling and disabling test cases from test suite

Good you figured it out!


Regards,
Rao.
2018 NEWS
Top Kudoed Authors