0

I'm facing issues with reusing feature file. I have added checkout feature file to place an order. My purpose is to reuse this feature file in other scenarios as well?

Feature: Checkout

  @checkout
  Scenario Outline: checkout
    Given I navigate to application home page
    When I search for keyword "<Search>"
    When I click on searched result "<Search>"
    Then I verify the checkout page "<Search>"
    When I click on Get Tickets button
    When I enter the fields values of buyer and Ticket information
    And I enter the payment details and click on Pay Now button
    Then I verify the payment will be successful

    Examples:
      |Search|
      |Test Event|

For eg: I have created another scenario "checkout with applied discount code" and it's reusing few steps from "checkout" feature file(bold text)

Feature: Checkout with applied discount code

  @discount
===============================================
    **Given I navigate to application home page
    When I search for keyword "<Search>"
    When I click on searched result "<Search>"
    Then I verify the checkout page "<Search>"
    When I click on Get Tickets button
    When I enter the fields values of buyer and Ticket information**
=================================================
    When I apply "CODE10" discount code
    And I enter the payment details and click on Pay Now button
    Then the discount will be applied on order total

    Examples:
      |Search|
      |Test Event|

I have added reusable steps in common file so that I don't have to create separate step file for both feature files.

Now framework is expanding and I need to reuse "Checkout feature" file in other scenarios as well.

Options I have in mind:

  1. Use checkout feature as a background step in new feature file: Problem Background step will have 8-10 lines.

  2. Refractor feature file to exclude implementation details like click, search , enter values and create methods in page file and reuse those methods in new feature file.

Need guidance on how to approach reusability so that I don't have to refractor code multiple times?

Any other ways to reuse feature file?

Sara
  • 19
  • 6
  • 1
    Possible duplicate - https://stackoverflow.com/questions/10812758/is-it-possible-to-reuse-a-feature-as-the-given-for-another-feature – Naveen Honest Raj Jul 09 '21 at 19:54
  • 1
    Does this answer your question? [Is it possible to reuse a feature as the "Given" for another feature?](https://stackoverflow.com/questions/10812758/is-it-possible-to-reuse-a-feature-as-the-given-for-another-feature) – Greg Burghardt Jul 10 '21 at 13:09
  • I think so..Thanks for the link – Sara Jul 12 '21 at 17:04

0 Answers0