-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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] add option to normalize whitespace to expect().toHaveValue() #23037
Comments
After some debugging it looks like .inputValue() returns a different whitespace charCode. If a whitespace is obtained using .inputValue() it's charCode will be 160 (or a Non-Breaking Space) while a charCode in a regular string within a program is usually charCode 32. This causes inconsistencies if ever an input from the web is fetched with .inputValue() to be used in further comparison operations, be it JavaScripts default equal operators or any sort of assertions. Proposed solution to the bug: |
@kLjubomir I tried to reproduce this, but was not able to, unfortunately. Could you please share the repro that we can run locally, including the page you are testing? I tried various |
So the locale on the page yields: I don't think that the nested HTML will tell you much, but I can say that the page is coded in Angular, will still attach the element as an example below. I have tried using .inputValue() on google's textarea element and confirmed that the whitespace returned is a regular whitespace, so I'm really not sure why on the page I'm working on it was returned as a nbsp, maybe it really could be due to the way that the page is coded, so I am not sure what to do with this information, I used normalization in these cases where it was required, but is it possible for me to locally overwrite playwrights inputValue function, so I could code in my regex to regulate the whitespace charCode? for keeping the business secret reasons I can not provide more information like page's domain and credentials etc.
|
@kLjubomir I agree this is most likely page-specific.
That's not possible. I'd recommend creating a helper function that you call instead of export function getInputValue(locator) {
const value = await locator.inputValue();
return value.replace(...);
} That said, we can probably add an option to |
Playwright Version: [v1.35.1] In case one of them has an extra whitespace, when two distinct texts are asserted by the method "toHaveText", it does not throw an error and the test passes. The text of the web element ="Book Store Application" |
System info
Source code
Steps:
Hello, the code itself will probably not have explained much, so here's how to reproduce:
Have a value > 1000.
Have an input field that instead of a "." or a "," puts a whitespace to separate "numeric" values (which are actually string), so for example "11250" would become "11 250,00" or 1000235 would become 1 000 235,00
Grab the .inputValue() of the field after typing or filling an unformatted raw numeric value into the field.
Assert the field with expect(await element.inputValue()).toBe("11 250,00")
Expected
Since "11 250,00" which was fetched from inputValue() is the same as "11 250,00" which was set there as a string in assertions, using any of the matching assertions should correctly deduce the two fields as equal.
Actual
If the inptValue() contains a whitespace, using assertions like .toBe() or .toContain(), comparing string with identical string causes an assertion error. This issue is not reproduced if the inputValue() of the string does not contain a whitespace, so if the number is parsed to "11.250,00" any assertion asserting this inputValue() to be or contain "11.250,00" will pass.
Error: expect(received).toBe(expected) // Object.is equality
Expected: "11 250,00"
Received: "11 250,00"
141 | for (const priceField of priceFields) {
142 | if(workerInfo.project.name==='at') {
The text was updated successfully, but these errors were encountered: