Search code examples
javaseleniumcucumberqaf

Cucumber Scenario: getSourceTagNames() inconsistently returns list in random order


I am trying to implement an automated evidence capture system for each cucumber scenario that is executed. As part of that I need to use the first scenario @tag as part of the evidence folder name.

However, I have found that the getSourceTagNames() method on a cucumber scenario returns the list in a random order, compared to the order in which the tags were written. So simply calling scenario.getSourceTagNames().get(0) will not consistently give me the tag I need.

e.g Scenario: Example @tagINeed @secondTag @thirdTag

getSourceTagNames() may return {@thirdTag, @tagINeed, @secondTag}

Is there a way to ensure the list returned is in the same order as the order in which it was written?


Solution

  • What you are looking for can be achieved using gherkin with qaf, you will be able to access tags in order they defined for example:

    @tagINeed @secondTag @thirdTag
    Scenario: Example 
    

    Java code:

    scenario.getGroups()[0];//will return "@tagINeed"
    

    If you will use BDD2 syntax instead of gherkin, you can have meta-data with scenario. For example:

    @TestID:ABC-123
    @Evidence:tagINeed @firstTag @secondTag
    Scenario: Example 
    

    Java code:

    scenario.getMetaData().get("Evidence");//will return "tagINeed"
    scenario.getGroups()[0];//will return "firstTag"