Beispiel #1
0
        long Form1_Load(string sProjectName, string sWebAccessIP, string sTestLogFolder, string sBrowser)
        {
            //string sCurrentFilePath = Directory.GetCurrentDirectory();
            string sCurrentFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);

            //ModSca1_AutoTest
            string sourceFile = sCurrentFilePath + "\\ModScan\\ModSca1_AutoTest";
            string destFile   = sCurrentFilePath + "\\ModSca1_AutoTest";

            EventLog.AddLog("copy " + sourceFile + " to " + destFile);
            System.IO.File.Copy(sourceFile, destFile, true);

            Process pModScan = new Process();

            // FileName 是要執行的檔案
            EventLog.AddLog("Open ModScan32.exe and load ModSca1_AutoTest setting file");
            pModScan.StartInfo.FileName = sCurrentFilePath + "\\ModScan\\ModScan32.exe";
            pModScan.Start();
            Thread.Sleep(5000);
            SendKeys.SendWait("%f");
            Thread.Sleep(500);
            SendKeys.SendWait("o");    // save
            Thread.Sleep(1000);
            SendKeys.SendWait("ModSca1_AutoTest");
            Thread.Sleep(500);
            SendKeys.SendWait("{ENTER}");
            Thread.Sleep(500);
            SendKeys.SendWait("%c");
            Thread.Sleep(500);
            SendKeys.SendWait("c");
            Thread.Sleep(2000);

            // Control ModeScan
            EventLog.AddLog("Set IP to modscan connectiong details");
            int iModScan           = tpc.F_FindWindow("#32770", "Connection Details");
            int iConnectionDetails = tpc.F_FindWindowEx(iModScan, 0, "Edit", "");

            if (iConnectionDetails > 0)
            {
                tpc.F_SendMessage(iConnectionDetails, tpc.V_WM_SETTEXT, 0, sWebAccessIP);    // set IP
                Thread.Sleep(2000);
                tpc.F_PostMessage(iConnectionDetails, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0); // Enter
                Thread.Sleep(3000);
            }
            else
            {
                EventLog.AddLog("Cannot get iModScan handle");
            }
            EventLog.PrintScreen("ModScan_ScreenShot");

            pModScan.WaitForExit(1000);
            pModScan.CloseMainWindow();

            bool bSeleniumResult      = true;
            int  iTotalSeleniumAction = dataGridView1.Rows.Count;

            for (int i = 0; i < iTotalSeleniumAction - 1; i++)
            {
                DataGridViewRow row             = dataGridView1.Rows[i];
                string          sSeleniumResult = row.Cells[2].Value.ToString();
                if (sSeleniumResult != "pass")
                {
                    bSeleniumResult = false;
                    EventLog.AddLog("Test Fail !!");
                    EventLog.AddLog("Fail TestItem = " + row.Cells[0].Value.ToString());
                    EventLog.AddLog("BrowserAction = " + row.Cells[1].Value.ToString());
                    EventLog.AddLog("Result = " + row.Cells[2].Value.ToString());
                    EventLog.AddLog("ErrorCode = " + row.Cells[3].Value.ToString());
                    EventLog.AddLog("ExeTime(ms) = " + row.Cells[4].Value.ToString());
                    break;
                }
            }

            if (bSeleniumResult)
            {
                Result.Text      = "PASS!!";
                Result.ForeColor = Color.Green;
                EventLog.AddLog("Test Result: PASS!!");
                return(0);
            }
            else
            {
                Result.Text      = "FAIL!!";
                Result.ForeColor = Color.Red;
                EventLog.AddLog("Test Result: FAIL!!");
                return(-1);
            }

            //return 0;
        }
Beispiel #2
0
        long Form1_Load(string sPrimaryProject, string sPrimaryIP, string sSecondaryProject, string sSecondaryIP, string sTestLogFolder, string sBrowser, string sUserEmail, string sLanguage)
        {
            string sExePath = Directory.GetCurrentDirectory();  // 如果是用iATester執行初始exe 也是指到iATester執行檔位置
                                                                // 如果是用初始exe檔直接執行 則是指到初始exe檔執行位置
            string sCurrentFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
            //sCurrentFilePath無論用什麼執行 就是指到初始exe檔執行位置

            //ModSca1_AutoTest
            string sourceFile = sCurrentFilePath + "\\ModScan\\ModSca1_AutoTest";
            string destFile   = sExePath + "\\ModSca1_AutoTest";

            EventLog.AddLog("copy " + sourceFile + " to " + destFile);
            System.IO.File.Copy(sourceFile, destFile, true);

            Process pModScan = new Process();

            // FileName 是要執行的檔案
            EventLog.AddLog("Open ModScan32.exe and load ModSca1_AutoTest setting file");
            pModScan.StartInfo.FileName = sCurrentFilePath + "\\ModScan\\ModScan32.exe";
            pModScan.Start();
            Thread.Sleep(5000);
            SendKeys.SendWait("%f");
            Thread.Sleep(500);
            SendKeys.SendWait("o");    // save
            Thread.Sleep(1000);

            // load ModSca1_AutoTest file
            EventLog.AddLog("Find ModSca1_AutoTest file to load");
            int iModScanOpen = tpc.F_FindWindow("#32770", "Open");
            int iComboxEx32  = tpc.F_FindWindowEx(iModScanOpen, 0, "ComboBoxEx32", "");
            int iCombox      = tpc.F_FindWindowEx(iComboxEx32, 0, "ComboBox", "");
            int iEdit        = tpc.F_FindWindowEx(iCombox, 0, "Edit", "");

            if (iEdit > 0)
            {
                tpc.F_SendMessage(iEdit, tpc.V_WM_SETTEXT, 0, "ModSca1_AutoTest");
                Thread.Sleep(2000);
            }
            else
            {
                EventLog.AddLog("Cannot get iModScanOpenEdit handle");
                bPartResult = false;
            }

            Thread.Sleep(500);
            SendKeys.SendWait("{ENTER}");
            Thread.Sleep(500);
            SendKeys.SendWait("%c");
            Thread.Sleep(500);
            SendKeys.SendWait("c");
            Thread.Sleep(2000);

            // Control ModeScan
            EventLog.AddLog("Set IP to modscan connectiong details");
            int iModScan           = tpc.F_FindWindow("#32770", "Connection Details");
            int iConnectionDetails = tpc.F_FindWindowEx(iModScan, 0, "Edit", "");

            if (iConnectionDetails > 0)
            {
                tpc.F_SendMessage(iConnectionDetails, tpc.V_WM_SETTEXT, 0, sPrimaryIP);      // set IP
                Thread.Sleep(2000);
                tpc.F_PostMessage(iConnectionDetails, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0); // Enter
                Thread.Sleep(3000);
            }
            else
            {
                EventLog.AddLog("Cannot get iModScan handle");
                bPartResult = false;
            }
            EventLog.PrintScreen("ModScan_ScreenShot");

            pModScan.WaitForExit(1000);
            pModScan.CloseMainWindow();

            #region Result judgement
            if (bFinalResult && bPartResult)
            {
                Result.Text      = "PASS!!";
                Result.ForeColor = Color.Green;
                EventLog.AddLog("Test Result: PASS!!");
                return(0);
            }
            else
            {
                Result.Text      = "FAIL!!";
                Result.ForeColor = Color.Red;
                EventLog.AddLog("Test Result: FAIL!!");
                return(-1);
            }
            #endregion
        }