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

Bug: getByTestIdOrAriaLabel does not work data-testid #825

Closed
1 of 3 tasks
tracy-french opened this issue Mar 14, 2024 · 5 comments · Fixed by #832
Closed
1 of 3 tasks

Bug: getByTestIdOrAriaLabel does not work data-testid #825

tracy-french opened this issue Mar 14, 2024 · 5 comments · Fixed by #832

Comments

@tracy-french
Copy link

Which package(s) does this bug affect?

  • Create Plugin
  • Sign Plugin
  • Plugin E2E

Package versions

0.18.0

What happened?

It's not possible to use getByTestIdOrAriaLabel with a data-testid. The method requires you to call it like getByTestIdOrAriaLabel('data-testid="my-id"') to use data-testid, but the method incorrectly creates the selector as [data-testid="data-testid="my-id""].

You can see the bug at

return (options?.root || this.ctx.page).locator(`[data-testid${startsWith}="${selector}"]`);
.

What you expected to happen

The method should create the selector as [data-testid="my-id"].

How to reproduce it (as minimally and precisely as possible)

Use the method with a data-testid.

Environment

System:
    OS: macOS 13.6.4
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 352.62 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.19.0 - ~/.volta/tools/image/node/18.19.0/bin/node
    Yarn: 1.22.19 - ~/.volta/tools/image/yarn/1.22.19/bin/yarn
    npm: 10.2.3 - ~/.volta/tools/image/node/18.19.0/bin/npm
  Browsers:
    Chrome: 122.0.6261.129
    Edge: 122.0.2365.80
    Firefox: 123.0
    Firefox Developer Edition: 121.0
    Safari: 17.3
  npmPackages:
    @grafana/aws-sdk: 0.3.1 => 0.3.1
    @grafana/data: 10.2.0 => 10.2.0
    @grafana/e2e: 10.2.0 => 10.2.0
    @grafana/e2e-selectors: 10.2.0 => 10.2.0
    @grafana/eslint-config: ^6.0.0 => 6.0.1
    @grafana/experimental: 1.7.3 => 1.7.3
    @grafana/plugin-e2e: ^0.18.0 => 0.18.0
    @grafana/runtime: 10.2.0 => 10.2.0
    @grafana/tsconfig: ^1.2.0-rc1 => 1.2.0-rc1
    @grafana/ui: 10.2.0 => 10.2.0

Additional context

No response

@sunker
Copy link
Contributor

sunker commented Mar 18, 2024

Thanks for creating this issue @tracy-french!

The intent of this method is to provide a safe way to use grafana/e2e-selectors. These selectors were initially using aria-label attribute, but to improve accessibility most of them have been migrated to use data-testid instead. For legacy reasons, the selector value had to be prefixed with data-testid so that the resolver would know what attribute to look for. So the purpose of the getByTestIdOrAriaLabel method is to provide a safe way to find locators based on a Grafana e2e selector. You can find more information about this in the plugin-e2e docs.

If you have defined data-testid attributes to elements in your plugin, I suggest you use page.getByTestId to access them.

The method name getByTestIdOrAriaLabel is a bit misleading since there's more to it. I'll definitely add a more explanatory comment. I'm also considering changing the method name entirely to something like getByGrafanaSelector. Thoughts on that @mckn?

@mckn
Copy link
Collaborator

mckn commented Mar 20, 2024

Thanks for creating this issue @tracy-french!

The intent of this method is to provide a safe way to use grafana/e2e-selectors. These selectors were initially using aria-label attribute, but to improve accessibility most of them have been migrated to use data-testid instead. For legacy reasons, the selector value had to be prefixed with data-testid so that the resolver would know what attribute to look for. So the purpose of the getByTestIdOrAriaLabel method is to provide a safe way to find locators based on a Grafana e2e selector. You can find more information about this in the plugin-e2e docs.

If you have defined data-testid attributes to elements in your plugin, I suggest you use page.getByTestId to access them.

The get that the method name getByTestIdOrAriaLabel is a bit misleading since there's more to it. I'll definitely add a more explanatory comment. I'm also considering changing the method name entirely to something like getByGrafanaSelector. Thoughts on that @mckn?

I think the getByGrafanaSelector is a better name for this method since it reflects a bit more what it does.

@sunker
Copy link
Contributor

sunker commented Mar 20, 2024

Great, I'll put up a PR that changes the name. We can mark getByTestIdOrAriaLabel as deprecated, but still support it until we release 1.0.0.

@jackw
Copy link
Collaborator

jackw commented Mar 20, 2024

IMHO whilst the package is on a major zero I don't think there's a need to deprecate things, rather I'd vote to rip it out now. Major zero signifies that the package is in active development and breaking changes can and will happen. This allows us to remove any cruft as it evolves into the api we want to give to consumers without the risk of something deprecated arriving in the 1.0.0 release.

@sunker
Copy link
Contributor

sunker commented Mar 20, 2024

IMHO whilst the package is on a major zero I don't think there's a need to deprecate things, rather I'd vote to rip it out now. Major zero signifies that the package is in active development and breaking changes can and will happen. This allows us to remove any cruft as it evolves into the api we want to give to consumers without the risk of something deprecated arriving in the 1.0.0 release.

Yes let's do it! I'm updating the PR.

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

Successfully merging a pull request may close this issue.

4 participants