Search code examples
seleniumqaf

QAF | How to fail a custom step?


I have created a custom step in which I'm doing some calculations. I need to pass or fail the step according to the outcome of the calculations. Presently step always shows pass in the report even when the calculation fails. Also, I would like to know how to pass the fail note to the report as I can see it is implemented in common steps.

I'm using QAF version 3.0.1

Below is a sample example:

@QAFTestStep(description = "I check quantity")
    public static void iCheckQuantity() {
         String product = getBundle().getString("prj.product");
         Int availableStock = getBundle().getString("prj.aStock");
         Int minStock = getBundle().getString("prj.minStock");

         if (availableStock < minStock) {
               // I want to fail the step here telling - minimum stock required to run the test for "product" is "minStock" but presenlty available is "availableStock"
          } 
    }

Solution

  • I was able to figure out the answer.

    import com.qmetry.qaf.automation.util.Validator.*;
    
    assertFalse(true, "FAIL message here", "SUCCESS message here");
    
    

    The below links were useful to understand more on verifications and also on different types of verifications/assertions available in QAF.

    Refer: https://qmetry.github.io/qaf/latest/assertion_verification.html https://qmetry.github.io/qaf/latest/javadoc/com/qmetry/qaf/automation/util/Validator.html