Question

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?

Était-ce utile?

La solution 2

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);
    }
}

Autres conseils

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:

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top