krogold
4 years agoRegular Contributor
Setup script execution from another groovy step
Hello,
I have several testCases in my project for which the setup script cleans the properties (generated dynamically during testCase execution). In order to clean my project before GIT commit, I wish to clear those dynamic properties and I created a testCase with a groovy script that parses all my project's testCases and, if the setup script cleans the properties, execute it. However, though my detection is correct, the script execution does not occur.
Am I missing something ? here is my script :
/* check setup scripts
if those contain
testRunner.testCase.getPropertyList().each{
testRunner.testCase.removeProperty(it.name)
}
it means that, prior to execution the setup script will clear data that will be (re)created during test execution
it means that this data is likely to be detected as a relevant modification in git though it is not
to avoid this this script will detect which test has such a setup script and will execute the setup script
in order to delete these dynamic properties
*/
testRunner.testCase.testSuite.project.testSuiteList.each
{
suite ->
name = suite.getName()
// if (name == "USE CASES - Configuration")
if ((name.contains("USE CASES -"))||(name.contains("TOOLS - Configuration")))
{
suite.testCaseList.each{
TC ->
if ((TC.setupScript != null)&&(TC.setupScript.contains("removeProperty")))
{
log.info "concerned test " + suite.getName() + " ; " + TC.name
TC.runSetupScript(context, testRunner)
}
}
}
}
Finally I found out how to do it : it requires to modify context.ExecutionID
/* check setup scripts if those contain testRunner.testCase.getPropertyList().each{ testRunner.testCase.removeProperty(it.name) } it means that, prior to execution the setup script will clear data that will be (re)created during test execution it means that this data is likely to be detected as a relevant modification in git though it is not to avoid this this script will detect which test has such a setup script and will execute the setup script in order to delete these dynamic properties */ testRunner.testCase.testSuite.project.testSuiteList.each { suite -> name = suite.getName() if ((name.contains("USE CASES -"))||(name.contains("TOOLS - Configuration"))) { suite.testCaseList.each{ TC -> if ((TC.setupScript != null)&&(TC.setupScript.contains("removeProperty"))) { s_script = TC.setupScript // store the script TC.setSetupScript(null) // clear setup script // neutralize init_test_case sscript = s_script.replace("setup.init_test_case","//setup.init_test_case") sleep(1000) TC.setSetupScript(sscript) // replace initial setup script // execute the modified setup script to clean properties without launching init context.ExecutionID = TC.config.id TC.runSetupScript(context, testRunner) // restore initial setupScript // re-enable setup init TC.setSetupScript(s_script) } } } }