ocherevkova
3 years agoOccasional Contributor
How to disable test cases in the setup script based on TC tag?
I have several test cases in my test suite with a specific tag.
How to make them disabled depending on project env in the test suite setup script?
Hi ocherevkova .
Below should do the trick. I took as environment name "tst" and test case tag "smoke", so you'll have to adjust these to your need.
def activeEnvironmentName = testSuite.project.activeEnvironment.name
def testCaseList = testSuite.getTestCaseList()
def numberOfTestCasesInSuite = testCaseList.size()
for (i = 0; i < numberOfTestCasesInSuite; i++) {
def testCase = testSuite.getTestCaseAt(i)
testCase.setDisabled(false)
def testCaseTagIdList = testCase.getTagIds()
for (testCaseTagId in testCaseTagIdList) {
def testCaseTagName = testSuite.project.getTagById(testCaseTagId)
if (testCaseTagName == "smoke" && activeEnvironmentName == "tst") {
log.info testCase.getName() + " has required tag $testCaseTagName and we are running our tests against environment $activeEnvironmentName, so let's disable!"
testCase.setDisabled(true)
}
}
}