2012-08-01 2 views
0

SWTBot을 사용하여 Eclipse 마법사의 설명 텍스트를 가져 오는 방법은 무엇입니까? wizard.shell.gettext() 메서드는 제목을 제공하지만 설명을 가져 오는 방법을 찾을 수 없습니다. 마법사 페이지에 표시된 설명과 오류 메시지를 확인해야합니다.SWTBot을 사용하여 마법사 설명을 얻는 방법?

답변

0

는 대안으로, 여기 코드

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

사용 로봇 자동 설명 필드에 공간 앞에 추가 그래서 " "+message을 사용하고 method.The 마법사 메시지 가능한 SWTBot 인스턴스이다. 희망이 있습니다.

0

Eclipse 플러그인을 테스트하기 위해 SWTBot 위에 사용자 정의 DSL을 개발하여 마법사, 대화 상자 등을 나타냅니다. 여기에 우리의 경우에 잘 작동하는 코드입니다

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; 
      } 
     }); 
    } 
} 
(이 이클립스 버전에 의존 될 수 있음을 조심 는 이클립스 3.6 및 4.2 OK 보인다)
관련 문제