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

feat: add support for custom decorators #27

Merged
merged 4 commits into from
Dec 29, 2023
Merged

Conversation

SebastianSedzik
Copy link
Owner

Custom decorators

Custom decorators can be created using createTestDecorator and createSuiteDecorator functions

Test decorator

The createTestDecorator function enables the generation of custom test decorators.
Attempting to utilize a custom test decorator on a method that lacks the @test decoration will result in an error.

import { suite, createTestDecorator } from 'playwright-decorators';
import playwright from '@playwright/test';

const customTestDecorator = createTestDecorator('customTestDecorator', ({test, context}) => {
  // create code using hooks provided by test decorator...
  test.beforeTest(() => { /* ... */ })
  test.afterTest(() => { /* ... */ })

  // ...or Playwright hooks
  playwright.beforeEach(() => {
    // ...
  })
});

Then use it on @test decorator:

@suite()
class MyTestSuite {
  @customTestDecorator() // <-- Decorate test with custom decorator
  @test()
  async myTest({ page }) {
    // ...
  }
}

Suite decorator

The createSuiteDecorator function allows the creation of custom suite decorators.
Attempting to apply a custom suite decorator to a class that lacks the @suite decoration will result in an error.

import { suite, createSuiteDecorator } from 'playwright-decorators';

const customSuiteDecorator = createSuiteDecorator('customSuiteDecorator', ({suite, context}) => {
  // ...
});

Then use it on @suite decorator:

@customSuiteDecorator() // <-- Decorate suite with custom decorator
@suite()
class MyTestSuite {
  // ...
}

@SebastianSedzik SebastianSedzik merged commit a15afab into master Dec 29, 2023
1 check passed
@SebastianSedzik SebastianSedzik deleted the custom-decorators branch December 29, 2023 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant