[英]How to get wizard description using SWTBot?
如何使用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實例。向導消息會自動在描述字段前面添加一個空格,所以我使用" "+message
。 希望能幫助到你
為了測試我們的eclipse插件,我工作的團隊在SWTBot上開發了一個自定義DSL來表示向導,對話框等等。 這是一個在我們的案例中運行良好的代碼片段( 請注意,這可能是eclipse版本依賴 ,對於eclipse 3.6和4.2似乎沒問題)
class Foo {
/**
* The shell of your dialog/wizard
*/
private SWTBotShell shell;
protected SWTBotShell getShell() {
return shell;
}
protected <T extends Widget> T getTopLevelCompositeChild(final Class<T> clazz, final int index) {
return UIThreadRunnable.syncExec(shell.display, new Result<T>() {
@SuppressWarnings("unchecked")
public T run() {
Shell widget = getShell().widget;
if (!widget.isDisposed()) {
for (Control control : widget.getChildren()) {
if (control instanceof Composite) {
Composite composite = (Composite) control;
int counter = 0;
for (Control child : composite.getChildren()) {
if (clazz.isInstance(child)) {
if (counter == index) {
return (T) child;
}
++counter;
}
}
}
}
}
return null;
}
});
}
/**
* Returns the wizard's description or message displayed in its title dialog
* area.
*
* A wizard's description or message is stored in the very first Text widget
* (cf. <tt>TitleAreaDialog.messageLabel</tt> initialization in
* <tt>org.eclipse.jface.dialogs.TitleAreaDialog.createTitleArea(Composite)</tt>
* ).
*
*/
public String getDescription() {
final Text text = getTopLevelCompositeChild(Text.class, 0);
return UIThreadRunnable.syncExec(getShell().display, new Result<String>() {
public String run() {
if (text != null && !text.isDisposed()) {
return text.getText();
}
return null;
}
});
}
}
在WizardNewProjectCreationPage的情況下,我使用:
bot.textWithLabel("Create Project"); // This title set by page.setTitle("Create Project");
bot.text("Description."); // this is description set by page.setDescription("Description.");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.