2011-07-21 48 views
0

我使用TestNG框架和Selenium進行Web UI測試。我有一個文件下載對話框,我想單擊並使用AutoIT。AutoIT腳本不會從我的Java代碼中執行任何操作

這裏是我的腳本來處理Firefox的題爲「開放」

Opt("WinTitleMatchMode", -2)  
If $CmdLine[0] < 2 Then  
ConsoleWrite("Usage: " & @ScriptName & " <Opening> <timeout in seconds>" & @CRLF) 
Exit(1) 
EndIf 
; File save dialog is titled "Opening <file>" in Firefox and "File Download" in IE. 

$title = WinGetTitle($CmdLine[1]) ; retrives whole window title $timeout = $CmdLine[2] 
; wait until dialog box appears 
If WinWait($title, "", $timeout) Then ; match the window with substring 
;ConsoleWrite("Found File save dialog" & @CRLF) 
WinActivate($title)  
Send("!S") 
ControlClick("Opening", "", "[TEXT:&OK]") 
Exit 
Else  
    ConsoleWrite("File save dialog did not appear after " & $timeout & " seconds" & @CRLF)  
Exit(2) 
EndIf 

這是我的Java代碼和路徑AutoIt的exe文件已經被添加到系統路徑FIEL對話框。但問題是,代碼似乎沒有做任何與該exe文件,它執行該行並進入下一個,但文件對話框仍然像無法識別。

final String type = getWebDriver().getClass().getName(); 
     if (type.toLowerCase().contains("firefox")) { 
      exe = "SelectFileDialogOptions.exe"; 
      commandLine = exe + " Opening " + 15; 
     } else { 
       //handle IE 
     } 
     logger.info("Executing the command '" + commandLine + "'..."); 
     try { 
      final String[] commands = commandLine.split(" "); 
      Runtime.getRuntime().exec(commands); 
     } catch (final IOException e) { 
      throw new WebTestControllerException(
        "Caught exception while trying to execute command '" 
          + commandLine 
          + "'. Exception is: " 
          + e.getMessage()); 
     } 
+0

嘗試將您的'ConsoleWrite()'改爲'MsgBox()'來試圖看看它有多遠。 –

+0

試過這個,但執行exe時的結果相同。當我手動嘗試它時,即打開文件對話框,然後從命令行運行AutoIT腳本,然後我可以看到ConsoleWrite/Msgbox顯示出來,但它仍然沒有點擊對話框,可能是因爲它無法「 t獲得焦點.. – Jai

回答

1

$ timeout從不定義。你的腳本應該會崩潰。

+0

它是通過Java代碼 – Jai

+0

@Jai傳入的「15」,但在AutoIt腳本中,您從不將$ CmdLine [2]分配給$ timeout,該部分在此處註釋掉:'$ title = WinGetTitle ($ CmdLine [1]);回顧整個窗口標題$超時= $ CmdLine [2]',$超時之前應該有一個換行符。 – Matt

+0

哦,對不起,它是這裏格式化的,但是在我的腳本中,它被賦值了。 – Jai