-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
[Feature]: have toHaveAttribute(name, value) behave like toHaveText(value) when parameter is an array #34132
Comments
Addendum: at the moment I'm doing this, and it works, but I feel it's a bit clunky
|
Another thing that should work is this: await expect.soft(page.locator(".theClass").nth(0)).toHaveAttribute("someAttr", "a")
await expect.soft(page.locator(".theClass").nth(1)).toHaveAttribute("someAttr", "b")
await expect.soft(page.locator(".theClass").nth(2)).toHaveAttribute("someAttr", "c")
await expect(page.locator(".theClass")).toHaveCount(3) Note the use of soft assertions, so that you'll see the values of all elements if one of them has the wrong attribute. |
@Oscaruzzo would an array of dictionaries be as good(i.e. instead of : |
I have to say I'm not a fan. Looks quite verbose and I'm not sure about the advantages, unless you have to assert something about multiple different attributes. |
🚀 Feature Request
The assertion expect(locator).toHaveText(value) accepts arrays as parameter and will check that the locator matches n elements and check that the nth element has the nth text value.
A similar behavior for other assertions would be very useful. In particular I'm in need of said behavior for the toHaveAttribute assertion. See example below.
Example
Given this document
I'd like this code to succeed
await expect(page.locator(".theClass")).toHaveAttribute("someAttr", ["a", "b", "c"])
and this code to fail
Motivation
I can write a function that does what I described, using a combination of expect.poll() and locator.getAttribute but I think this is a general enough case that deserves support out of the box. Motivation is basically ease of use.
The text was updated successfully, but these errors were encountered: