import com.kms.katalon.core.exception.StepFailedException
...
try {
//Something in this method
} catch (StepFailedException ex) {
//call on test case 2
} finally {
//delete the data created
}
Hi,
how would this try-catch block know if the test case failed, not just a test step? let’s say the test failed at any given steps… once the test case fails (at any step), I need the test to do something.
I basically needs to know the result of the test case fail… is there a way to get that?
i was thinking something along this line:
def status = test case?
If status of test case == ‘Fail’
// then do this
else
//do this
I suppose you don’t understand the basic of Java Programing language: Exception, try { … } catch { … } .
Unless you understand what Exception is, how try {} catch {} works, you would not be able to reach to a solution. You should buy a good Java book, such as Core Java I, and read the first few chapters.
The closest you can get to what you want is to use something like the following…
First, let’s look at how a typical test case is presented:
// Imports
// Step 1
// Step 2
...
// Step n
To gain some control over all steps AND “take another action when a test case fails”, you can give Katalon a single entry point into your own class. Technically, this is a class within a class, an inner class, since your test case itself lives inside a run() method of a class you cannot ordinarily see.
In the following, you can place your test steps inside the constructor for the new inner class:
// Imports
public class Test {
Test() {
// Step 1
// Step 2
...
// Step n
}
}
try {
new Test()
passThisTest()
} catch(Exception e) {
failThisTest(e.message)
}
You can code passThisTest() and failThisTest() to do anything you want.
Sorry for the late response…
So I’ve tried to do something of this nature, I have a test ase that uses Key Stroke, but I’m trying to suport that action for both Windows and Mac.
i.e -
can’t I use TearDown() function on specific tests that needs to do something if entire test fails? In theory, will it not call that function in the end of the test run whether it fails or pass?
I’m sorry, but that is a bullshit way to do it. You shouldn’t do try-catch for something like this, StepFailedException could throw for any number of reasons, outside an operating system not having a certain key.
Try this instead:
public final class GeneralWebUIUtils {
public static Keys GetCommandKey() {
final String os = System.getProperty("os.name")
if (os.toUpperCase().contains("WINDOWS"))
return Keys.CONTROL;
return Keys.COMMAND;
}
}