I have a business scenario to be tested, where if a condition is met, then mark the testcase as passed and termiate the test case execution and continue with other test case execution in Testuite.
String portMenu = "miami"
println('Execute Step 1')
println('Execute Step 2')
if(portMenu =="miami") {
println ("Exit the TC and mark the TC as passed.")
KeywordUtil.markPassedAndStop(" Test Success")
}
println('Execute Step 3')
println('Execute Step 4')
println('Execute Step 5')
I am looking for a keyword behaviour KeywordUtil.markPassedandStop(“”) which doesn’t exist. Is there a workaround to acheive it. [Want to handle in if block, without using the else block]
I like @Russ_Thomas’ approach (avoid “GOTO”). His approach helps making my code structured better.
I do not like the approach that uses the markPassedAndStop keyword. It is a sort of “GOTO” statement. It tends to make my code unstructured. It will make my code like a “Spaghetti”.
In Java/Groovy programming, you would/should never use “GOTO”. It is not necessary. No reason to introduce new “GOTO” named markPassedAndStop.
2022-11-19 07:50:52.624 INFO c.k.katalon.core.main.TestCaseExecutor - --------------------
2022-11-19 07:50:52.627 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/RussApproach3
Execute Step 1
Execute Step 2
2022-11-19 07:50:53.188 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/RussApproach3
This is clean, isn’t it?
It is far easier to read the code and understand what it will do, than the approach using “GOTO” keyword
2022-11-21 10:02:14.693 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/RussApproach4
Execute Step 1
Execute Step 2
2022-11-21 10:02:15.344 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/RussApproach4
do1stBlock() && do2ndBlock() makes a chain of closure calls. The chain is conditional. The following closure (do2ndBlock) is executed only when the preceding closure (do1stBlock) returned true.
We can extend the conditional chain of closures as long as we like:
This style will motivate you to structure your code as a composition of code blocks, not as a single sequence of a lot of statements with GOTO occasionally inserted.
Each component clousre can stop the chain by returning false. This behavior would be similar to markPassedAndStop keyword.
This might be a fly-weight alternative to Test Suite with capability to stop conditionally.
Of course, this style is advanced one; it is only possible using the “Script mode” of Test Case editor. You can not use this style in the “Manual mode” at all. — I don’t mind this, as I never use the Manual mode.