简体   繁体   中英

Can SWTBot recognize Action Buttons?

I have an RCP Application with a ViewPart that has a toolbar with some Actions on it. These Actions are put on the toolbar by the system as simple Buttons with an icon and a tooltip.

The Action looks like this:

public class MyAction extends Action {

    public static final String TITLE = "My Action Tooltip";

    public MyAction() {
        super(TITLE, Activator.getImageDescriptor("icons/clock_edit.png"));
        setToolTipText(TITLE);
    }

    // ...
}

Now I am trying to invoke a button click on them with SWTBot, like this:

SWTBotButton myButton = bot.buttonWithTooltip(MyAction.TITLE);
myButton.click();

And if I let the SWTBot test run, I get the error message that it couldn't find the Button:

org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException: Could not find widget matching: (of type 'Button' and with tooltip 'My Action Tooltip' and with style 'SWT.PUSH')
    at org.eclipse.swtbot.swt.finder.SWTBotFactory.waitUntilWidgetAppears(SWTBotFactory.java:362)
    at org.eclipse.swtbot.swt.finder.SWTBotFactory.widget(SWTBotFactory.java:309)
    at org.eclipse.swtbot.swt.finder.SWTBot.buttonWithTooltip(SWTBot.java:205)
    at org.eclipse.swtbot.swt.finder.SWTBot.buttonWithTooltip(SWTBot.java:193)

Now I'm wondering, is an Action not put onto the Toolbar as an SWT.PUSH Button? Or what could be the reason that it can't find it?

The Buttons on the Toolbar can be found by SWTBot a bit differently. I was finally able to do that like this:

List<SWTBotToolbarButton> items = view.getToolbarButtons();
for (SWTBotToolbarButton button : items) {
    if (MyAction.TITLE.equals(button.getToolTipText())) {
        button.click();
        break;
    }
}

Try bot.toolbarButtonWithTooltip(MyAction.TITLE).click(); Also, you can use the EclipseSpy View to determine the type of the widget that you want to work on(Window-Show View-SWTBot Category)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM