Exemplo n.º 1
0
        private void ViewAlarmData(string sTestLogFolder, string slanguage)
        {
            // Start view
            EventLog.AddLog("Start view");
            driver.SwitchTo().Frame("rightFrame");
            driver.FindElement(By.XPath("//a[contains(@href, '/broadWeb/system/bwview.asp')]")).Click();
            //PrintStep("Start View");

            // Control browser
            EventLog.AddLog("Control browser");
            int iIE_Handl, iIE_Handl_2, iIE_Handl_3, iIE_Handl_4, iIE_Handl_5, iIE_Handl_6, iIE_Handl_7, iWA_MainPage = 0;

            switch (slanguage)
            {
            case "ENG":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHT":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "節點 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "節點 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHS":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "节点 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "节点 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "JPN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "ノード : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "ノード : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "KRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "노드 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "노드 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "FRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Noeud : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Noeud : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            default:
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;
            }

            /*
             * int iIE_Handl = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
             * int iIE_Handl_2 = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
             * int iIE_Handl_3 = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
             * int iIE_Handl_4 = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
             * int iIE_Handl_5 = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
             * int iIE_Handl_6 = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
             * int iIE_Handl_7 = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
             * int iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
             */

            if (iWA_MainPage > 0)
            {
                //SendMessage(iWA_MainPage, BM_CLICK, 0, 0);
                //SendMessage(iWA_MainPage, WM_RBUTTONDOWN, 0, 0);
                //SendMessage(iWA_MainPage, WM_RBUTTONDOWN, MK_RBUTTON, 0);
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_ESCAPE, 0);
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Start View WebAccess Main Page handle");
                bPartResult = false;
            }
            // Login keyboard
            EventLog.AddLog("admin login");
            int iLoginKeyboard_Handle;

            switch (slanguage)
            {
            case "ENG":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;

            case "CHT":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登入");
                break;

            case "CHS":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登录");
                break;

            case "JPN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "ログイン");
                break;

            case "KRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "로그인");
                break;

            case "FRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Connexion");
                break;

            default:
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;
            }
            int iEnterText = tpc.F_FindWindowEx(iLoginKeyboard_Handle, 0, "Edit", "");

            if (iEnterText > 0)
            {
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'a', 0);
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'd', 0); //d
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'm', 0); //m
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'i', 0); //i
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'n', 0); //n
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
                System.Threading.Thread.Sleep(500);
            }
            else
            {
                EventLog.AddLog("Cannot get Login keyboard handle");
                bPartResult = false;
            }
            EventLog.AddLog("Send F5 to show alarm summary");
            tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_F5, 0);
            System.Threading.Thread.Sleep(2000);
            EventLog.PrintScreen("AlarmSummary");

            EventLog.AddLog("Send F6 to show alarm group data");
            tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_F6, 0);
            System.Threading.Thread.Sleep(2000);

            int iAlarmGroup_Handle;

            switch (slanguage)
            {
            case "ENG":
                iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "Alarm Group List");
                break;

            case "CHT":
                iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "警報群組目錄");
                break;

            case "CHS":
                iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "报警群组目录");
                break;

            case "JPN":
                iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "アラーム グループ一覧");
                break;

            case "KRN":
                iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "알람 그룹리스트 ");
                break;

            case "FRN":
                iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "Liste des groupes d'alarme");
                break;

            default:
                iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "Alarm Group List");
                break;
            }
            //int iAlarmGroup_Handle = tpc.F_FindWindow("#32770", "Alarm Group List");
            int iEnterText2 = tpc.F_FindWindowEx(iAlarmGroup_Handle, 0, "Edit", "");

            if (iEnterText2 > 0)
            {
                tpc.F_PostMessage(iEnterText2, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
            }
            else
            {
                EventLog.AddLog("Cannot get Alarm Group List handle");
                bPartResult = false;
            }
            Thread.Sleep(3000);
            EventLog.PrintScreen("AlarmGroupData");
        }
Exemplo n.º 2
0
        //public static void HandleRunningInstance(Process instance)
        //{
        //    // 相同時透過ShowWindowAsync還原,以及SetForegroundWindow將程式至於前景
        //    ShowWindowAsync(instance.MainWindowHandle, WS_SHOWNORMAL);
        //    tcp.F_SetForegroundWindow(instance.MainWindowHandle);
        //}
        long Form1_Load()
        {
            cThirdPartyToolControl tpc = new cThirdPartyToolControl();

            string[] file_name = { "CoilStatus_250_Sync_20160331", "HoldingRegister_250_Sync_20160401", "InputRegister_250_Sync_20160331", "InputStatus_250_Sync_20160401" };

            try
            {
                Process[] processes = Process.GetProcessesByName("ModSim32");
                foreach (Process p in processes)
                {
                    // 關閉目前程序前先等待 1000 毫秒
                    p.WaitForExit(1000);
                    p.CloseMainWindow();
                }
                EventLog.AddLog("Check existed ModSim and Close it");
                System.Threading.Thread.Sleep(1000);

                string str = this.GetType().Assembly.Location;
                str = str.Substring(0, str.LastIndexOf(@"\"));
                string sourceDirName = @"\ModSim";
                string destDirName   = @"c:\ModSim";
                bool   copySubDirs   = true;
                DirectoryCopy(str + sourceDirName, destDirName, copySubDirs);

                string sExePath = Directory.GetCurrentDirectory();  // 如果是用iATester執行初始exe 也是指到iATester執行檔位置
                                                                    // 如果是用初始exe檔直接執行 則是指到初始exe檔執行位置
                string sCurrentFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
                //sCurrentFilePath無論用什麼執行 就是指到初始exe檔執行位置
                for (int i = 0; i < file_name.Length; i++)
                {
                    string sourceFile = sCurrentFilePath + "\\ModSim\\" + file_name[i];
                    string destFile   = sExePath + "\\" + file_name[i];
                    EventLog.AddLog("copy " + sourceFile + " to " + destFile);
                    System.IO.File.Copy(sourceFile, destFile, true);
                }
            }
            catch (Exception ex)
            {
                EventLog.AddLog(@"Error occurred Delete ModSim and Move it to C:\ : " + ex.ToString());
                Result.Text      = "FAIL!!";
                Result.ForeColor = Color.Red;
                EventLog.AddLog("Test Result: FAIL!!");
                return(-1);
            }

            try
            {
                Process ModSim = new Process();
                // FileName 是要執行的檔案
                ModSim.StartInfo.FileName = @"C:\ModSim\ModSim32.exe";
                ModSim.Start();

                EventLog.AddLog("Excute ModSim");
            }
            catch (Exception ex)
            {
                EventLog.AddLog(@"Error occurred Excute ModSim: " + ex.ToString());
                Result.Text      = "FAIL!!";
                Result.ForeColor = Color.Red;
                EventLog.AddLog("Test Result: FAIL!!");
                return(-1);
            }

            try
            {
                System.Threading.Thread.Sleep(3000);
                //EventLog.AddLog("enter");
                tpc.F_KeybdEvent(tpc.V_VK_ESCAPE, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
                //EventLog.AddLog("wait 1 sec");
                System.Threading.Thread.Sleep(1000);

                foreach (Process pTarget in Process.GetProcesses())
                {
                    if (pTarget.ProcessName == "ModSim32")  // 取得處理序名稱並與指定程序名稱比較
                    {
                        //HandleRunningInstance(pTarget);
                        ShowWindowAsync(pTarget.MainWindowHandle, WS_SHOWNORMAL);
                        tpc.F_SetForegroundWindow((int)pTarget.MainWindowHandle);
                    }
                }

                EventLog.AddLog("Load script");

                //string[] file_name = { "CoilStatus_250_Sync_20160331" };

                for (int i = 0; i < file_name.Length; i++)
                {
                    System.Threading.Thread.Sleep(2000);
                    SendKeys.SendWait("^o");
                    System.Threading.Thread.Sleep(1000);

                    int           iRecipeList_Handle = tpc.F_FindWindow("#32770", "Open");
                    StringBuilder lpString           = new StringBuilder(10);
                    int           bb          = tpc.F_GetWindowText(iRecipeList_Handle, lpString, 100);
                    int           iEnterText2 = tpc.F_FindWindowEx(iRecipeList_Handle, 0, "Edit", "");
                    if (iEnterText2 > 0)
                    {
                        byte[] ch = (ASCIIEncoding.ASCII.GetBytes(file_name[i]));
                        for (int j = 0; j < ch.Length; j++)
                        {
                            //SendMessage(PW, WM_CHAR, ch, 0);
                            tpc.F_PostMessage(iEnterText2, tpc.V_WM_CHAR, ch[j], 0);
                            //System.Threading.Thread.Sleep(100);
                        }
                        tpc.F_PostMessage(iEnterText2, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);

                        //tpc.F_PostMessage(iEnterText2, tpc.V_WM_CHAR, 'a', 0);
                    }
                }
            }
            catch (Exception ex)
            {
                EventLog.AddLog(@"Error occurred Load file: " + ex.ToString());
                Result.Text      = "FAIL!!";
                Result.ForeColor = Color.Red;
                EventLog.AddLog("Test Result: FAIL!!");
                return(-1);
            }

            try
            {
                EventLog.AddLog("connect to TCP");

                System.Threading.Thread.Sleep(2000);
                SendKeys.SendWait("%c");
                System.Threading.Thread.Sleep(1000);
                SendKeys.SendWait("%c");
                System.Threading.Thread.Sleep(1000);
                tpc.F_KeybdEvent(tpc.V_VK_RETURN, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
                System.Threading.Thread.Sleep(1000);
                tpc.F_KeybdEvent(tpc.V_VK_UP, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
                System.Threading.Thread.Sleep(1000);
                tpc.F_KeybdEvent(tpc.V_VK_RETURN, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
                System.Threading.Thread.Sleep(2000);
                tpc.F_KeybdEvent(tpc.V_VK_RETURN, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
            }
            catch (Exception ex)
            {
                EventLog.AddLog(@"Error occurred connect to TCP: " + ex.ToString());
                Result.Text      = "FAIL!!";
                Result.ForeColor = Color.Red;
                EventLog.AddLog("Test Result: FAIL!!");
                return(-1);
            }

            try
            {
                if (master != null)
                {
                    master.Dispose();
                }
                if (tcpClient != null)
                {
                    tcpClient.Close();
                }
                tcpClient = new TcpClient();
                IAsyncResult asyncResult = tcpClient.BeginConnect(ipAddress, tcpPort, null, null);
                asyncResult.AsyncWaitHandle.WaitOne(3000, true); //wait for 3 sec
                if (!asyncResult.IsCompleted)
                {
                    tcpClient.Close();
                    EventLog.AddLog("Cannot connect to ModSim.");
                    return(-1);
                }
                //tcpClient = new TcpClient(ipAddress, tcpPort);

                // create Modbus TCP Master by the tcp client
                //document->Modbus.Device.Namespace->ModbusIpMaster Class->Create Method
                master = ModbusIpMaster.CreateIp(tcpClient);
                master.Transport.Retries     = 0; //don't have to do retries
                master.Transport.ReadTimeout = 1500;
                //this.Text = "On line " + DateTime.Now.ToString();
                EventLog.AddLog("Connect to ModSim.");

                //read DI(1xxxx), start address=0, points=4
                byte   slaveID = 1;
                bool[] status  = master.ReadInputs(slaveID, 0, 1);
                if ((status[0] == true) || (status[0] == false))
                {
                }
                else
                {
                    EventLog.AddLog("read DI(10001) fail");
                    return(-1);
                }
                //read DO(00001), start address=0, points=1
                bool[] coils = master.ReadCoils(slaveID, 0, 1);
                if ((coils[0] == true) || (coils[0] == false))
                {
                }
                else
                {
                    EventLog.AddLog("read DO(00001) fail");
                    return(-1);
                }
                //read AI(30001), start address=0, points=1
                ushort[] register = master.ReadInputRegisters(1, 0, 1);
                if (register[0] > 0)
                {
                }
                else
                {
                    EventLog.AddLog("read AI(30001) fail");
                    return(-1);
                }
                //read AO(40001), start address=0, points=1
                ushort[] holding_register = master.ReadHoldingRegisters(1, 0, 1);
                if (holding_register[0] > 0)
                {
                }
                else
                {
                    EventLog.AddLog("read AO(40001) fail");
                    return(-1);
                }
            }
            catch (Exception ex)
            {
                EventLog.AddLog(@"Error occurred verification: " + ex.ToString());
                Result.Text      = "FAIL!!";
                Result.ForeColor = Color.Red;
                EventLog.AddLog("Test Result: FAIL!!");
                return(-1);
            }

            #region Result judgement
            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")
                {
                    bFinalResult = 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 (bFinalResult)
            {
                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
        }
Exemplo n.º 3
0
Arquivo: Form1.cs Projeto: IAGDQA/WA
        private void SaveDatatoExcel(string sProject, string sTestLogFolder)
        {
            string sUserName  = Environment.UserName;
            string sourceFile = string.Format(@"C:\Users\{0}\Documents\ODBC_Temp.xlsx", sUserName);

            if (System.IO.File.Exists(sourceFile))
            {
                System.IO.File.Delete(sourceFile);
            }

            // Control browser
            int iIE_Handl   = tpc.F_FindWindow("IEFrame", "WebAccess Analog Tag Log - Internet Explorer");
            int iIE_Handl_2 = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
            int iIE_Handl_3 = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "WebAccess Analog Tag Log - Internet Explorer");
            int iIE_Handl_4 = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
            int iIE_Handl_5 = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");

            if (iIE_Handl_5 > 0)
            {
                int x = 500;
                int y = 500;

                tpc.F_PostMessage(iIE_Handl_5, tpc.V_WM_RBUTTONDOWN, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
                //SendMessage(this.Handle, WM_LBUTTONDOWN, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
                Thread.Sleep(1000);
                tpc.F_PostMessage(iIE_Handl_5, tpc.V_WM_RBUTTONUP, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
                //SendMessage(this.Handle, WM_LBUTTONUP, 0, (x & 0xFFFF) + (y & 0xFFFF) * 0x10000);
                Thread.Sleep(1000);
                // save to excel
                SendKeys.SendWait("X"); // Export to excel
                Thread.Sleep(10000);
            }
            else
            {
                EventLog.AddLog("Cannot get Internet Explorer_Server page handle");
            }

            int iExcel = tpc.F_FindWindow("XLMAIN", "Microsoft Excel - 活頁簿1");

            if (iExcel > 0)                          // 讓開啟的Excel在最上層顯示
            {
                tpc.F_SetForegroundWindow(iExcel);
                Thread.Sleep(5000);
                SendKeys.SendWait("^s");    // save
                Thread.Sleep(2000);
                SendKeys.SendWait("ODBC_Temp");
                Thread.Sleep(500);
                SendKeys.SendWait("{ENTER}");
            }
            else
            {
                EventLog.AddLog("Could not find excel handle, excel may not be opened!");
            }

            EventLog.AddLog("Copy ODBC_Temp file to Test log folder ");
            string destFile = sTestLogFolder + string.Format("\\ODBCData_{0:yyyyMMdd_hhmmss}.xlsx", DateTime.Now);

            if (System.IO.File.Exists(sourceFile))
            {
                System.IO.File.Copy(sourceFile, destFile, true);
            }
            else
            {
                EventLog.AddLog(string.Format("The file ( {0} ) is not found.", sourceFile));
            }

            EventLog.AddLog("close excel start");
            Process[] processes = Process.GetProcessesByName("EXCEL");
            foreach (Process p in processes)
            {
                EventLog.AddLog("close excel...");
                p.WaitForExit(2000);
                //p.CloseMainWindow();
                p.Kill();
                p.Close();
            }
        }
Exemplo n.º 4
0
        private void PowerUserLoginCheck(string sProjectName, string sWebAccessIP, string sTestLogFolder, string sBrowser)
        {
            EventLog.AddLog("Power user check");
            baseUrl = "http://" + sWebAccessIP;
            if (sBrowser == "Internet Explorer")
            {
                EventLog.AddLog("Browser= Internet Explorer");
                api = new AdvSeleniumAPI("IE", "");
                System.Threading.Thread.Sleep(1000);
            }
            else if (sBrowser == "Mozilla FireFox")
            {
                EventLog.AddLog("Browser= Mozilla FireFox");
                api = new AdvSeleniumAPI("FireFox", "");
                System.Threading.Thread.Sleep(1000);
            }

            // Launch Firefox and login
            api.LinkWebUI(baseUrl + "/broadWeb/bwconfig.asp?username=admin");
            api.ById("userField").Enter("").Submit().Exe();
            PrintStep("Login WebAccess");

            // Configure project by project name
            api.ByXpath("//a[contains(@href, '/broadWeb/bwMain.asp?pos=project') and contains(@href, 'ProjName=" + sProjectName + "')]").Click();
            PrintStep("Configure project");

            // Start view
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("//tr[2]/td/a/font").Click();
            PrintStep("Start View");

            // Control browser
            int iIE_Handl, iIE_Handl_2, iIE_Handl_3, iIE_Handl_4, iIE_Handl_5, iIE_Handl_6, iIE_Handl_7, iWA_MainPage = 0;

            switch (slanguage)
            {
            case "ENG":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHT":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "節點 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "節點 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHS":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "节点 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "节点 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "JPN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "ノード : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "ノード : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "KRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "노드 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "노드 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "FRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Noeud : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Noeud : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            default:
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;
            }

            /*
             * int iIE_Handl = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
             * int iIE_Handl_2 = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
             * int iIE_Handl_3 = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
             * int iIE_Handl_4 = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
             * int iIE_Handl_5 = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
             * int iIE_Handl_6 = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
             * int iIE_Handl_7 = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
             * int iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
             */

            if (iWA_MainPage > 0)
            {
                //SendMessage(iWA_MainPage, BM_CLICK, 0, 0);
                //SendMessage(iWA_MainPage, WM_RBUTTONDOWN, 0, 0);
                //SendMessage(iWA_MainPage, WM_RBUTTONDOWN, MK_RBUTTON, 0);
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_ESCAPE, 0);
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Start View WebAccess Main Page handle");
            }

            // Login keyboard
            int iLoginKeyboard_Handle;

            switch (slanguage)
            {
            case "ENG":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;

            case "CHT":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登入");
                break;

            case "CHS":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登录");
                break;

            case "JPN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "ログイン");
                break;

            case "KRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "로그인");
                break;

            case "FRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Connexion");
                break;

            default:
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;
            }
            int iEnterText = tpc.F_FindWindowEx(iLoginKeyboard_Handle, 0, "Edit", "");
            int iEnter_PW  = tpc.F_GetWindow(iEnterText, tpc.V_GW_HWNDNEXT);

            if (iEnterText > 0 && iEnter_PW > 0)
            {
                SendCharToHandle(iEnterText, 100, "PowerUser");
                SendCharToHandle(iEnter_PW, 100, "12345678");

                tpc.F_PostMessage(iEnterText, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);

                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Login keyboard handle");
            }

            Thread.Sleep(2000);
            EventLog.PrintScreen("PowerUserCheck");

            api.Quit();
            PrintStep("Quit browser");
        }
Exemplo n.º 5
0
    private void WorkSteps()
    {
        PrintTitle("Check folder path.");
        errorCnt = 0;
        string filepath = GCtxtBox.Text;

        if (filepath == "" || filepath == null)
        {
            PrintTitle("Path failed!");
            return;
        }

        selenium = new AdvSeleniumAPIv2();

        selenium.StartupServer("http://" + textBox1.Text);
        System.Threading.Thread.Sleep(1000);

        selenium.Type("id=ACT0", "root");
        selenium.Type("id=PWD0", "00000000");
        selenium.Click("id=APY0");
        selenium.WaitForPageToLoad("30000");
        PrintStep();
        //
        selenium.Click("id=configuration");
        selenium.Click("link=Firmware");
        selenium.Click("id=groupConfigIpSettingBtn");
        selenium.Click("link=With IP Settings");
        selenium.Click("id=inpGroupConfig");
        PrintStep();
        //
        String pathToFile = "";

        if (dev.ModuleType.ToUpper() == "WISE-4012E")
        {
            pathToFile = @filepath + "\\config_file_wise4012e.cfg";
        }
        else if (dev.ModuleType.ToUpper() == "WISE-4012")
        {
            pathToFile = @filepath + "\\config_file_wise4012.cfg";
        }
        else if (dev.ModuleType.ToUpper() == "WISE-4051")
        {
            pathToFile = @filepath + "\\config_file_wise4051.cfg";
        }
        else if (dev.ModuleType.ToUpper() == "WISE-4050")
        {
            pathToFile = @filepath + "\\config_file_wise4050.cfg";
        }
        else if (dev.ModuleType.ToUpper() == "WISE-4060")
        {
            pathToFile = @filepath + "\\config_file_wise4060.cfg";
        }
        else if (dev.ModuleType.ToUpper() == "WISE-4050/LAN")
        {
            pathToFile = @filepath + "\\config_file_wise4050lan.cfg";
        }
        else if (dev.ModuleType.ToUpper() == "WISE-4060/LAN")
        {
            pathToFile = @filepath + "\\config_file_wise4060lan.cfg";
        }
        else if (dev.ModuleType.ToUpper() == "WISE-4010/LAN")
        {
            pathToFile = @filepath + "\\config_file_wise4010lan.cfg";
        }

        //
        System.Threading.Thread.Sleep(3000); int Main_Handl = 0;
        int iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "上傳檔案");
        int iIE_Handl_1           = tpc.F_FindWindowEx(iLoginKeyboard_Handle, 0, "ComboBoxEx32", "");
        int iIE_Handl_2           = tpc.F_FindWindowEx(iIE_Handl_1, 0, "ComboBox", "");

        Main_Handl = tpc.F_FindWindowEx(iIE_Handl_2, 0, "Edit", "");

        if (Main_Handl > 0)
        {
            System.Threading.Thread.Sleep(1000);
            SendCharToHandle(Main_Handl, 1, pathToFile);
            System.Threading.Thread.Sleep(1000);
            tpc.F_PostMessage(Main_Handl, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
            System.Threading.Thread.Sleep(1000);
            //
            selenium.Click("//a[@id='btnGroupConfig']/i");
            PrintStep();
            System.Threading.Thread.Sleep(20000);//delay 20sec
        }
        else
        {
            PrintTitle("Get Handle Fail.");
        }
        //MessageBox.Show("Get Handle Fail.");
        //
        //System.Threading.Thread.Sleep(3000);
        //SendKeys.SendWait(pathToFile);
        //System.Threading.Thread.Sleep(3000);
        //SendKeys.SendWait("{ENTER}");

        PrintTitle("Browser close.");
        selenium.Close();
    }
Exemplo n.º 6
0
        private void StartViewRealTimeTrend()
        {
            // Start view
            EventLog.AddLog("Start view");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("//tr[2]/td/a/font").Click();
            PrintStep("Start View");

            // Control browser
            EventLog.AddLog("Control browser");
            int iIE_Handl, iIE_Handl_2, iIE_Handl_3, iIE_Handl_4, iIE_Handl_5, iIE_Handl_6, iIE_Handl_7, iWA_MainPage = 0;

            switch (slanguage)
            {
            case "ENG":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHT":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "節點 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "節點 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHS":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "节点 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "节点 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "JPN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "ノード : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "ノード : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "KRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "노드 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "노드 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "FRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Noeud : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Noeud : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            default:
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;
            }

            /*
             * int iIE_Handl = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
             * int iIE_Handl_2 = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
             * int iIE_Handl_3 = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
             * int iIE_Handl_4 = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
             * int iIE_Handl_5 = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
             * int iIE_Handl_6 = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
             * int iIE_Handl_7 = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
             * int iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
             */
            if (iWA_MainPage > 0)
            {
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_ESCAPE, 0);
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Start View WebAccess Main Page handle");
            }

            // Login keyboard
            EventLog.AddLog("admin login");
            int iLoginKeyboard_Handle;

            switch (slanguage)
            {
            case "ENG":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;

            case "CHT":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登入");
                break;

            case "CHS":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登录");
                break;

            case "JPN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "ログイン");
                break;

            case "KRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "로그인");
                break;

            case "FRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Connexion");
                break;

            default:
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;
            }

            int iEnterText = tpc.F_FindWindowEx(iLoginKeyboard_Handle, 0, "Edit", "");

            if (iEnterText > 0)
            {
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'a', 0);
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'd', 0); //d
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'm', 0); //m
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'i', 0); //i
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'n', 0); //n
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
                System.Threading.Thread.Sleep(500);
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_F3, 0);
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Login keyboard handle");
            }

            int iRealTimeTrend_Handle;

            switch (slanguage)
            {
            case "ENG":
                iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "Realtime Trend List");
                break;

            case "CHT":
                iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "即時趨勢列表");
                break;

            case "CHS":
                iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "实时趋势列表");
                break;

            case "JPN":
                iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "リアルタイム トレンド一覧");
                break;

            case "KRN":
                iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "실시간 트랜드 리스트");
                break;

            case "FRN":
                iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "Liste courbes en temps réel");
                break;

            default:
                iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "Realtime Trend List");
                break;
            }
            //int iRealTimeTrend_Handle = tpc.F_FindWindow("#32770", "Realtime Trend List");
            int iEnterText2 = tpc.F_FindWindowEx(iRealTimeTrend_Handle, 0, "Edit", "");

            if (iEnterText2 > 0)
            {
                tpc.F_PostMessage(iEnterText2, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
            }
            else
            {
                EventLog.AddLog("Cannot get Realtime Trend List handle");
            }
        }
Exemplo n.º 7
0
        private void StartViewDataLogTrend(string sProjectName, string sTestLogFolder)
        {
            // Start view
            EventLog.AddLog("Start view");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("//tr[2]/td/a/font").Click();
            PrintStep("Start View");

            Thread.Sleep(5000);

            // Control browser
            EventLog.AddLog("Control browser");
            int iIE_Handl, iIE_Handl_2, iIE_Handl_3, iIE_Handl_4, iIE_Handl_5, iIE_Handl_6, iIE_Handl_7, iWA_MainPage = 0;

            switch (slanguage)
            {
            case "ENG":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHT":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "節點 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "節點 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHS":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "节点 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "节点 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "JPN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "ノード : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "ノード : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "KRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "노드 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "노드 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "FRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Noeud : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Noeud : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            default:
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;
            }

            /*
             * int iIE_Handl = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
             * int iIE_Handl_2 = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
             * int iIE_Handl_3 = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
             * int iIE_Handl_4 = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
             * int iIE_Handl_5 = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
             * int iIE_Handl_6 = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
             * int iIE_Handl_7 = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
             * int iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
             */

            if (iWA_MainPage > 0)
            {
                //SendMessage(iWA_MainPage, BM_CLICK, 0, 0);
                //SendMessage(iWA_MainPage, WM_RBUTTONDOWN, 0, 0);
                //SendMessage(iWA_MainPage, WM_RBUTTONDOWN, MK_RBUTTON, 0);
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_ESCAPE, 0);
                System.Threading.Thread.Sleep(1500);
            }
            else
            {
                EventLog.AddLog("Cannot get Start View WebAccess Main Page handle");
            }

            // Login keyboard
            EventLog.AddLog("admin login");
            int iLoginKeyboard_Handle;

            switch (slanguage)
            {
            case "ENG":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;

            case "CHT":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登入");
                break;

            case "CHS":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登录");
                break;

            case "JPN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "ログイン");
                break;

            case "KRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "로그인");
                break;

            case "FRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Connexion");
                break;

            default:
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;
            }

            int iEnterText = tpc.F_FindWindowEx(iLoginKeyboard_Handle, 0, "Edit", "");

            if (iEnterText > 0)
            {
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'a', 0);
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'd', 0); //d
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'm', 0); //m
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'i', 0); //i
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'n', 0); //n
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
                System.Threading.Thread.Sleep(500);
                //PostMessage(iWA_MainPage, WM_KEYDOWN, VK_F4, 0);
                SendKeys.SendWait("{F4}");
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Login keyboard handle");
            }

            int iDataLogTrend_Handle;

            switch (slanguage)
            {
            case "ENG":
                iDataLogTrend_Handle = tpc.F_FindWindow("#32770", "Datalog Trend List");
                break;

            case "CHT":
                iDataLogTrend_Handle = tpc.F_FindWindow("#32770", "資料記錄趨勢列表");
                break;

            case "CHS":
                iDataLogTrend_Handle = tpc.F_FindWindow("#32770", "历史趋势列表");
                break;

            case "JPN":
                iDataLogTrend_Handle = tpc.F_FindWindow("#32770", "データログ トレンド一覧");
                break;

            case "KRN":
                iDataLogTrend_Handle = tpc.F_FindWindow("#32770", "데이터로그 트랜드 리스트");
                break;

            case "FRN":
                iDataLogTrend_Handle = tpc.F_FindWindow("#32770", "Liste courbes historiques");
                break;

            default:
                iDataLogTrend_Handle = tpc.F_FindWindow("#32770", "Datalog Trend List");
                break;
            }
            int iEnterText2 = tpc.F_FindWindowEx(iDataLogTrend_Handle, 0, "Edit", "");

            if (iEnterText2 > 0)
            {
                tpc.F_PostMessage(iEnterText2, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
            }
            else
            {
                EventLog.AddLog("Cannot get DataLog Trend List handle");
            }

            /*
             * int iOK_Button_of_DataLogTrendList = tpc.F_FindWindowEx(iDataLogTrend_Handle, 0, "Button", "OK");
             * if (iOK_Button_of_DataLogTrendList > 0)
             * {
             *  // Change interval value
             *  EventLog.AddLog("Click Change button of PointInfo window");
             *  tpc.F_PostMessage(iOK_Button_of_DataLogTrendList, tpc.V_BM_CLICK, 0, 0);
             *  System.Threading.Thread.Sleep(1000);
             * }
             * else
             *  EventLog.AddLog("Cannot get iOK_Button_of_DataLogTrendList handle");
             *
             * Thread.Sleep(3000);
             * PrintScreen("DataLogData", sTestLogFolder);
             */
            for (int iInterval = 1; iInterval <= 3; iInterval++)
            {
                string[] sInterval = { "1 sec", "2 sec", "5 sec", "10 sec", "20 sec", "40 sec",
                                       "1Min",  "2Min",  "3Min",  "4Min",   "8Min",   "16Min", "28Min",
                                       "1Hour", "2Hour", "4Hour", "6Hour",  "8Hour",  "12Hour",
                                       "1Day",  "2Day",  "3Day",  "4Day",   "5Day" };
                int      iii = sInterval.Length;
                Thread.Sleep(4000);
                SendKeys.SendWait("{F4}"); // Right most
                Thread.Sleep(4000);

                EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_RightMost_Step1", sInterval[iInterval - 1]));

                SendKeys.SendWait("{F2}"); // Left
                Thread.Sleep(4000);

                EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Left_Step2", sInterval[iInterval - 1]));

                SendKeys.SendWait("{F2}"); // Left
                Thread.Sleep(4000);

                EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Right_Step3", sInterval[iInterval - 1]));

                SendKeys.SendWait("{F3}"); // Right
                Thread.Sleep(4000);

                EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Right_Step4", sInterval[iInterval - 1]));

                SendKeys.SendWait("{F3}"); // Right
                Thread.Sleep(4000);

                EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Right_Step5", sInterval[iInterval - 1]));

                SendKeys.SendWait("{F1}"); // Left most
                Thread.Sleep(4000);

                EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_LeftMost_Step6", sInterval[iInterval - 1]));

                SendKeys.SendWait("{F4}"); // Right most
                Thread.Sleep(4000);

                EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_RightMost_Step7", sInterval[iInterval - 1]));

                Thread.Sleep(1000);
                SendKeys.SendWait("^{F5}"); // quick key of PointInfo window
                Thread.Sleep(1000);

                EventLog.AddLog("Open Point Info window");
                int iPointInfo_Handle;
                switch (slanguage)
                {
                case "ENG":
                    iPointInfo_Handle = tpc.F_FindWindow("#32770", "Point Info");
                    break;

                case "CHT":
                    iPointInfo_Handle = tpc.F_FindWindow("#32770", "點資訊");
                    break;

                case "CHS":
                    iPointInfo_Handle = tpc.F_FindWindow("#32770", "点信息");
                    break;

                case "JPN":
                    iPointInfo_Handle = tpc.F_FindWindow("#32770", "ポイント情報");
                    break;

                case "KRN":
                    iPointInfo_Handle = tpc.F_FindWindow("#32770", "포인트 정보");
                    break;

                case "FRN":
                    iPointInfo_Handle = tpc.F_FindWindow("#32770", "Info point");
                    break;

                default:
                    iPointInfo_Handle = tpc.F_FindWindow("#32770", "Point Info");
                    break;
                }

                //  用來改變interval
                //int iPointInfo_Handle = tpc.F_FindWindow("#32770", "Point Info");
                int iEnterText_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Edit", "");
                if (iEnterText_PointInfo > 0)
                {
                    EventLog.AddLog("Change Datalog Trend Interval");
                    SendCharToHandle(iEnterText_PointInfo, 100, "%ADTRDST");
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    EventLog.AddLog("Cannot get EnterText_PointInfo handle");
                }


                int iChange_Button_of_PointInfo = 0;
                switch (slanguage)
                {
                case "ENG":
                    iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Change");
                    break;

                case "CHT":
                    iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "改變");
                    break;

                case "CHS":
                    iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "改变");
                    break;

                case "JPN":
                    iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "変更");
                    break;

                case "KRN":
                    iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "변경");
                    break;

                case "FRN":
                    iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Modifier");
                    break;

                default:
                    iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Change");
                    break;
                }

                if (iChange_Button_of_PointInfo > 0)
                {
                    // Change interval value
                    EventLog.AddLog("Click Change button of PointInfo window");
                    tpc.F_PostMessage(iChange_Button_of_PointInfo, tpc.V_BM_CLICK, 0, 0);
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    EventLog.AddLog("Cannot get iChange_Button_of_PointInfo handle");
                }

                int iEditWindow_of_interval = tpc.F_FindWindow("#32770", "%ADTRDST");
                int iEnterValue_of_interval = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "BW_DSPINUP");      // 換設定interval視窗裡的向右鍵
                if (iEnterValue_of_interval > 0)
                {
                    // Change interval value
                    EventLog.AddLog("Click add one interval button Change window");
                    tpc.F_PostMessage(iEnterValue_of_interval, tpc.V_BM_CLICK, 0, 0);
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    EventLog.AddLog("Cannot get iEnterValue_of_interval handle");
                }


                int iEnterButton_ChangeWindow = 0;
                switch (slanguage)
                {
                case "ENG":
                    iEnterButton_ChangeWindow = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "Enter");       // 按設定interval視窗裡的enter
                    break;

                case "CHT":
                    iEnterButton_ChangeWindow = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "輸入");
                    break;

                case "CHS":
                    iEnterButton_ChangeWindow = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "回车");
                    break;

                case "JPN":
                    iEnterButton_ChangeWindow = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "エンター");
                    break;

                case "KRN":
                    iEnterButton_ChangeWindow = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "Enter");
                    break;

                case "FRN":
                    iEnterButton_ChangeWindow = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "Valider");
                    break;

                default:
                    iEnterButton_ChangeWindow = tpc.F_FindWindowEx(iEditWindow_of_interval, 0, "Button", "Enter");       // 按設定interval視窗裡的enter
                    break;
                }

                if (iEnterButton_ChangeWindow > 0)
                {
                    // Change interval value
                    EventLog.AddLog("Click Enter button Change window");
                    tpc.F_PostMessage(iEnterButton_ChangeWindow, tpc.V_BM_CLICK, 0, 0);
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    EventLog.AddLog("Cannot get iEnterButton_ChangeWindow handle");
                }

                int iExitButton_PointInfo = 0;
                switch (slanguage)
                {
                case "ENG":
                    iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Exit");        // 按PointInfo視窗裡的Exit
                    break;

                case "CHT":
                    iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "退出");
                    break;

                case "CHS":
                    iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "退出");
                    break;

                case "JPN":
                    iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "終了");
                    break;

                case "KRN":
                    iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "종료");
                    break;

                case "FRN":
                    iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Quitter");
                    break;

                default:
                    iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Exit");        // 按PointInfo視窗裡的Exit
                    break;
                }

                if (iExitButton_PointInfo > 0)
                {
                    // Change interval value
                    EventLog.AddLog("Click Exit button of PointInfo window");
                    tpc.F_PostMessage(iExitButton_PointInfo, tpc.V_BM_CLICK, 0, 0);
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    EventLog.AddLog("Cannot get iExitButton_PointInfo handle");
                }

                if (iInterval == sInterval.Length)
                {
                    Thread.Sleep(4000);
                    SendKeys.SendWait("{F4}"); // Right most
                    Thread.Sleep(4000);

                    EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_RightMost_Step1", sInterval[iInterval - 1]));

                    SendKeys.SendWait("{F2}"); // Left
                    Thread.Sleep(4000);

                    EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Left_Step2", sInterval[iInterval - 1]));

                    SendKeys.SendWait("{F2}"); // Left
                    Thread.Sleep(4000);

                    EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Right_Step3", sInterval[iInterval - 1]));

                    SendKeys.SendWait("{F3}"); // Right
                    Thread.Sleep(4000);

                    EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Right_Step4", sInterval[iInterval - 1]));

                    SendKeys.SendWait("{F3}"); // Right
                    Thread.Sleep(4000);

                    EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_Right_Step5", sInterval[iInterval - 1]));

                    SendKeys.SendWait("{F1}"); // Left most
                    Thread.Sleep(4000);

                    EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_LeftMost_Step6", sInterval[iInterval - 1]));

                    SendKeys.SendWait("{F4}"); // Right most
                    Thread.Sleep(4000);

                    EventLog.PrintScreen(string.Format("DataLogTrend_Interval_{0}_RightMost_Step7", sInterval[iInterval - 1]));
                }

                /*
                 * ////////這邊開始左左右右////////
                 * DateTime dt = DateTime.Now.AddSeconds(-270); // 開始時間設定為4分半前
                 * for (int LLRR = 1; LLRR <= 4; LLRR++)
                 * {
                 *  Thread.Sleep(1000);
                 *  SendKeys.SendWait("^{F5}"); // quick key of PointInfo window
                 *  Thread.Sleep(1000);
                 *
                 *  EventLog.AddLog("Open Point Info window");
                 *  //int iPointInfo_Handle;
                 *  switch (slanguage)
                 *  {
                 *      case "ENG":
                 *          iPointInfo_Handle = tpc.F_FindWindow("#32770", "Point Info");
                 *          break;
                 *      case "CHT":
                 *          iPointInfo_Handle = tpc.F_FindWindow("#32770", "點資訊");
                 *          break;
                 *      case "CHS":
                 *          iPointInfo_Handle = tpc.F_FindWindow("#32770", "点信息");
                 *          break;
                 *      case "JPN":
                 *          iPointInfo_Handle = tpc.F_FindWindow("#32770", "ポイント情報");
                 *          break;
                 *      case "KRN":
                 *          iPointInfo_Handle = tpc.F_FindWindow("#32770", "포인트 정보");
                 *          break;
                 *      case "FRN":
                 *          iPointInfo_Handle = tpc.F_FindWindow("#32770", "Info point");
                 *          break;
                 *
                 *      default:
                 *          iPointInfo_Handle = tpc.F_FindWindow("#32770", "Point Info");
                 *          break;
                 *  }
                 *
                 *  //用來改變時間
                 *  iEnterText_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Edit", "");
                 *  if (iEnterText_PointInfo > 0)
                 *  {
                 *      EventLog.AddLog("Change Datalog Trend Interval");
                 *      SendCharToHandle(iEnterText_PointInfo, 100, "%TDTRDSTM");
                 *      System.Threading.Thread.Sleep(1000);
                 *  }
                 *  else
                 *      EventLog.AddLog("Cannot get EnterText_PointInfo handle");
                 *                                                                                                  // 注意! 尚未加上多國語言版本
                 *  iChange_Button_of_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Change");     // 按 PointInfo視窗裡的change 按扭
                 *  if (iChange_Button_of_PointInfo > 0)
                 *  {
                 *      // Change interval value
                 *      EventLog.AddLog("Click Change button of PointInfo window");
                 *      tpc.F_PostMessage(iChange_Button_of_PointInfo, tpc.V_BM_CLICK, 0, 0);
                 *      System.Threading.Thread.Sleep(1000);
                 *  }
                 *  else
                 *      EventLog.AddLog("Cannot get iChange_Button_of_PointInfo handle");
                 *
                 *  int iTDTRDSTM_window = tpc.F_FindWindow("#32770", "%TDTRDSTM");
                 *  int iEditField_of_TDTRDSTM = tpc.F_FindWindowEx(iTDTRDSTM_window, 0, "Edit", "");
                 *  int iBackspace_of_TDTRDSTM = tpc.F_FindWindowEx(iTDTRDSTM_window, 0, "Button", "");
                 *  for (int i = 0; i < 37; i++)    // 換設定interval視窗裡的Backspace
                 *  {
                 *      iBackspace_of_TDTRDSTM = tpc.F_FindWindowEx(iTDTRDSTM_window, iBackspace_of_TDTRDSTM, "Button", "");
                 *  }
                 *  if (iBackspace_of_TDTRDSTM > 0)
                 *  {
                 *      //
                 *      EventLog.AddLog("Click Backspace button Change window");
                 *      tpc.F_PostMessage(iBackspace_of_TDTRDSTM, tpc.V_BM_CLICK, 0, 0);
                 *      System.Threading.Thread.Sleep(1000);
                 *  }
                 *  else
                 *      EventLog.AddLog("Cannot get iBackspace_of_TDTRDSTM handle");
                 *
                 *  if (iEditField_of_TDTRDSTM > 0)
                 *  {
                 *      string sTime;
                 *      if(LLRR <= 2)   //前兩次往左推2單位時間
                 *          sTime = string.Format("{0:yyyy/MM/dd HH:mm:ss}", dt.AddSeconds(-(90*LLRR)));
                 *      else            //後兩次往右推2單位時間
                 *          sTime = string.Format("{0:yyyy/MM/dd HH:mm:ss}", dt.AddSeconds(90*(LLRR-2)));
                 *
                 *      EventLog.AddLog("Enter the date time in Edit field");
                 *      SendCharToHandle(iEditField_of_TDTRDSTM, 100, sTime);
                 *      System.Threading.Thread.Sleep(1000);
                 *      tpc.F_PostMessage(iEditField_of_TDTRDSTM, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
                 *  }
                 *  else
                 *      EventLog.AddLog("Cannot get iEditField_of_TDTRDSTM handle");
                 *
                 *  Thread.Sleep(1000);
                 *  iExitButton_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Button", "Exit");    // 按PointInfo視窗裡的Exit
                 *                                                                                         // 注意! 尚未加上多國語言版本
                 *  if (iExitButton_PointInfo > 0)
                 *  {
                 *      // Change interval value
                 *      EventLog.AddLog("Click Exit button of PointInfo window");
                 *      tpc.F_PostMessage(iExitButton_PointInfo, tpc.V_BM_CLICK, 0, 0);
                 *      System.Threading.Thread.Sleep(1000);
                 *  }
                 *  else
                 *      EventLog.AddLog("Cannot get iExitButton_PointInfo handle");
                 * }
                 */
            }

            // Export Data (ctrl+F4) , 會在C:\WebAccess\Client\TestProject_TestSCADA 產生 $view001.htm 檔
            EventLog.AddLog("Send ctrl+F4 keyboard command to export data");
            if (iWA_MainPage > 0)
            {
                /*
                 * SendMessage(iWA_MainPage, WM_KEYDOWN, VK_CONTROL, 0);
                 * SendMessage(iWA_MainPage, WM_KEYDOWN, VK_F4, 0);
                 * Thread.Sleep(1000);
                 * SendMessage(iWA_MainPage, WM_KEYUP, VK_F4, 0);
                 * SendMessage(iWA_MainPage, WM_KEYUP, VK_CONTROL, 0);
                 */
                /*
                 * keybd_event(VK_CONTROL, 0, 0, 0);
                 * PostMessage(iWA_MainPage, WM_KEYDOWN, VK_F4, 0);
                 * PostMessage(iWA_MainPage, WM_KEYUP, VK_F4, 0);
                 * keybd_event(VK_CONTROL, 0, KEYEVENTF_KEYUP, 0);
                 */
                Thread.Sleep(1000);
                SendKeys.SendWait("^{F4}"); // [Aaron] I have no idea how to implement ctrl+F4...so this poor method used.
                // this method will press ctrl + F4 key with no handle input
                Thread.Sleep(1500);
            }
            else
            {
                EventLog.AddLog("Cannot get Start View WebAccess Main Page handle");
            }

            // copy $view001.htm to log path.
            EventLog.AddLog("copy $view001.htm to log path.");
            {
                string fileNameSrc = "$view001.htm";
                string fileNameTar = string.Format("DataLogGroup_{0:yyyyMMdd_hhmmss}.htm", DateTime.Now);

                string sourcePath = string.Format(@"C:\WebAccess\Client\{0}_TestSCADA", sProjectName);
                string targetPath = sTestLogFolder;

                // Use Path class to manipulate file and directory paths.
                string sourceFile = System.IO.Path.Combine(sourcePath, fileNameSrc);
                string destFile   = System.IO.Path.Combine(targetPath, fileNameTar);

                if (System.IO.File.Exists(sourceFile))
                {
                    System.IO.File.Copy(sourceFile, destFile, true);
                }
                else
                {
                    EventLog.AddLog("Cannot get $view001.htm file");
                }
            }

            if (iWA_MainPage > 0)
            {
                Thread.Sleep(5000); //delay 5s before close $view001 window
                EventLog.AddLog("Send alt+F4 keyboard command to close $view001.htm window");
                SendKeys.SendWait("%{F4}");
                Thread.Sleep(500);
            }
            else
            {
                EventLog.AddLog("Cannot find $view001.htm window");
            }

            //PrintScreen("DataLogData", sTestLogFolder);
        }
Exemplo n.º 8
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;
        }
Exemplo n.º 9
0
Arquivo: Form1.cs Projeto: IAGDQA/WA
        private void StartViewRecipeData(string slanguage)
        {
            // Start view
            EventLog.AddLog("Start view");
            driver.SwitchTo().Frame("rightFrame");
            driver.FindElement(By.XPath("//a[contains(@href, '/broadWeb/system/bwview.asp')]")).Click();
            //PrintStep("Start View");

            // Control browser
            EventLog.AddLog("Control browser");
            int iIE_Handl, iIE_Handl_2, iIE_Handl_3, iIE_Handl_4, iIE_Handl_5, iIE_Handl_6, iIE_Handl_7, iWA_MainPage = 0;

            switch (slanguage)
            {
            case "ENG":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHT":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "節點 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "節點 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "CHS":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "节点 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "节点 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "JPN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "ノード : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "ノード : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "KRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "노드 : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "노드 : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            case "FRN":
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Noeud : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Noeud : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;

            default:
                iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
                iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
                iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
                iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
                iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
                iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
                iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
                iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
                break;
            }

            /*
             * int iIE_Handl = tpc.F_FindWindow("IEFrame", "Node : TestSCADA - main:untitled");
             * int iIE_Handl_2 = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
             * int iIE_Handl_3 = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : TestSCADA - Internet Explorer");
             * int iIE_Handl_4 = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
             * int iIE_Handl_5 = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
             * int iIE_Handl_6 = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
             * int iIE_Handl_7 = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
             * int iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");
             */
            if (iWA_MainPage > 0)
            {
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_ESCAPE, 0);
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Start View WebAccess Main Page handle");
            }

            // Login keyboard
            EventLog.AddLog("admin login");
            int iLoginKeyboard_Handle;

            switch (slanguage)
            {
            case "ENG":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;

            case "CHT":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登入");
                break;

            case "CHS":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "登录");
                break;

            case "JPN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "ログイン");
                break;

            case "KRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "로그인");
                break;

            case "FRN":
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Connexion");
                break;

            default:
                iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
                break;
            }

            int iEnterText = tpc.F_FindWindowEx(iLoginKeyboard_Handle, 0, "Edit", "");

            if (iEnterText > 0)
            {
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'a', 0);
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'd', 0); //d
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'm', 0); //m
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'i', 0); //i
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_CHAR, 'n', 0); //n
                System.Threading.Thread.Sleep(100);
                tpc.F_PostMessage(iEnterText, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
                System.Threading.Thread.Sleep(500);
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_F8, 0);
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Login keyboard handle");
            }

            int iRecipeList_Handle;

            switch (slanguage)
            {
            case "ENG":
                iRecipeList_Handle = tpc.F_FindWindow("#32770", "Recipe List");
                break;

            case "CHT":
                iRecipeList_Handle = tpc.F_FindWindow("#32770", "配方列表");
                break;

            case "CHS":
                iRecipeList_Handle = tpc.F_FindWindow("#32770", "配方列表");
                break;

            case "JPN":
                iRecipeList_Handle = tpc.F_FindWindow("#32770", "レシピ一覧");
                break;

            case "KRN":
                iRecipeList_Handle = tpc.F_FindWindow("#32770", "레시피 리스트");
                break;

            case "FRN":
                iRecipeList_Handle = tpc.F_FindWindow("#32770", "Liste des recettes");
                break;

            default:
                iRecipeList_Handle = tpc.F_FindWindow("#32770", "Recipe List");
                break;
            }
            //int iRecipeList_Handle = tpc.F_FindWindow("#32770", "Recipe List");
            int iEnterText2 = tpc.F_FindWindowEx(iRecipeList_Handle, 0, "Edit", "");

            if (iEnterText2 > 0)
            {
                tpc.F_PostMessage(iEnterText2, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
            }
            else
            {
                EventLog.AddLog("Cannot get Recipe List handle");
            }

            if (iWA_MainPage > 0)
            {
                tpc.F_KeybdEvent(tpc.V_VK_SHIFT, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
                tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_F1, 0);
                System.Threading.Thread.Sleep(1000);
                tpc.F_KeybdEvent(tpc.V_VK_SHIFT, 0, tpc.V_KEYEVENTF_KEYUP, 0);
                System.Threading.Thread.Sleep(1000);
                tpc.F_KeybdEvent(tpc.V_VK_DOWN, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
                System.Threading.Thread.Sleep(1000);
                tpc.F_KeybdEvent(tpc.V_VK_RETURN, 0, tpc.V_KEYEVENTF_EXTENDEDKEY, 0);
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                EventLog.AddLog("Cannot get Start View WebAccess Main Page handle");
            }
        }
Exemplo n.º 10
0
Arquivo: Form1.cs Projeto: IAGDQA/WA
        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
        }
Exemplo n.º 11
0
    //==============================================================//
    private void ViewandSaveCloudTagInfo()
    {
        PrintTitle("Start WA View");
        api.LinkWebUI(txtCloudIp.Text + "/broadWeb/bwconfig.asp?username=admin");
        api.ById("userField").Enter("").Submit().Exe();
        PrintStep();
        // Configure project by project name

        string sProjectName = "WISE%2DDQA"; // WISE-DQA

        api.ByXpath("//a[contains(@href, '/broadWeb/bwMain.asp?pos=project') and contains(@href, 'ProjName=" + sProjectName + "')]").Click();
        PrintStep();

        // Start kernel
        PrintTitle("Start kernel");
        StartNode();

        System.Threading.Thread.Sleep(5000);

        // Start view
        PrintTitle("Start view");
        api.SwitchToCurWindow(0);
        api.SwitchToFrame("rightFrame", 0);
        api.ByXpath("//tr[2]/td/a/font").Click();
        PrintStep();

        System.Threading.Thread.Sleep(1000);
        // Control browser
        PrintTitle("Control browser");
        int iIE_Handl    = tpc.F_FindWindow("IEFrame", "Node : " + RenameModname() + "-AUTOTEST - main:untitled");                              // 注意是CTestSCADA而不是TestSCADA!! Jammy這邊要改!!
        int iIE_Handl_2  = tpc.F_FindWindowEx(iIE_Handl, 0, "Frame Tab", "");
        int iIE_Handl_3  = tpc.F_FindWindowEx(iIE_Handl_2, 0, "TabWindowClass", "Node : " + RenameModname() + "-AUTOTEST - Internet Explorer"); // 注意是CTestSCADA而不是TestSCADA  Jammy這邊要改!!
        int iIE_Handl_4  = tpc.F_FindWindowEx(iIE_Handl_3, 0, "Shell DocObject View", "");
        int iIE_Handl_5  = tpc.F_FindWindowEx(iIE_Handl_4, 0, "Internet Explorer_Server", "");
        int iIE_Handl_6  = tpc.F_FindWindowEx(iIE_Handl_5, 0, "AfxOleControl42s", "");
        int iIE_Handl_7  = tpc.F_FindWindowEx(iIE_Handl_6, 0, "AfxWnd42s", "");
        int iWA_MainPage = tpc.F_FindWindowEx(iIE_Handl_7, 0, "ActXBroadWinBwviewWClass", "Advantech View 001 - main:untitled");

        PrintTitle("Get handle is [" + iWA_MainPage.ToString() + "].");
        if (iWA_MainPage > 0)
        {
            System.Threading.Thread.Sleep(5000);
            tpc.F_PostMessage(iWA_MainPage, tpc.V_WM_KEYDOWN, tpc.V_VK_ESCAPE, 0);
            System.Threading.Thread.Sleep(1000);
        }

        // Login keyboard
        PrintTitle("Login keyboard");
        int iLoginKeyboard_Handle = tpc.F_FindWindow("#32770", "Login");
        int iEnterText            = tpc.F_FindWindowEx(iLoginKeyboard_Handle, 0, "Edit", "");

        if (iEnterText > 0)
        {
            SendCharToHandle(iEnterText, 100, "admin");
            tpc.F_PostMessage(iEnterText, tpc.V_WM_KEYDOWN, tpc.V_VK_RETURN, 0);
        }

        System.Threading.Thread.Sleep(1000);
        SendKeys.SendWait("^{F5}");
        System.Threading.Thread.Sleep(1000);

        int iPointInfo_Handle    = tpc.F_FindWindow("#32770", "Point Info");
        int iEnterText_PointInfo = tpc.F_FindWindowEx(iPointInfo_Handle, 0, "Edit", "");

        if (iEnterText_PointInfo > 0)
        {
            if (ai_point > 0)
            {
                // AT_AI0
                PrintTitle("Print Screen AI Tag.");
                SendCharToHandle(iEnterText_PointInfo, 100, "AUTOTEST-AI_0");
                System.Threading.Thread.Sleep(1500);

                PrintScreen("PlugandPlay_TagInfoSyncTest_AUTOTEST-AI_0", System.IO.Directory.GetCurrentDirectory());
                for (int i = 1; i <= 20; i++)
                {
                    tpc.F_PostMessage(iEnterText_PointInfo, tpc.V_WM_KEYDOWN, tpc.V_VK_BACK, 0);
                    System.Threading.Thread.Sleep(100);
                }
            }

            if (di_point > 0)
            {
                PrintTitle("Print Screen DI Tag.");
                SendCharToHandle(iEnterText_PointInfo, 100, "AUTOTEST-DI_0");
                System.Threading.Thread.Sleep(1500);

                PrintScreen("PlugandPlay_TagInfoSyncTest_AUTOTEST-DI_0", System.IO.Directory.GetCurrentDirectory());
                for (int i = 1; i <= 20; i++)
                {
                    tpc.F_PostMessage(iEnterText_PointInfo, tpc.V_WM_KEYDOWN, tpc.V_VK_BACK, 0);
                    System.Threading.Thread.Sleep(100);
                }
            }

            if (do_point > 0)
            {
                // AT_AI0
                PrintTitle("Print Screen DO Tag.");
                SendCharToHandle(iEnterText_PointInfo, 100, "AUTOTEST-DO_0");
                System.Threading.Thread.Sleep(1500);

                PrintScreen("PlugandPlay_TagInfoSyncTest_AUTOTEST-DO_0", System.IO.Directory.GetCurrentDirectory());
                for (int i = 1; i <= 20; i++)
                {
                    tpc.F_PostMessage(iEnterText_PointInfo, tpc.V_WM_KEYDOWN, tpc.V_VK_BACK, 0);
                    System.Threading.Thread.Sleep(100);
                }
            }


            // AT_DO0100
            //PrintTitle("Exe4012E_AISetting");
            //SendCharToHandle(iEnterText_PointInfo, 100, "AUTOTEST-DO0");
            //System.Threading.Thread.Sleep(1500);

            //PrintScreen("PlugandPlay_TagInfoSyncTest_AUTOTEST-DO0", System.IO.Directory.GetCurrentDirectory());
            //for (int i = 1; i <= 20; i++)
            //{
            //    tpc.F_PostMessage(iEnterText_PointInfo, tpc.V_WM_KEYDOWN, tpc.V_VK_BACK, 0);
            //    System.Threading.Thread.Sleep(100);
            //}
        }

        tpc.F_PostMessage(iPointInfo_Handle, tpc.V_WM_KEYDOWN, tpc.V_VK_ESCAPE, 0);
    }