Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to assign unique id to swt widget and get it in swtbot?

I want to assign a unique id to swt widget, and than get back the widget in SWTBot test with this unique id. Is there a way to do it?

like image 528
Ido Avatar asked Mar 22 '23 23:03

Ido


2 Answers

In your Composite / UI part you set the data with the default SWT Bot Key or with your custom key

textOne.setData("org.eclipse.swtbot.widget.key", "textId1");
textTwo.setData("com.sample.my.custom.key", "textCustomId2");

In your SWTBot Test you can get the text as follows

// using the default SWTBot Key
botTextOne = bot.textWithId("textId1")

and

//using your custom key
botTextTwo = bot.textWithId("com.sample.my.custom.key", "textCustomId2")

References:

  • http://www.vogella.com/tutorials/SWTBot/article.html
  • http://download.eclipse.org/technology/swtbot/helios/dev-build/apidocs/org/eclipse/swtbot/swt/finder/package-summary.html
like image 171
psuzzi Avatar answered Apr 24 '23 23:04

psuzzi


Unfortunately, there is no built-in way to do this.


I think your best option is to use the method Widget#setData(Object) to set the id.

You can generate a (pseudo) random id using:

UUID id = UUID.randomUUID();
widget.setData(id);

(or use any id generation method you want).

To find your widget, you would have to search through the children of the Shell (or the Composite to which you can narrow it down) with any search algorithm you want (DFS, BFS, ...) and then compare the UUID to the id you are searching for.

for(Control control : shell.getChildren())
{
    UUID id = (UUID) control.getData();

    if(id.equals(WHATEVER_HERE))
    {
        System.out.println(control);
    }
}
like image 40
Baz Avatar answered Apr 24 '23 22:04

Baz