qmetry / qaf

Quality Automation Framework for web, mobileweb, mobile native and rest web-service using Selenium, webdrier, TestNG and Java Jersey
https://qmetry.github.io/qaf
MIT License
254 stars 138 forks source link

Unable to skip a QAFTestStep #450

Closed ajaysuryavamshi closed 1 year ago

ajaysuryavamshi commented 1 year ago

QAF Version - 2.1.14

Note: only the latest version is supported

Steps To Reproduce

1. Define a bdd file as below:
2. Run a config.xml file as below:
3. We would like to skip specific step in this case Test Step-3
4. We added a QAFTestStepListener
5. Added a below statements for beforeExecute(StepExecutionTracker stepExecutionTracker)
6. if(stepExecutionTracker.getStep().getDescription().contains("Test Step-3")) {
7. getBundle().setProperty(ApplicationProperties.DRY_RUN_MODE.key, true);
8. }
9. and afterexecute we will be setting it back to false

SCENARIO: Test Step SKIP Scenario META-DATA: {"description":"Test Step Skip Scenario", "groups":["Regression"]} Given Test Step-1 When Test Step-2 And Test Step-3 Then Test Step-4 END

Sample Config XML file

Expected behavior

Expecting Test Step-3 to be skipped

Actual behavior

Test Step-3 is getting executed

Is the issue reproducible on the runner?

Test case sample

Please, share the test case (as small as possible) which shows the issue

cjayswal commented 1 year ago

you are setting dryrun mode so it is expected to step get reported.

ajaysuryavamshi commented 1 year ago

I even tried by setting false but still all the steps are getting executed. Can you please help me here on how to skip a specific step on a condition

cjayswal commented 1 year ago

It worked for me as expected. Make sure you have registered listener. Here is what i tried with: Listener class:

package com.example.common;
...
public class QAFListenerImpl extends QAFListenerAdapter {

    @Override
    public void beforExecute(StepExecutionTracker stepExecutionTracker) {
        TestStep step = stepExecutionTracker.getStep();
        //stepExecutionTracker.getScenario().getSteps()
        if(stepExecutionTracker.getStep().getDescription().contains("Test Step-3")) {
            getBundle().setProperty(ApplicationProperties.DRY_RUN_MODE.key, true);
        }
    }

    @Override
    public void afterExecute(StepExecutionTracker stepExecutionTracker) {
        if(stepExecutionTracker.getStep().getDescription().contains("Test Step-3")) {
            getBundle().setProperty(ApplicationProperties.DRY_RUN_MODE.key, false);
        }
    }

}

Step Implementation:


    @QAFTestStep(description = "Test Step-1")
    public static void step1() {
        Reporter.log("Excecuted Test Step-1");
    }
    @QAFTestStep(description = "Test Step-2")
    public static void step2() {
        Reporter.log("Excecuted Test Step-2");
    }
    @QAFTestStep(description = "Test Step-3")
    public static void step3() {
        Reporter.log("Excecuted Test Step-3");
    }
    @QAFTestStep(description = "Test Step-4")
    public static void step4() {
        Reporter.log("Excecuted Test Step-4");
    }

BDD file:

 Scenario: Test Step SKIP 
    Given Test Step-1 
    When Test Step-2 
    And Test Step-3 
    Then Test Step-4
    And Test Step-1
 End

Report without listener: Commented listener registration to run without listener

# commented to run without listener
#qaf.listeners=com.example.common.QAFListenerImpl
image

Report with listener Registered full qualified name in properties file:

qaf.listeners=com.example.common.QAFListenerImpl
image