Main Page | File List | File Members

Win32Dom.js

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Win32Dom class provices direct access to Windows desktop window.
00004  */
00005  
00006 /**
00007  * Contruct a Win32Dom object. 
00008  */
00009 function Win32Dom(){
00010     this._desktop = null;
00011 
00012     function buildXPath(cls, cap) {
00013         if ( cap == undefined ) cap = null;
00014         if ( cls == undefined ) cls = null;
00015         var xpath = ".//Win";
00016         if ( (cls != null) && ( cap != null ) ) {
00017             xpath += "[@Cls='" + cls + "' and contains(@Cap, '" + cap + "')]";        
00018         } else if ( cls != null ) {
00019             xpath += "[@Cls='" + cls + "']";                
00020         } else if ( cap != null ) {
00021             xpath += "[contains(@Cap, '" + cap + "')]";        
00022         }
00023         return xpath;
00024     };
00025 
00026     /**
00027      * Search for a window with given caption and timeout value in milliseconds.
00028      * If timeoutMS is omitted this method will wait for 1500 milliseconds.
00029      */
00030     this.waitForWindow = function(caption, timeoutMS) {
00031         if ( this._desktop == null ) {
00032             this._desktop = new ActiveXObject("Win32Dom.Desktoop");
00033         }
00034         
00035         if( timeoutMS == undefined ) {
00036             timeoutMS = 1500;
00037         }
00038         
00039         for(var i=0; i<timeoutMS; i+=100) {
00040             var win = this._desktop.findTopWindow(caption);   
00041             if ( win != null ) {
00042                 return win;
00043             }
00044             WScript.Sleep(100);
00045         }
00046         return null;
00047     };
00048     
00049     /**
00050      * Find a top level window with given caption
00051      */
00052     this.findTopWindow = function(caption) {
00053         return this._desktop.findTopWindow(caption);
00054     };
00055      
00056     /**
00057      * Find all top level windows 
00058      */
00059     this.findAllTopWindows = function() {
00060         return this._desktop.findAllTopWindows();
00061     };
00062     
00063     /**
00064      * Fild all child windows of a window with given class and caption 
00065      */
00066     this.findWindowList = function(win, cls, cap) {
00067         return win.findWindowList( buildXPath(cls, cap) );
00068     };
00069 
00070     /**
00071      * Fild a child window with given class and caption 
00072      */
00073     this.findWindow = function(win, cls, cap) {
00074         return win.findWindow( buildXPath(cls, cap) );
00075     };
00076 
00077     /**
00078      * Find a button child window with given label and index.
00079      */
00080     this.findWinButton = function(win, label, index) {
00081         var node;    
00082         if ( (index == undefined) || (index==0) ) {
00083             node = this.findWindow(win, "Button", label);
00084         } else {
00085             var nodes = this.findWindowList(win, "Button", label);
00086             if ( nodes.Count > index ) {
00087                 node = nodes(index);
00088             }
00089         }     
00090         return (node == null) ? null : node.ToButton();
00091     };
00092 
00093     /**
00094      * Find a text edit field window with given index
00095      */ 
00096     this.findTextBox = function(win, index) {
00097         var nodes = this.findWindowList(win, "Edit");
00098         if ( nodes.Count > index ) {
00099             return nodes(index).ToTextBox();
00100         } else {
00101             return null;
00102         }
00103     };
00104     
00105     /**
00106      * Pass the basic login window with given user name and password.
00107      */
00108     this.openWindowAsUser = function(url, userName, userPwd) {
00109         var loginWinCap = url.substring(url.indexOf("//")+2);
00110         loginWinCap = loginWinCap.substring(0, loginWinCap.indexOf("/"));
00111 
00112         var portIndex = loginWinCap.indexOf(":");
00113         if (portIndex != -1) {
00114           loginWinCap = loginWinCap.substring(0, portIndex);
00115         }
00116 
00117         loginWinCap = "Connect to " + loginWinCap;
00118 
00119         this.openWindowAsync(url);
00120         var loginWin = this.waitForWindow(loginWinCap, this.findTimeout);        
00121 
00122         this.findTextBox(loginWin, 1).text = userName;
00123         this.findTextBox(loginWin, 2).text = userPwd;
00124         this.findWinButton(loginWin, "OK").Click();
00125 
00126         this.checkSubmit();    
00127     };
00128     
00129     
00130     /**
00131      * Open a URL and acknowledge possible popup window with given title by 
00132      * click the button with given label.
00133      */
00134     this.acceptPopupWindow = function(url, title, btnLable) {
00135         this.openWindowAsync(url);
00136         var alertWin = this.waitForWindow(title); 
00137         if ( alertWin != null ) {
00138             this.findWinButton(alertWin, btnLable).Click();
00139         }
00140         this.checkSubmit();
00141     };
00142     
00143     /**
00144      * Open a URL and skil possible security alert window
00145      */
00146     this.skipAlert = function(url) {
00147         this.acceptPopupWindow(url, "Security Alert", "Yes");
00148     };    
00149 
00150 
00151     /**
00152      * Attach to a IE modal dialog window. This function is usually called
00153      * in sbk script launched before opening a modal dialog.
00154      */
00155     this.waitForModalDialog = function(winTitle) { 
00156             var popupWin = this.waitForWindow(winTitle); 
00157         if ( popupWin == null ) {
00158             this.log("Can't find modal dialog window with title: " + winTitle);
00159             return;
00160         }
00161 
00162             var ie = this.findWindow(popupWin, "Internet Explorer_Server"); 
00163 
00164             this.findScope = this.doc = ie.toDhtml(); 
00165             this.comWin = this.win = this.doc.window; 
00166     }; 
00167 };
00168 
00169 

Generated on Thu Sep 29 09:05:40 2005 for IeUnit by  doxygen 1.3.9.1