I am on Katalon Studio v8.6.0, on Windows 11 machine.
I ran a collection of test suites last night, which have cleanup logic that relies on creating a @Field
, setting that in the @SetUp
method, and then reference that in the @TearDownTestSuite
method to decide to do teardown at the very end of the test suite.
It failed to clean up after itself… WHY.groovy !?
I create a dummy test suite, with script like:
import com.kms.katalon.core.annotation.SetUp
import com.kms.katalon.core.annotation.SetupTestCase
import com.kms.katalon.core.annotation.TearDown
import com.kms.katalon.core.annotation.TearDownTestCase
import groovy.transform.Field
/**
* Some methods below are samples for using SetUp/TearDown in a test suite.
*/
@Field
int field = 0;
/**
* Setup test suite environment.
*/
@SetUp
def setUp() {
// Put your code here.
field = 3;
}
/**
* Clean test suites environment.
*/
@TearDown
def tearDown() {
// Put your code here.
assert field == 3;
}
/**
* Run before each test case starts.
*/
@SetupTestCase(skipped = true) // Please change skipped to be false to activate this method.
def setupTestCase() {
// Put your code here.
}
/**
* Run after each test case ends.
*/
@TearDownTestCase(skipped = true) // Please change skipped to be false to activate this method.
def tearDownTestCase() {
// Put your code here.
}
/**
* References:
* Groovy tutorial page: http://docs.groovy-lang.org/next/html/documentation/
*/
When I run the test suite, it fails on tearDown
:
Back in February of this year, if I were to run this code, on v8.1.0, it would have passed. The actual code that I wrote back then was like:
import com.kms.katalon.core.annotation.SetUp
import com.kms.katalon.core.annotation.SetupTestCase
import com.kms.katalon.core.annotation.TearDown
import com.kms.katalon.core.annotation.TearDownTestCase
import com.signaturemd.pages.PracticePage
import com.signaturemd.profiles.PracticeProfile
import com.signaturemd.utils.SMDWebDriverUtils
import com.signaturemd.utils.recordHandler.PracticeProfileHandler
import groovy.transform.Field
import internal.GlobalVariable
/**
* Some methods below are samples for using SetUp/TearDown in a test suite.
*/
@Field
final PracticeProfile defaultProfile = GlobalVariable.practiceProfile;
@Field
final String practiceProfileName = "Demo practice5";
@Field
int initialPracticeCount;
/**
* Setup test suite environment.
*/
@SetUp
def setUp() {
GlobalVariable.practiceProfile = PracticeProfileHandler.GetInstance().getPracticeProfile(practiceProfileName);
SMDWebDriverUtils.DoWebAction {
PracticePage page = new PracticePage(GlobalVariable.practiceProfile);
page.go();
initialPracticeCount = page.getNumberOfContracts();
}
}
/**
* Clean test suites environment.
*/
@TearDown
def tearDown() {
SMDWebDriverUtils.DoWebAction {
PracticePage.DeleteContractsIfNeeded(GlobalVariable.practiceProfile);
}
GlobalVariable.practiceProfile = defaultProfile;
PracticeProfileHandler.GetInstance().close();
}
/**
* Run before each test case starts.
*/
@SetupTestCase(skipped = true) // Please change skipped to be false to activate this method.
def setupTestCase() {
// Put your code here.
}
/**
* Run after each test case ends.
*/
@TearDownTestCase
def tearDownTestCase() {
PracticePage page = new PracticePage(GlobalVariable.practiceProfile);
page.go();
PracticePage.NewContractsCreated += (page.getNumberOfContracts() - initialPracticeCount);
}
/**
* References:
* Groovy tutorial page: http://docs.groovy-lang.org/next/html/documentation/
*/
This seems to be consistent with a regression on @Field
s in test suite scripts: that either attempts to set non-final @Field
s don’t work, or they lose their state after @SetUp
…