Skip Test Cases
In this article, we demonstrate how to skip test cases in a test suite by preconfiguring a Test Listener with the TestCaseContext.skipThisTestCase()
method. To learn more about the usage of Test Listeners, go to Test Listeners (Test Hooks).
Skip Test Cases
- In the Test Explorer panel, right-click on Test Listeners. Select New > New Test Listener.
A New Test Listener dialog opens. Give it a name, such as Skiptest. Choose Generate sample Before Test Case method. Click OK.
Katalon Studio generates a sample template with the necessary annotations, libraries and supported functions as below:
import internal.GlobalVariable as GlobalVariable
import com.kms.katalon.core.annotation.BeforeTestCase
import com.kms.katalon.core.annotation.BeforeTestSuite
import com.kms.katalon.core.annotation.AfterTestCase
import com.kms.katalon.core.annotation.AfterTestSuite
import com.kms.katalon.core.context.TestCaseContext
import com.kms.katalon.core.context.TestSuiteContext
class Skiptest {
/**
* Executes before every test case starts.
* @param testCaseContext related information of the executed test case.
*/
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
println testCaseContext.getTestCaseId()
println testCaseContext.getTestCaseVariables()
}Use the
TestCaseContext.skipThisTestCase()
method to skip test cases. See also: skipThisTestCase()Inside the Skiptest Listener, copy and paste the following code under the generated sample template.
// To check for the desired condition and skip the test case if true.
if(inputyourconditionhere)
{ testCaseContext.skipThisTestCase()
}- Return to your test suite and run it. Check the results in the Results tab to see the final status of your tests.
Katalon Studio supports exporting test reports inHTML, CSV, PDFand JUnit. You can learn more about exporting reports here: Generate reports.
Example
In this example, we want to skip the Test Case named: "Google" in a test suite. We input the following sample code in the Skiptest Listener:
class Skiptest {
/**
* Executes before every test case starts.
* @param testCaseContext related information of the executed test case.
*/
@BeforeTestCase
def sampleBeforeTestCase(TestCaseContext testCaseContext) {
println testCaseContext.getTestCaseId()
println testCaseContext.getTestCaseVariables()
if ((testCaseContext.getTestCaseId()) == "Test Cases/Google")
{ testCaseContext.skipThisTestCase()
}
}
Check the results after running the Test Suite. Katalon successfully skips the test case named: "Google".