There are ways to get id attributes on elements working even just for test, 
but that will not work efficiently for testing purposes. 
As id's need to be unique within the html, you have manage this for 
instance with a counter. If you do not keep them unique you'll be in a 
world of html behavior fun. 
When you write your tests on a specific Id, the moment you add a widget 
somewhere in the user click path going up to the panel you want for test, 
your id will be higher then expected for the test. So it will fail and 
you'll need to fix ids. Very maintenance intensive.

Best to set an attribute on your element named 'data-xxxxxxx' (xxx as 
whatever you like) with a functional value. For instance if it's a value in 
a table, set the corresponding DB id, name or anything that identifies that 
row and is reusable.
data-xxxxx is also ignored by screen readers and the like - so no need to 
remove them from prod html. And there is no need to keep them unique in all 
your html - so you can't break behavior.

It's quite easy to do, and it'll work wonders for your setup & maintenance 
of playwright or selenium testing.

Op dinsdag 6 februari 2024 om 12:59:45 UTC+1 schreef Sebastian Bota:

> Thank you very much for your response
>
> On Tuesday 6 February 2024 at 12:03:38 UTC+2 Jens wrote:
>
>> Nothing that I am aware of. Also I think you need some naming conventions 
>> for your debug ids anyways which makes automatic generation difficult. 
>> Otherwise it will be difficult to write and later understand the UI test if 
>> debug ids are generic like input-0, input-1, input-2. You also need to 
>> verify if any of your widgets might already use an ID because of CSS 
>> styling or element selection using document.querySelector(). This would 
>> break if you override the ID.
>>
>> Every widget has onAttach/onDetach/onLoad/onUnload methods you can 
>> override. You could copy GWT's Widget class into your own source code (keep 
>> the original package) or give all your widgets a common super class and 
>> adjust the code to set a debug id. But I think you will quickly realize 
>> that generating stable but unique debug IDs on that abstract level will be 
>> difficult. Also widgets usually want debug ids on some internal meaningful 
>> elements as well, which you do not know at that abstract level.
>>
>> -- J.
>>
>>
>> Sebastian Bota schrieb am Dienstag, 6. Februar 2024 um 09:15:33 UTC+1:
>>
>>> Hello everyone. 
>>> I have a GWT application and for testing purposes ( using external UI 
>>> testing tools ) i need that each widget to have an ID set. i know it is 
>>> possible by using ensureDebugID(), but this approach will take forever to 
>>> change in my project and is very error prone.
>>>
>>> So my question, is there any way i can set an ID to each widget 
>>> automaticly ?
>>> Perhaps some kind of hook, so when a widget is added to DOM i can set 
>>> the ID.
>>> This id will be only used in test, not in production.
>>>
>>> Thank you very much for any suggestions.
>>> BR,
>>> Sebastian
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups "GWT 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit/c37a971a-ea12-4fa4-a926-103afefa3e2bn%40googlegroups.com.

Reply via email to