简体   繁体   English

SWTBot可以识别动作按钮吗?

[英]Can SWTBot recognize Action Buttons?

I have an RCP Application with a ViewPart that has a toolbar with some Actions on it. 我有一个带有ViewPart的RCP应用程序,它有一个带有一些Actions的工具栏。 These Actions are put on the toolbar by the system as simple Buttons with an icon and a tooltip. 这些操作由系统放在工具栏上,作为带有图标和工具提示的简单按钮。

The Action looks like this: Action看起来像这样:

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: 现在我试图用SWTBot调用按钮点击它们,如下所示:

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: 如果我让SWTBot测试运行,我收到错误消息,它找不到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? 现在我想知道,一个动作是不是作为SWT.PUSH按钮放在工具栏上? 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. SWTBot可以找到工具栏上的按钮略有不同。 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(); 尝试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) 此外,您可以使用EclipseSpy View来确定要处理的窗口小部件的类型(Window-Show View-SWTBot Category)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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