Search code examples
mavencucumbercucumber-jvmcucumber-java

Is it possible to execute same tags multiple times in maven command for cucumber project on different tag position?


I have 5 scenarios and those tags are @UserAddSaveButton, @UserEditSaveButton, @UserAddSaveContinueButton, @UserEditSaveContinueButton, @UserDelete

Now I want to execute all 5 scenario in below sequence @UserAddSaveButton, @UserEditSaveButton, @UserDelete, @UserAddSaveContinueButton, @UserEditSaveContinueButton, @UserDelete

See @UserDelete tag is used twice but when I execute Maven command it's executed only once and at last position is not working.


Solution

  • Nope, you can't achieve this with a single TestRunner file.

    Here are my 2 ways:

    Solution#1:

    1. Create 3 TestRunner files
    2. In your testng.xml file, create 4 <suite> tags that contains TestRunner test classes in this order - TestRunner1, TestRunner2, TestRunner3 and TestRunner2
    3. TestRunner1 to execute '@UserAddSaveButton, @UserEditSaveButton' tags
    4. TestRunner2 to execute '@UserDelete' tag
    5. TestRunner3 to execute '@UserAddSaveContinueButton, @UserEditSaveContinueButton' tags

    Now run your tests (as mvn test or from testng.xml), deletion scenario will be executed as mentioned in testng.xml order by TestRunner2 suite#2 and suite#4 as you expected.

    Solution#2:

    1. Make your deletion tests/steps in single function
    2. Create conditional hooks
    @After("@UserEditSaveButton or @UserEditSaveContinueButton")
    public void deletionSteps(){
    // your deletion steps goes here OR 
    // call your deletion step from here
    }
    
    1. Just have single TestRunner file for tags '@UserAddSaveButton, @UserEditSaveButton, @UserAddSaveContinueButton, @UserEditSaveContinueButton'
    2. The conditional @After hook will take care of performing the deletion (You can remove the deletion scenario from your feature file)

    However, non-technical users will not know that deletion is performed after the execution of @UserEditSaveButton OR @UserEditSaveContinueButton scenarios.