#副標=告別苦悶的網頁測試生涯 #大標=IEUnit進階應用探討 #眉標=IEUnit #作者=文/李明儒 =====box程式1========== function WebLoginTest() { assimilate(this, new IeUnit()); this.testLogin = function() { var url = "http://ieunit.sourceforge.net/samples/LoginDemo/Helloworld.html"; this.openWindowAsUser(url, "ieunit", "DemoPwd"); this.assertPageHasText("Hello World!"); this.closeWindow(); }; } ===========end============= ==========程式2 ======== IEUnit\lib\Win32Dom.js第117列 //loginWinCap = "Connect to " + loginWinCap; loginWinCap = "連線到 " + loginWinCap; this.openWindowAsync(url); …省略… this.findTextBox(loginWin, 2).text = userPwd; //this.findWinButton(loginWin, "OK").Click(); this.findWinButton(loginWin, "確定").Click(); ====================end================ =========box程式3 ============ IEUnit\Samples\Win32DomTest\ModalDialogTest.jst function ModalDialogTest() { assimilate(this, new IeUnit()); this.testModalDialog = function() { //html檔改放IIS時,URL要修改 this.openWindow("http://localhost/ModalDialog.html"); // 開啟Modal Dialog前, 先啟動攔截程式 var cmdShell = new ActiveXObject("WScript.Shell"); cmdShell.Run("ModalEnterName.sbk", 0, false); this.clickButton("Open Modal Dialog"); this.assertPageHasText("Hi, Jeffrey"); this.closeWindow(); }; } =================end============== =============box程式4========== IEUnit\Samples\Win32DomTest\ModalEnterName.sbk this.waitForModalDialog("Modal Popup Window -- 網頁對話"); this.setField("yourName", "Jeffrey"); this.clickButton("submit"); ================end============= =========box程式5========== Upload.html,放在Web上 Select File: =============end============= =========box程式6========== UploadTest.jst function UploadTest() { assimilate(this, new IeUnit()); this.testUpload = function() { this.openWindow("http://localhost/Upload.html"); this.clickObjById("uploadFile"); var fname = "C:\\Temp\\Test.txt"; var cmdShell = new ActiveXObject("WScript.Shell"); cmdShell.Run("EnterFileName.sbk " + fname, 0, false); this.assertEquals(this.findObjById("uploadFile").value, fname); this.closeWindow(); }; } =============end=========== ==============box程式7=========== EnterFileName.sbk var fpath = " " + WScript.Arguments(1); var popupWin = _.waitForWindow("選擇檔案", 30000); _.findWindow(popupWin, "Edit").sendText(fpath); _.findWinButton(popupWin, "開啟(&O)").click(); ================end==============