Is there a way to automatically generate IDs on SWT-Widgets so UI-Tests can reference them? I know i can manually set an id using seData but I want to implement this feature for an existing application in a somewhat generic fashion.
Is there a way to automatically generate IDs on SWT-Widgets so UI-Tests can reference
Share
You can recursively assign IDs for all your shells in your application using
Display.getCurrent().getShells();andWidget.setData();.Setting the IDs
You have access to all the active (not disposed) Shells in your application with the method
Display.getCurrent().getShells();. You can loop through all children of eachShelland assign an ID to eachControlwith the methodWidget.setData();.If the
Controlis aCompositeit may have controls inside the composite, that’s the reason I have used a recursive solution in my example.Finding Controls by ID
Now, if you like to find a Control in one of your shells I would suggest a similar, recursive, approach:
With the method
findControlById()you can easily find aControlby it’s ID.Links