Read .feature file in cucumber and copy content to new feature file

1.1k views Asked by At

Suppose, I have numerous scenarios under 1 feature file- GamePlay.feature.

Feature: Game play

@TestCase_1 @Regression
 Scenario: Breaker joins a game
    Given the Maker has started a game with the word "silky"
    When the Breaker joins the Maker's game
    Then the Breaker must guess a word with 5 characters

@TestCase_2 @Regression 
 Scenario: Breaker joins a game
    Given the Maker has started a game with the word "soft"
    When the Breaker joins the Maker's game
    Then the Breaker must guess a word with 4 characters

.
.
. and many more

Let's say I want to copy the test steps of Test case #2(Scenario, Given, When, Then) and paste them into new feature file (GameLost.feature). I'll search the scenario based on tags (For Ex -@TestCase_2) The new feature file GameLost.feature should look like -

Feature: Game lost

@TestCase_2 @Regression 
 Scenario: Breaker joins a game
    Given the Maker has started a game with the word "soft"
    When the Breaker joins the Maker's game
    Then the Breaker must guess a word with 4 characters

How can I do that in Java?

1

There are 1 answers

0
user861594 On

May be you can take benefit of bdd generator with qaf-cucumber. You should run in dry run mode with meta-data filter and generated files will have scenarios only with those meta-data (tags). BDD Generator generates feature file from your test authored in .bdd, .feature or .java file. If required, you can create your custom implementation same as BDDGenerator.