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

Support Playwright component testing #1784

Closed
3 of 4 tasks
jan-molak opened this issue Jul 7, 2023 · 1 comment
Closed
3 of 4 tasks

Support Playwright component testing #1784

jan-molak opened this issue Jul 7, 2023 · 1 comment
Labels
@serenity-js/playwright @serenity-js/playwright-test Serenity/JS reporter and test APIs for Playwright Test

Comments

@jan-molak
Copy link
Member

jan-molak commented Jul 7, 2023

Playwright Test offers component testing, which Serenity/JS could leverage to allow developers to write component-specific Screenplay interactions, to be reused for E2E tests.

For example, given standard component test taken from the Playwright docs:

test('event should work', async ({ mount }) => {
  let clicked = false;

  // Mount a component. Returns locator pointing to the component.
  const component = await mount(
    <Button title="Submit" onClick={() => { clicked = true }}></Button>
  );

  // As with any Playwright test, assert locator text.
  await expect(component).toContainText('Submit');

  // Perform locator click. This will trigger the event.
  await component.click();

  // Assert that respective events have been fired.
  expect(clicked).toBeTruthy();
});

We could have a Serenity/JS equivalent along the lines of:

test('event should work', async ({ mount, actor }) => {
  let clicked = false;

  const element = PageElement.from(await mount(
    <Button title="Submit" onClick={() => { clicked = true }}></Button>
  ));
  
  await actor.attemptsTo(
    Ensure.that(Text.of(element), includes('Submit')),
    Click.on(element),
    Ensure.that(clicked, equals(true)),
  )
});

Scope:

@jan-molak jan-molak added @serenity-js/playwright @serenity-js/playwright-test Serenity/JS reporter and test APIs for Playwright Test labels Jul 7, 2023
jan-molak added a commit that referenced this issue Jul 8, 2023
This is an enabler required to allow Serenity/JS to deduce a web-integration tool-agnostic selector
based on a native selector and compare the result against what was expected.

Related tickets: re #1784
@jan-molak jan-molak self-assigned this Jul 9, 2023
jan-molak added a commit that referenced this issue Jul 9, 2023
This enables introduction of alternative implementations of BrowsingSessions, such as one that
attaches to an existing Playwright page instead of creating a new browser context

Related tickets: re #1784
jan-molak added a commit that referenced this issue Jul 9, 2023
so that they can be used for component testing

Related tickets: re #1784
jan-molak added a commit that referenced this issue Jul 9, 2023
…existing page instance

Reusing an existing Playwright page instance enables better integration with Playwright Test and
support for Playwright Component Testing

Related tickets: #1784
jan-molak added a commit that referenced this issue Jul 9, 2023
… component testing

PageElement.from(nativeElement) is a new API that enables a web integration tool-agnostic way to
instantiate Serenity/JS PageElement wrapping an existing tool-specific "native" element. This new
API also enables Serenity/JS to be used for web UI component testing.

Related tickets: #1784
jan-molak added a commit that referenced this issue Jul 11, 2023
… and Playwright Test

It's now possible to use Serenity/JS reporting capabilities and Serenity/JS Screenplay Pattern APIs
to write UI Component Tests

Related tickets: #1784
jan-molak added a commit that referenced this issue Jul 11, 2023
@jan-molak jan-molak removed their assignment Sep 24, 2023
@jan-molak
Copy link
Member Author

@viper3400 published a good tutorial at https://www.pilot-period.org/sjs-playwright-ct, which is now linked from https://serenity-js.org/community/resources/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@serenity-js/playwright @serenity-js/playwright-test Serenity/JS reporter and test APIs for Playwright Test
Projects
None yet
Development

No branches or pull requests

1 participant