Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用SWTBot获取向导描述?_Java_Eclipse_Junit_Eclipse Plugin_Swtbot - Fatal编程技术网

Java 如何使用SWTBot获取向导描述?

Java 如何使用SWTBot获取向导描述?,java,eclipse,junit,eclipse-plugin,swtbot,Java,Eclipse,Junit,Eclipse Plugin,Swtbot,如何使用SWTBot获取eclipse向导的描述文本?wizard.shell.gettext()方法给出了标题,但我找不到任何获取描述的方法。我需要它来验证描述和向导页面上显示的错误消息。作为一种解决方法,我使用了此代码 public void verifyWizardMessage(String message) throws AssertionError{ try{ bot.text(" "+message); }catch(WidgetNotFoundExc

如何使用SWTBot获取eclipse向导的描述文本?
wizard.shell.gettext()方法给出了标题,但我找不到任何获取描述的方法。我需要它来验证描述和向导页面上显示的错误消息。

作为一种解决方法,我使用了此代码

public void verifyWizardMessage(String message) throws AssertionError{
    try{
       bot.text(" "+message);
    }catch(WidgetNotFoundException e){
        throw (new AssertionError("no matching message found"));
    }
}

这里bot是方法可用的SWTBot实例。向导消息会自动在description字段前面加一个空格,所以我使用
“”+message
。希望它能有所帮助

为了测试我们的eclipse插件,与我一起工作的团队在SWTBot之上开发了一个定制DSL来表示向导、对话框等。下面是一个代码片段,它在我们的例子中运行良好(注意,这可能与eclipse版本有关,在eclipse 3.6和4.2中似乎没有问题)

class-Foo{
/**
*对话框/向导的外壳
*/
私人SWTBotShell;
受保护的SWTBotShell getShell(){
返回壳;
}
受保护的T GetToLevel复合child(最终类clazz,最终整型索引){
返回UIThreadRunnable.syncExec(shell.display,new Result()){
@抑制警告(“未选中”)
公营机构{
Shell widget=getShell().widget;
如果(!widget.isDisposed()){
for(控件:widget.getChildren()){
if(复合对象的控制实例){
复合=(复合)控制;
int计数器=0;
for(控件子项:composite.getChildren()){
if(类实例(子类)){
如果(计数器==索引){
返回(T)儿童;
}
++计数器;
}
}
}
}
}
返回null;
}
});
}
/**
*返回向导标题对话框中显示的向导说明或消息
*区域。
*
*向导的描述或消息存储在第一个文本小部件中
*(请参阅中的TitlearReadialog.messageLabel初始化。)
*org.eclipse.jface.dialogs.titlearealog.createTitleArea(复合)
* ).
*
*/
公共字符串getDescription(){
final Text Text=getTopLevelCompositeChild(Text.class,0);
返回UIThreadRunnable.syncExec(getShell().display,new Result()){
公共字符串run(){
if(text!=null&&!text.isDisposed()){
返回text.getText();
}
返回null;
}
});
}
}

对于向导NewProjectCreationPage,我使用:

bot.textWithLabel("Create Project"); // This title set by page.setTitle("Create Project");
bot.text("Description."); // this is description set by page.setDescription("Description.");
bot.textWithLabel("Create Project"); // This title set by page.setTitle("Create Project");
bot.text("Description."); // this is description set by page.setDescription("Description.");