2010-07-21 28 views
1

嘗試使用從http://easytesting.org/swing/wiki/pmwiki.php?n=FEST-Swing.LaunchFromMainFEST搖擺例如不工作,frame.isShowing()返回false

不幸的是,frame.isShowing(中FEST-Swing的爲Swing GUI測試,並且使用的例子)總是返回false雖然我已經看到了JavaApp搖擺運行

見我的代碼

... 
    ApplicationLauncher.application(JavaApp.class).start(); 
    GenericTypeMatcher<Frame> matcher = new GenericTypeMatcher<Frame>(Frame.class) { 
     protected boolean isMatching(Frame frame) { 
     System.out.println("title:" + frame.getTitle() + " showing:" +frame.isShowing()); // .getTitle()); 
      return "Java Application".equals(frame.getTitle()) && frame.isShowing(); 
     } 
    }; 
    Robot robot = BasicRobot.robotWithNewAwtHierarchy(); 
    FrameFixture frame2 = WindowFinder.findFrame(matcher).withTimeout(5000).using(robot); 
... 

從控制檯日誌

title: showing: false 

兩個問題:
1.我必須使用JFrame的Frame insteaf,否則它不能匹配,導致標題不正確,我期望「Java應用程序」
2. frame.isShowing( )總是返回false,這似乎很奇怪

BTW:最新的代碼似乎需要參數GenericTypeMatcher() RGS /拉里

回答

3

的問題是,您所呼叫robotWithNewAwtHierarchy後您啓動應用程序。所發生的是在調用robotWithNewAwtHierarchy之前實例化的任何框架或對話框將不會被創建的Robot看到。

您可以前行移動robotWithNewAwtHierarchy你開始你的應用程序,也可以使用robotWithCurrentAwtHierarchy,而不是(這將看不到任何實例化的框架或對話框,無論何時調用此方法。)