Rayrun
← Back to Discord Forum

Combination of features/tiers/userTypes

jesus_20988posted in #help-playwright
Open in Discord

hello there people. We recently started to implement E2E tests for the product we developed in my company. Now, this product is going to have different types of subscriptions (Free, Basic, Premium), but in addition, within each of the subscriptions we have roles, (user, manager, admin).

I'm finding it difficult how to structure all of this, as I want to avoid duplicating code but make it easy to maintain. That is to say, if for whatever reason some tier changes, it should be easy to maintain.

I have experience using WDIO with Cucumber, and I remember that Outline Scenarios could be a perfect candidate, where we have a table for each tier, and we run the scenario for all the necessary roles etc. I'm not quite sure how to approach this using the Playwright runner (which I don't want to stop using because we already have a lot of things configured and adapted to this runner).

Any ideas or links so I can dig further?

Something like this:

Feature: Add product to the cart

  Scenario Outline: <Role> adds product to the cart
    When the <Role> click on the "Add product to the cart"
    Then the <Role> should see the product added to the cart

  @free # only admin can add products to the cart
  Examples:
    | role  |
    | admin |

  @basic # manager and admins can add products to the cart
  Examples:
    | role    |
    | manager |
    | admin   |

  @premium
  Examples:
    | role    |
    | user |
    | manager |
    | admin   |

This thread is trying to answer question "How to structure E2E tests that cover different subscriptions (Free, Basic, Premium) and roles (user, manager, admin) using Playwright without duplicating code?"

8 replies
tphillips8117

How do you change between subscriptions? Different users?

tphillips8117

might be worth having a table that links users to their role and subscription

tphillips8117

And a column for the expected result too, whether or not they can add products to the cart

tphillips8117
Feature: Shopping Cart Permissions based on User Roles and Subscriptions

  Scenario Outline: Adding items to the cart based on user roles and subscriptions
    Given a <user_role> user with a <subscription> subscription is logged in
    When they attempt to add items to the cart
    Then they <ability> items to the cart

    Examples:
      | user_role | subscription | ability         |
      | User      | Free         | cannot add      |
      | Manager   | Free         | cannot add      |
      | Admin     | Free         | can add         |
      | User      | Basic        | cannot add      |
      | Manager   | Basic        | can add         |
      | Admin     | Basic        | can add         |
      | User      | Premium      | can add         |
      | Manager   | Premium      | can add         |
      | Admin     | Premium      | can add         |
tphillips8117

That said, not a playwright-specific question

tphillips8117

It would be up to you to sort out how to implement the Given a <user_role> user with a <subscription> subscription is logged in

Before each scenario, we run a fixture to create the customer with the right role and subscription. So, thats something given with the "background" lets say.

Yeah, we can also have that table, im aware. My question is more like, we dont have cucumber in our framework. We have plain Playwright, so we have to use the test.describe, beforeEach, etc. We can't create a "template" sceneario/tests, then read the table and execute each particular case. If we use cucumber, we lost the hability to run those scenarios with the PW runner

We might need to use something like this: https://vitalets.github.io/playwright-bdd/#/

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].