I’ve started to get issues with Focus keyword within last month or so.. Scenario is following:
In testcase:
Focus And Input Text ${INPUT_FIRSTNAME} clientname True
Focus And Input Text ${INPUT_LASTNAME} clientsurename True
Focus And Input Text ${INPUT_EMAIL} clientname.clientsurename@mailinator.com True
Focus And Input Text ${INPUT_PHONE} 401234567 True
Obviously this is my own keyword so the implementation looks like this:
Focus And Input Text
[Arguments] ${selector} ${text} ${clear}=${False} ${unfocus}=${False}
Focus ${selector}
IF ${clear}==${True} Clear Text ${selector}
Keyboard Input action=type input=${text}
IF ${unfocus}==${True} Keyboard Key press Tab
Issue is, every now and then, setting to focus to given selector works - eg, element is found but when actual text input happens, text is entered into previously focused element - email in my case.
Anyone seen this sort of case happening ? My assumptions are:
focus doesn’t seem to work correctly
Clear Text kw will shift the focus away from element that was focused in previous row in my kw.
Something that i might not understand at this time ..
Any ideas ? And to be clear, none of the kw calls triggers an error since text was inputted into wrong input field, form does not validate and test fails as validation error prevents form submit..
Since my original kw was written over a year ago i’ve forgotten the reason but i do remember switching out from Press Keys to Keyboard Input. However, that should be irrelevant as the issue is with Focus keyword and focus not staying where it was requested to be placed.
Focus should do it and most likely it does it too. But I would suspect that something changes the focus, maybe the browser is doing something or something and it sets the focus on the original position. As a simple and dummy try, have you put small sleep and see does it after the execution. To know where to put the sleep is hard to say because I don’t see your application and don’t know how it works.
In any case, if sleep resolves the problem, then it’s a timing issue and just relying on element being present and Playwright doing its checks are not good enough. Perhaps there is a network request or something that should be waited before you input credentials.
I have not ruled out the possibility that the app itself changes the focus – and there has been such feature implemented but that would mean that there should be visible notification in page but screenshot does not have notification..
Waiting for network calls doesnt feel correct because in the cases i’ve seen this happen, all the fields are there and initial 2 fields have already been filled correctly by Focus And Input Text - and then the third one has both 3rd and 4th’s input data ..
I did add add a call to Get Elements States to verify that the selector is focused after the call to Focus ..
In order to rule out someone stealing the focus or Clear Text messing it up, i made additional kw
Ensure Focus
[Arguments] ${selector}
Focus ${selector}
Get Element States ${selector} *= focused
Lets see if this gets triggered ..
But as you are now here @aaltat - when i checked the nodejs focus ( Locator | Playwright ) .. It is async function and has possibility to set the timeout. However in browser side, there’s no option to set the timeout. This feels it could be that if default timeout is 0, focus is not checked ?