2015-10-13 68 views
0

我正在使用Java web start應用程序(通過JNLP運行)。目前,我想要使用此代碼來尋找應用程序主框架:使用Robot定位主框架(JFrame)(FEST Swing測試)

Process p = Runtime.getRuntime().exec("C:\\Windows\\System32\\cmd.exe /c cd C:/Users/ash/Documents/MyApp/Environment & launcher.jnlp", null, new File("C:\\Users\\ash\\Documents\\MyApp\\Environment")); 
    p.waitFor(); 
    Thread.sleep(40000); 
    robot = BasicRobot.robotWithCurrentAwtHierarchy(); 
    robot.settings().delayBetweenEvents(50); 
FrameFixture frame = WindowFinder.findFrame(getMainFrameByTitle(".*?MyApp.*?")).using(robot); 
    frame.focus(); 

但是我得到一個錯誤:

org.fest.swing.exception.WaitTimedOutError:超時等待組件使用匹配器找到[email protected] 無法使用匹配器[email protected]查找組件。

下面的方法是,我使用的名稱框匹配:

private static GenericTypeMatcher<javax.swing.JFrame> getMainFrameByName(
     final String frame) { 
    GenericTypeMatcher<javax.swing.JFrame> textMatcher = new GenericTypeMatcher<javax.swing.JFrame>(
      javax.swing.JFrame.class) { 
     protected boolean isMatching(javax.swing.JFrame frameName) { 
      return (frame.replace(" ", "")).equals(frameName.getName() 
      .replace(" ", "")); 
     } 
    }; 
    return textMatcher; 
} 

可以anyobody請告知,如果我做錯什麼或不考慮東西,我應該。我是新來的巨星和剛剛開始使用它

感謝

+0

小幅盤整FrameFixture幀= WindowFinder .findFrame(getMainFrameByName() 「* MyApp的*。?。?」),使用(機器人)。 frame.focus(); –

回答

0

好像當前AWT層次結構將看到應用程序,如果我從類在本機運行罐子只