Unexpected behaviour of an automated test

Hello!
Just to make things clearer - when I say that a paramerer is accepted I mean that
the value was immediatly and automatically modified to a valid one.
I’m in a form of creating a new object.
I am testing a parameter that is supposed to accept only integers from 0 to 2000.
This parameter (input box) doesn’t accept minus sign
when typing but if you copy paste the negative value (-120),
the minus sign is accepted.
When I automate and I use the sendkeys method, the minus sign is accepted,
the same thing happened when I tried to enter character by character, using
a method I created.
The same thing happened when I used JavaScript:

Blockquote
public void inputByJs(WebElement el) {
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“arguments[0].value = ‘-120’;” +
“var event = new Event(‘input’, { bubbles: true });” +
“arguments[0].dispatchEvent(event);”, el);

}

Blockquote
By these three methods, the input box accepted a minus sign (It is not erased).
Any Ideas why does it work like that? I am really trying to reach a result
that reflects a manual action.
Thanks!

3 Likes

Im not familiar with the deep internal workings of pasting vs sendkeys vs human keyboard input.

But have you considered that there may be a defect in the application? it sounds like the UI layer is supposed to do input validation in order to avoid the round trip of an error being returned from the api. It sounds like the UI isnt properly validating input in all cases.

I would expect that the UI would behave the same way whether the input is pasted, typed or by sendkeys.

Also (and this is off-topic I dont want to be that stack exchange guy…so feel free to ignore this) - again Im only going by what you present, I dont know the use case - I would think that automatically correcting an invalid input is a very rare design pattern, because it is making assumptions for the user. A better design pattern would be to indicate invalid input and allow the user to correct it. outline the input in red with an error displayed “Input value between 0 and 2000: negative numbers are not valid” Which I might file as a design defect and make a case for changing

(please someone feel free to tell me Im full of beans, it wont hurt my feelings)

2 Likes

@liormof Please see , if this can help:

  1. Validation Trigger**: The validation logic might be triggered by keyboard events (such as keydown or keyup) rather than input events (such as input or change). When typing directly into the input field, the validation logic successfully intercepts the keystrokes before the minus sign is entered. However, when pasting, the validation logic might not be triggered in the same way, allowing the minus sign to be pasted into the field.
  2. Different Input Method**: The browser or application may treat pasted text differently from typed text. It’s possible that the validation logic is bypassed or not applied consistently when text is pasted into the input field, leading to the acceptance of invalid characters like the minus sign.

you may need to review the validation logic and ensure that it consistently applies to all input methods, including typing and pasting. Additionally, implementing client-side validation using JavaScript to enforce the restriction on negative values can provide a more robust solution.

1 Like

It seems like the input validation mechanism is not consistently enforced, while entering the value programmatically. This could be due to how to application handles input events triggered by automation methods- sendKeys/JS.
To ensure accurately, you may need to investigate the input validation logic and adjust your automation approach accordingly. This may involve simulating manual input more accurately/enhancing validation checks in your scripts.

1 Like

I suspect you want to speak to your dev team. Boundary validation code in a client-side is normally ‘generated’ code, if someone is writing that code by hand then you have security problems because someone will be able to hijack and submit incorrect data. If your app wants to reduce round trips, the code will be generated, but it’s messy to validate twice, Best practise to do it once, on the back-end, the front-end validation is sugar only, and will suffer from all sorts of fun problems.

That said, if it’s a valid business case/constraint or rule to ‘fix’ incorrect input fields, then it’s not a bug at all. It depends entirely on the product owner, not the QA to decide. But as @ansha_batra hinted, try hard not to use JS to inject values into fields, they won’t work the same way as when a human does it.

1 Like

Hello Everyone! Thanks for your help to shed light on this issue :slight_smile:

1 Like

so often, all you need to do is have someone to talk through it with. Lately I’m beginning to wonder if that is a role for something like chat-gpt at some point.