microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.72k stars 3.58k forks source link

[Feature]: Locator Alias #32246

Closed LinkPovilas closed 3 weeks ago

LinkPovilas commented 4 weeks ago

🚀 Feature Request

Allow the assignment of aliases to locators to improve the readability of test reports.

Example

As locator method:

page.getByRole('button', { name: 'Save' }).alias('Save button');

// Alternatively
page.getByRole('button', { name: 'Save' }).describe('Save button');
page.getByRole('button', { name: 'Save' }).describedAs('Save button');

Usage:

const saveButton = page.getByRole('button', { name: 'Save' }).alias('Save button');
await saveButton.click();

Motivation

It would enhance the readability of test reports for stakeholders, including business analysts, project managers, product owners or clients.

Currently without aliases: current

With aliases: enhanced

Skn0tt commented 3 weeks ago

Hi! Take a look at test.step. Let me know wether that helps your usecase!

LinkPovilas commented 3 weeks ago

Hi @Skn0tt, thank you for your reply! While the test.step API is great for its use case, this feature request is more about being able to provide meaningful names for locators themselves without needing additional wrapper functions, especially in short tests that may consist of a single step.

Additionally, some users might find it useful for hiding certain details. For example, in my provided screenshot, the test report exposes the API key name. Another user could accidentally expose an administrator's username or email by selecting a dropdown menu that displays it using the page.getByRole() strategy.

Skn0tt commented 3 weeks ago

Thanks for elaborating. Generally speaking, neither steps nor (potential) aliases will be a good way of hiding sensitive credentials. Even if the report doesn't visibly show the sensitive information, it will most likely still contain it in some internal representation. The only right solution here is to use less sensitive credentials.

For other usecases, we believe that test.step is sufficient.