AutoIT脚本不会对我的Java代码执行任何操作

时间:2011-07-21 17:19:13

标签: java path autoit

我使用Selenium的TestNG框架进行Web UI测试。我有一个文件下载对话框,我想点击它,为此我使用AutoIT。

这是我的脚本,用于处理名为“Opening”的Firefox fiel对话框

 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文件的路径已添加到系统路径中。但问题是代码似乎对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());
        }

1 个答案:

答案 0 :(得分:1)

永远不会定义$ timeout。你的脚本应该崩溃。