Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: support several custom test instances #46

Open
vitalets opened this issue Aug 11, 2023 · 1 comment
Open

Feature: support several custom test instances #46

vitalets opened this issue Aug 11, 2023 · 1 comment
Labels

Comments

@vitalets
Copy link
Owner

Describe the problem
Currently only one custom test instance can be provided via importTestFrom option. In many cases this is no enough. Depending on project structure, different groups of tests may require own auto-fixtures, not applicable for other tests. Even without auto-fixtures sometimes it's more convenient to keep fixtures separated instead of having all-in-one test.extend.

Imagine we have an app that has 3 main parts: user login, todo list and administration of uses. Each part could have own Page Object Models and fixtures. Example structure:

features
    login.feature
    todolist.feature
    admin.feature
steps
   Login
      LoginPage.ts
      LogoutPage.ts
      fixtures.ts
   TodoList
      TodoListPage.ts
      TodoDetailsPage.ts
      fixtures.ts
   Admin
      UserList.ts
      UserDetails.ts
      fixtures.ts

Currently to run such tests with playwright-bdd we need to combine all fixtures.ts into one and point to it with importTestFrom.

Describe the solution
The solution I'm thinking about - is to refuse using importTestFrom at all. Technically, when we know all steps used in particular feature file, we can detect what test instance should be imported. To achieve it we need to switch from Cucumber's steps loading to own implementation (that is already used for decorator steps). To make it backwards compatible I can add new config option steps: string | string[] that should point to all steps definitions including fixtures. When steps option is defined, no need for Cucumber's require or import options and laso no need for importTestFrom. The config will looks very simple:

const testDir = defineBddConfig({
  paths: ['features'],
  steps: './steps',
});

Describe alternatives you've considered
Alternatively we can allow passing object to importTestFrom mapping different features with different test instances, e.g.:

const testDir = defineBddConfig({
  importTestFrom: {
    'features/Login': 'features/Login/fixtures.ts',
    'features/TodoList': 'features/TodoList/fixtures.ts',
    'features/Admin': 'features/Admin/fixtures.ts',
  },
  paths: ['features'],
  steps: './steps',
});

This is less convenient as we need manually sync changes in files structure with config.

@vitalets
Copy link
Owner Author

vitalets commented Nov 4, 2023

Playwright 1.39 introduced mergeTests helper that merge several test instances into one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant