microsoft / microsoft/playwright-java

[Feature] Add custom description to assertThat and/or Locator naming

Open
#954 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3-collecting-feedback
Dominant language
Java
Stars
1.6k
Forks
298
Avg merge
3d 2h
Merged PRs (30d)
14

Description

With assertJ, we can add a custom name for given asserted object, for example:

Assertions.assertThat(mansion.guests()).as("Living Guests").isEqualTo(7);

Will result in:

[Living Guests] expected:<[7]> but was<[6]>

Selenide comes with element-aliasing as well as the .because() call (that does the similar thing, but not on asserted element, but the assertion itself):

$("div >> span").as("Living Guests").shouldHaveSize(7).because("The guest count should be valid")

The playwright-java assertions would be more readable if we'd be able to do similar thing with PlaywrightAssertions.assertThat or even the Locator/Page/ApiResponse itself, e.g.:

// on assertion:
PlaywrightAssertions.assertThat(questCount).hasText("7").because("The guest count should be valid");
// on asserted object:
PlaywrightAssertions.assertThat(questCount).as("Living Guests").hasText("7");
// on Locator
Locator guestCount = page.locator("div >> span").as("Living Guests");

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the PlaywrightAssertions API and the Locator, Page, and ApiResponse types referenced in the issue. Compare the requested assertion-level and object-level naming examples, then define a consistent supported approach whose failure messages include the custom description or name.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, playwright
Domain
testing-qa
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.