Search code examples
seleniumselenium-webdrivercucumbercucumber-jvmcucumber-junit

how to give a unique serial number to each scenario in a feature file using cucumber jvm and selenium webdriver


Since there are too many scenarios , when there is failure or error I find it difficult to jump to the scenario which has the problem.

Is there a way to give a unique number to each scenario so that it is easy to map and can be used in logging too .

I am using selenium webdriver with cucumber jvm and pageobjects.

eg of feature file :

    #1
    @regression @CPM_PI @visibility
    Scenario Outline: To check if CPMPI panel is visible
    Given Go to Nerd
    And set Team="CTM"
    And set Client="PQR"
    And set Broker="ABC"
    And select Product="CPM"
    And set Revenue"1000000"
    And set Revenue(CY)="500000"
    And tick Coverages="CPM/PI"
    And select Main Activity="<MainActivity>"
    Then check CPMPI visible


    #2
    @regression @CPM_PI @visibility
    Scenario: To check visiblity of all CPMPI panels
    Given Go to Nerd
    And set Team="CTM"
    And tick Cyber 
    Then check panel Cyber visible

Solution

  • You can simply "tag" your scenario names like:

    Scenario Outline: Scenario 1: To check if CPMPI panel is visible
    Given Go to Nerd
    And set Team="CTM"
    And set Client="PQR"
    And set Broker="ABC"
    And select Product="CPM"
    And set Revenue"1000000"
    And set Revenue(CY)="500000"
    And tick Coverages="CPM/PI"
    And select Main Activity="<MainActivity>"
    Then check CPMPI visible
    
    
    #2
    @regression @CPM_PI @visibility
    Scenario: Scenario2: To check visiblity of all CPMPI panels
    Given Go to Nerd
    And set Team="CTM"
    And tick Cyber 
    Then check panel Cyber visible
    

    Make it a habit to give your scenario tagged names