示例#1
0
    void ChangeDIConfig()
    {
        PrintTitle("DIConfgSts");
        api.ById("ioStatus0").ClickAndWait(1000);
        api.ByTxt("DI").ClickAndWait(1000);
        EnterDIConfigPage();
        //
        for (int i = 0; i < di_point; i++)
        {
            api.SelectTxt(i.ToString()).ByCss("#diConfigBaseForm > div.panel-heading "
                                              + "> div.form-group > div.col-lg-3 > div.input-group > #selCh").Exe();
            api.Enter("AUTOTEST-" + "DI_" + i.ToString()).Clear().ByCss("#diConfigBaseForm > div.panel-heading "
                                                                        + "> div.form-group > div.col-lg-6 > div.input-group > #inpTag").Exe();

            api.SelectTxt("DI").ByCss("#selMd").Exe();
            api.ByCss("#diConfigBaseForm > div.panel-footer.clearfix > div.pull-right > #btnSubmit")
            .ClickAndWait(1000);
        }
    }
示例#2
0
文件: Form1.cs 项目: IAGDQA/WA
        private bool bNodeREDDashboardNodeTest(string sProjectName, string sTestLogFolder)
        {
            bool bTestResult = true;

            string[] sDashboardNodeName = { "RTBar_BuildinWidget_InternalDataSource", "RTBar_BuildinWidget_ExternalDataSource", "GroupAid" };
            // Custom widget node 必須與widget builder測試完成後 搭配測試 待完成後再補上

            for (int i = 1; i <= sDashboardNodeName.Length; i++)
            {
                //Step1: add workspace
                api.ByXpath("//a[contains(@href, '#debug')]").Click();      //切到debug視窗
                api.ByXpath("//a[@id='btn-workspace-add-tab']/i").Click();  //新增Sheet2 (主要操作區)

                //Step2: import test case
                string       sCurrentFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
                string       sourceFile       = sCurrentFilePath + string.Format("\\NodeREDSample\\{0}.txt", sDashboardNodeName[i - 1]);
                StreamReader sr = new StreamReader(sourceFile, Encoding.Default);
                string       line;
                string       sNodeRED_Sample = "";
                while ((line = sr.ReadLine()) != null)
                {
                    sNodeRED_Sample += line.ToString();
                    //Console.WriteLine(line.ToString());
                }
                //Replace project name here
                sNodeRED_Sample = sNodeRED_Sample.Replace("TestProjectName", sProjectName);

                /* this method doesn't work...WTF
                 * api.ByXpath("//a[@id='btn-sidemenu']/i").Click(); // click side menu
                 * api.ByXpath("//a[@id='menu-item-import']").MoveToEle(); // moveToElement
                 * Thread.Sleep(2000);
                 * api.ById("menu-item-import-clipboard").Click(); // click Import
                 * Thread.Sleep(2000);
                 * */
                SendKeys.SendWait("^{i}");  // import tag
                Thread.Sleep(2000);

                if (sNodeRED_Sample.Length > 700)   // 如果要寫入的字串太長 會出錯 故用關鍵字wires拆開字串並分別寫入
                {
                    string[] sNodeRED_SampleTemp = sNodeRED_Sample.Split(new string[] { "wires" }, StringSplitOptions.RemoveEmptyEntries);
                    for (int gg = 0; gg < sNodeRED_SampleTemp.Length; gg++)
                    {
                        if (gg == 0)
                        {
                            api.ById("clipboard-import").Enter(sNodeRED_SampleTemp[gg]).Exe();
                        }
                        else
                        {
                            api.ById("clipboard-import").Enter("wires" + sNodeRED_SampleTemp[gg]).Exe();
                        }
                    }
                }
                else
                {
                    api.ById("clipboard-import").Enter(sNodeRED_Sample).Exe();
                }

                api.ById("clipboard-dialog-ok").Click();                   // click ok

                api.ByXpath("//a[@id='btn-workspace-add-tab']/i").Click(); //新增Sheet3
                Thread.Sleep(500);
                api.ByXpath("//div[2]/ul/li[3]/a").DoubleClick();          //點擊Sheet3 -> 為了使貼上去的資料固定住
                api.ByXpath("//button[@type='button']").Click();           //刪除Sheet3

                api.ByXpath("//div[2]/ul/li[2]/a").Click();                //點擊Sheet2
                Thread.Sleep(2000);
                api.ByXpath("//div[2]/ul/li[2]/a").DoubleClick();
                Thread.Sleep(2000);
                api.ById("node-input-workspace-name").Clear();
                Thread.Sleep(2000);
                api.ById("node-input-workspace-name").Enter(sDashboardNodeName[i - 1]).Exe();
                Thread.Sleep(2000);
                api.ByXpath("(//button[@type='button'])[2]").Click();

                Thread.Sleep(2000);

                //Step3: Deploy setting
                api.ByXpath("//a[@id='btn-deploy']/span").Click();  // deploy
                Thread.Sleep(3000);

                //Step4-1: Trigger
                api.ByCss("g.node_button.node_left_button > rect.node_button_button").Click();

                Thread.Sleep(2000);
                //Step4-2: Create dashboard node
                api.ByCss("g.node_button.node_right_button > rect.node_button_button").Click();
                Thread.Sleep(20000);

                EventLog.AddLog("Find pop up dashboard window handle");
                string main; object subobj;                     // Find pop up download window handle
                api.GetWinHandle(out main, out subobj);
                IEnumerator <String> windowIterator = (IEnumerator <String>)subobj;

                List <string> items = new List <string>();
                while (windowIterator.MoveNext())
                {
                    items.Add(windowIterator.Current);
                }

                //EventLog.AddLog("Main window handle= " + main);
                //EventLog.AddLog("Window handle list items[0]= " + items[0]);
                //EventLog.AddLog("Window handle list items[1]= " + items[1]);
                if (main != items[1])
                {
                    //EventLog.AddLog("Switch to items[1]");
                    api.SwitchToWinHandle(items[1]);
                }
                else
                {
                    //EventLog.AddLog("Switch to items[0]");
                    api.SwitchToWinHandle(items[0]);
                }

                Thread.Sleep(1000);
                EventLog.AddLog(sDashboardNodeName[i - 1] + " Dashboard test...");
                string sProducedDashboardName = api.ByCss("div > div > div.title").GetText();  // 抓取產生的dashboard的標題值是否如預期
                if (sDashboardNodeName[i - 1] != sProducedDashboardName)
                {
                    bTestResult = false;
                    EventLog.AddLog("Output type ERROR!!");
                    EventLog.AddLog("Produced dashboard name is: " + sProducedDashboardName);
                    EventLog.AddLog("Correct name should be: " + sDashboardNodeName[i - 1]);
                }

                PrintScreen(sDashboardNodeName[i - 1] + "_Test", sTestLogFolder);
                api.Close();
                api.SwitchToWinHandle(main);

                /*
                 * //Step5: catch debug message and judgment
                 * string sDebugMessageDate = api.ByCss("#debug-content > div:nth-child(1) > span.debug-message-date").GetText();
                 * string sDebugMessageName = api.ByCss("#debug-content > div > span.debug-message-name").GetText();
                 * string sDebugMessageTopic = api.ByCss("#debug-content > div > span.debug-message-topic").GetText();
                 * string sDebugMessagePayload = api.ByCss("#debug-content > div > span.debug-message-payload").GetText();
                 *
                 * EventLog.AddLog(sDashboardNodeName[i - 1] + " Dashboard test");
                 * EventLog.AddLog("-------------Debug Message--------------");
                 * EventLog.AddLog(sDebugMessageDate + " " + sDebugMessageName);
                 * EventLog.AddLog(sDebugMessageTopic);
                 * EventLog.AddLog(sDebugMessagePayload);
                 * EventLog.AddLog("----------------------------------------");
                 * string[] sType = sDebugMessageTopic.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries); // 切割文字抓取回傳type
                 *
                 * if (sType[1] != sOutputType[i - 1])
                 * {
                 *  bTestResult = false;
                 *  EventLog.AddLog("Output type ERROR!!");
                 *  EventLog.AddLog("Correct type is: " + sOutputType[i - 1]);
                 * }
                 *
                 * if (sDebugMessagePayload != sOutputValue[i - 1])
                 * {
                 *  bTestResult = false;
                 *  EventLog.AddLog("Output value ERROR!!");
                 *  EventLog.AddLog("Correct value is: " + sOutputValue[i - 1]);
                 * }
                 *
                 * //Step6: clear debug message
                 * api.ByXpath("//a[@id='debug-tab-clear']/i").Click();    // clear debug message
                 */
                //Step7: delete test sheet
                api.ByXpath("//div[2]/ul/li[2]/a").DoubleClick();       //點擊Sheet2
                Thread.Sleep(1000);
                api.ByXpath("//button[@type='button']").Click();        //刪除Sheet2
                Thread.Sleep(1000);
                api.ByXpath("(//button[@type='button'])[4]").Click();   //確認刪除Sheet2
                Thread.Sleep(1000);
                api.ByXpath("//a[@id='btn-deploy']/span").Click();      // deploy

                PrintStep(sDashboardNodeName[i - 1] + " Test");
                if (sNodeRED_Sample.Length > 700)
                {
                    Thread.Sleep(5000);
                }
            }

            return(bTestResult);
        }
示例#3
0
文件: Form1.cs 项目: IAGDQA/WA
        private void GroundPC_DeleteTag()
        {
            // Delete AT_AI0004/AT_AO0004/AT_DI0004/AT_DO0004/OPCDA_0004/OPCUA_0004/Acc_0004/ConAna_0004/SystemSec_0004
            EventLog.AddLog("<GroundPC> Delete AT_AI0004/AT_AO0004/AT_DI0004/AT_DO0004 tags");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("leftFrame", 0);
            api.ByXpath("//a[3]/img").Click();  //ModSim

            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("(//input[@name='tsel'])[4]").Click();      //AT_AI0004
            api.ByXpath("(//input[@name='tsel'])[254]").Click();    //AT_AO0004
            api.ByXpath("(//input[@name='tsel'])[504]").Click();    //AT_DI0004
            api.ByXpath("(//input[@name='tsel'])[754]").Click();    //AT_DO0004


            api.ByCss("span.e5").Click();   // delete
            string alertText = api.GetAlartTxt();

            if (alertText == "Are you sure you want to delete these tags?" || alertText == "Are you sure you want to delete these 4 tags?")
            {
                api.Accept();
            }

            PrintStep(api, "<GroundPC> Delete AT_AI0004/AT_AO0004/AT_DI0004/AT_DO0004 tags");

            EventLog.AddLog("<GroundPC> Delete OPCDA_0004 tag");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("leftFrame", 0);
            api.ByXpath("//tr[2]/td/table/tbody/tr/td/a[3]/img").Click();   //OPCDA

            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("(//input[@name='tsel'])[4]").Click();      //OPCDA_0004


            api.ByCss("span.e5").Click();   // delete
            string alertText2 = api.GetAlartTxt();

            if (alertText2 == "Are you sure you want to delete these tags?" || alertText2 == "Are you sure you want to delete these 1 tags?")
            {
                api.Accept();
            }

            PrintStep(api, "<GroundPC> Delete OPCDA_0004 tag");

            EventLog.AddLog("<GroundPC> Delete OPCUA_0004 tag");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("leftFrame", 0);
            api.ByXpath("//tr[3]/td/table/tbody/tr/td/a[3]/img").Click();   //OPCUA

            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("(//input[@name='tsel'])[4]").Click();      //OPCUA_0004


            api.ByCss("span.e5").Click();   // delete
            string alertText3 = api.GetAlartTxt();

            if (alertText3 == "Are you sure you want to delete these tags?" || alertText3 == "Are you sure you want to delete these 1 tags?")
            {
                api.Accept();
            }

            PrintStep(api, "<GroundPC> Delete OPCUA_0004 tag");

            EventLog.AddLog("<GroundPC> Delete Acc_0004 tag");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("leftFrame", 0);
            api.ByXpath("//a[contains(@href, '/broadWeb/bwMainRight.asp?pos=AccList')]").Click();   //Acc Point

            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("(//input[@name='tsel'])[4]").Click();      //Acc_0004


            //api.ByXpath("(//a[contains(text(),'Delete')])[4]").Click();   // delete
            api.ByXpath("//a[2]/font/b").Click();
            string alertText4 = api.GetAlartTxt();

            //if (alertText4 == "Delete this Accumulation Point(TagName=Acc_0004), are you sure? ")
            if (alertText4 == "Are you sure you want to delete these 1 tags?")
            {
                api.Accept();
            }

            PrintStep(api, "<GroundPC> Delete Acc_0004 tag");

            EventLog.AddLog("<GroundPC> Delete ConAna_0004 tag");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("leftFrame", 0);
            api.ByXpath("//a[contains(@href, '/broadWeb/bwMainRight.asp?pos=ConstList')]").Click();   //Const Point

            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("(//input[@name='tsel'])[4]").Click();      //ConAna_0004


            //api.ByXpath("(//a[contains(text(),'Delete')])[4]").Click();   // delete
            api.ByXpath("//a[2]/font/b").Click();
            string alertText5 = api.GetAlartTxt();

            //if (alertText5 == "Delete this Constant Point(TagName=ConAna_0004), are you sure? ")
            if (alertText5 == "Are you sure you want to delete these 1 tags?")
            {
                api.Accept();
            }

            PrintStep(api, "<GroundPC> Delete ConAna_0004 tag");

            EventLog.AddLog("<GroundPC> Delete SystemSec_0004 tag");
            api.SwitchToCurWindow(0);
            api.SwitchToFrame("leftFrame", 0);
            api.ByXpath("//a[contains(@href, '/broadWeb/bwMainRight.asp?pos=SysList')]").Click();   //System Point

            api.SwitchToCurWindow(0);
            api.SwitchToFrame("rightFrame", 0);
            api.ByXpath("(//input[@name='tsel'])[4]").Click();      //SystemSec_0004


            //api.ByXpath("(//a[contains(text(),'Delete')])[4]").Click();   // delete
            api.ByXpath("//a[2]/font/b").Click();
            string alertText6 = api.GetAlartTxt();

            //if (alertText6 == "Delete this System Point(TagName=SystemSec_0004), are you sure? ")
            if (alertText6 == "Are you sure you want to delete these 1 tags?")
            {
                api.Accept();
            }

            PrintStep(api, "<GroundPC> Delete SystemSec_0004 tag");
        }
示例#4
0
        private void Create_SelfDefined_Datalog_ExcelReport(string sUserEmail)
        {
            api.ByXpath("//a[contains(@href, 'addRptCfg.aspx')]").Click();

            api.ByName("rptName").Clear();
            api.ByName("rptName").Enter("ExcelReport_SelfDefined_DataLog_Excel").Exe();
            api.ByName("dataSrc").Click();  // Click "Data Log" button
            api.ByName("selectTemplate").SelectVal("template1.xlsx").Exe();
            switch (slanguage)
            {
            case "ENG":
                api.ByName("speTimeFmt").SelectTxt("Self-Defined").Exe();
                break;

            case "CHT":
                api.ByName("speTimeFmt").SelectTxt("自訂").Exe();
                break;

            case "CHS":
                api.ByName("speTimeFmt").SelectTxt("自订").Exe();
                break;

            case "JPN":
                api.ByName("speTimeFmt").SelectTxt("Self-Defined").Exe();
                break;

            case "KRN":
                api.ByName("speTimeFmt").SelectTxt("Self-Defined").Exe();
                break;

            case "FRN":
                api.ByName("speTimeFmt").SelectTxt("Self-Defined").Exe();
                break;

            default:
                api.ByName("speTimeFmt").SelectTxt("Self-Defined").Exe();
                break;
            }

            // set today as start/end date
            string sToday    = DateTime.Now.ToString("%d");
            string sTomorrow = DateTime.Now.AddDays(+1).ToString("%d");

            api.ByName("tStart").Click();
            Thread.Sleep(500);
            api.ByTxt(sToday).Click();
            Thread.Sleep(500);
            api.ByXpath("(//button[@type='button'])[2]").Click();

            if (sTomorrow != "1")
            {
                api.ByName("tEnd").Click();
                Thread.Sleep(500);
                api.ByTxt(sTomorrow).Click();
                Thread.Sleep(500);
                api.ByXpath("(//button[@type='button'])[2]").Click();
            }
            else  // 跳頁
            {
                api.ByName("tEnd").Click();
                Thread.Sleep(500);
                api.ByCss("span.ui-icon.ui-icon-circle-triangle-e").Click();
                Thread.Sleep(500);
                api.ByTxt(sTomorrow).Click();
                Thread.Sleep(500);
                api.ByXpath("(//button[@type='button'])[2]").Click();
            }

            api.ByName("interval").Clear();
            api.ByName("interval").Enter("1").Exe();
            api.ByXpath("(//input[@name='fileType'])[2]").Click();

            // 湊到最大上限32個TAG
            string[] ReportTagName = { "Calc_ConAna",       "Calc_ConDis",   "Calc_ModBusAI", "Calc_ModBusAO", "Calc_ModBusDI",  "Calc_ModBusDO",     "Calc_OPCDA",        "Calc_OPCUA", "Calc_System",
                                       "Calc_ANDConDisAll", "Calc_ANDDIAll", "Calc_ANDDOAll", "Calc_AvgAIAll", "Calc_AvgAOAll",  "Calc_AvgConAnaAll", "Calc_AvgSystemAll",
                                       "AT_AI0050",         "AT_AI0100",     "AT_AI0150",     "AT_AO0050",     "AT_AO0100",      "AT_AO0150",         "AT_DI0050",         "AT_DI0100",  "AT_DI0150",  "AT_DO0050",
                                       "AT_DO0100",         "AT_DO0150",     "ConAna_0100",   "ConDis_0100",   "SystemSec_0100", "SystemSec_0200" };
            for (int i = 0; i < ReportTagName.Length; i++)
            {
                try
                {
                    api.ById("tagsLeftList").SelectTxt(ReportTagName[i]).Exe();
                }
                catch (Exception ex)
                {
                    EventLog.AddLog("CreateExcelReport error: " + ex.ToString());
                    i--;
                }
            }
            api.ById("torightBtn").Click();
            api.ById("tagsRightList").SelectTxt(ReportTagName[0]).Exe();

            api.ByXpath("(//input[@name='attachFormat'])[2]").Click();
            api.ByName("emailto").Clear();
            api.ByName("emailto").Enter(sUserEmail).Exe();
            api.ByName("cfgSubmit").Click();
        }
示例#5
0
        private bool bNodeREDIONodeTest(string sProjectName)
        {
            bool bTestResult = true;

            string[] sIONodeName  = { "GetProjectList", "GetScadaList", "GetTagList", "SetTagValue", "GetTagValue" };
            string[] sOutputType  = { "array", "array", "array", "number", "array" };
            string[] sOutputValue = { sProjectName, "CTestSCADA", "Acc_0035", "1", "whoami" };

            for (int i = 1; i <= sIONodeName.Length; i++)
            {
                //Step1: add workspace
                api.ByXpath("//a[contains(@href, '#debug')]").Click();      //切到debug視窗
                api.ByXpath("//a[@id='btn-workspace-add-tab']/i").Click();  //新增Sheet2 (主要操作區)

                //Step2: import test case
                string       sCurrentFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
                string       sourceFile       = sCurrentFilePath + string.Format("\\NodeREDSample\\{0}.txt", sIONodeName[i - 1]);
                StreamReader sr = new StreamReader(sourceFile, Encoding.Default);
                string       line;
                string       sNodeRED_Sample = "";
                while ((line = sr.ReadLine()) != null)
                {
                    sNodeRED_Sample += line.ToString();
                    //Console.WriteLine(line.ToString());
                }
                //Replace project name here
                sNodeRED_Sample = sNodeRED_Sample.Replace("TestProjectName", sProjectName);

                /* this method doesn't work...WTF
                 * api.ByXpath("//a[@id='btn-sidemenu']/i").Click(); // click side menu
                 * api.ByXpath("//a[@id='menu-item-import']").MoveToEle(); // moveToElement
                 * Thread.Sleep(2000);
                 * api.ById("menu-item-import-clipboard").Click(); // click Import
                 * Thread.Sleep(2000);
                 * */
                SendKeys.SendWait("^{i}");  // import tag
                Thread.Sleep(2000);

                if (sNodeRED_Sample.Length > 700)   // 如果要寫入的字串太長 會出錯 故用關鍵字wires拆開字串並分別寫入
                {
                    string[] sNodeRED_SampleTemp = sNodeRED_Sample.Split(new string[] { "wires" }, StringSplitOptions.RemoveEmptyEntries);
                    for (int gg = 0; gg < sNodeRED_SampleTemp.Length; gg++)
                    {
                        if (gg == 0)
                        {
                            api.ById("clipboard-import").Enter(sNodeRED_SampleTemp[gg]).Exe();
                        }
                        else
                        {
                            api.ById("clipboard-import").Enter("wires" + sNodeRED_SampleTemp[gg]).Exe();
                        }
                    }
                }
                else
                {
                    api.ById("clipboard-import").Enter(sNodeRED_Sample).Exe();
                }

                api.ById("clipboard-dialog-ok").Click();                   // click ok

                api.ByXpath("//a[@id='btn-workspace-add-tab']/i").Click(); //新增Sheet3
                Thread.Sleep(500);
                api.ByXpath("//div[2]/ul/li[3]/a").DoubleClick();          //點擊Sheet3 -> 為了使貼上去的資料固定住
                api.ByXpath("//button[@type='button']").Click();           //刪除Sheet3

                api.ByXpath("//div[2]/ul/li[2]/a").Click();                //點擊Sheet2
                Thread.Sleep(2000);
                api.ByXpath("//div[2]/ul/li[2]/a").DoubleClick();
                Thread.Sleep(2000);
                api.ById("node-input-workspace-name").Clear();
                Thread.Sleep(2000);
                api.ById("node-input-workspace-name").Enter(sIONodeName[i - 1]).Exe();
                Thread.Sleep(2000);
                api.ByXpath("(//button[@type='button'])[2]").Click();
                Thread.Sleep(2000);

                //Step3: Deploy setting
                api.ByXpath("//a[@id='btn-deploy']/span").Click();  // deploy
                Thread.Sleep(3000);

                //Step4: Trigger
                api.ByCss("g.node_button.node_left_button > rect.node_button_button").Click();

                //Step5: catch debug message and judgment
                string sDebugMessageDate    = api.ByCss("#debug-content > div:nth-child(1) > span.debug-message-date").GetText();
                string sDebugMessageName    = api.ByCss("#debug-content > div > span.debug-message-name").GetText();
                string sDebugMessageTopic   = api.ByCss("#debug-content > div > span.debug-message-topic").GetText();
                string sDebugMessagePayload = api.ByCss("#debug-content > div > span.debug-message-payload").GetText();

                EventLog.AddLog(sIONodeName[i - 1] + " IO test");
                EventLog.AddLog("-------------Debug Message--------------");
                EventLog.AddLog(sDebugMessageDate + " " + sDebugMessageName);
                EventLog.AddLog(sDebugMessageTopic);
                EventLog.AddLog(sDebugMessagePayload);
                EventLog.AddLog("----------------------------------------");
                string[] sType = sDebugMessageTopic.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries); // 切割文字抓取回傳type

                if (sType[1] != sOutputType[i - 1])
                {
                    bTestResult = false;
                    EventLog.AddLog("Output type ERROR!!");
                    EventLog.AddLog("Correct type is: " + sOutputType[i - 1]);
                }

                bool isContain = sDebugMessagePayload.Contains(sOutputValue[i - 1]);    // 與Coversion和Logic不同的是這邊使用Contain,
                                                                                        //只要其中有包含到關鍵字即pass
                if (!isContain)
                {
                    bTestResult = false;
                    EventLog.AddLog("Output value ERROR!!");
                    EventLog.AddLog("DebugMessage need to contain: " + sOutputValue[i - 1]);
                }

                //Step6: clear debug message
                api.ByXpath("//a[@id='debug-tab-clear']/i").Click();    // clear debug message

                //Step7: delete test sheet
                api.ByXpath("//div[2]/ul/li[2]/a").DoubleClick();       //點擊Sheet2
                api.ByXpath("//button[@type='button']").Click();        //刪除Sheet2
                api.ByXpath("(//button[@type='button'])[4]").Click();   //確認刪除Sheet2
                api.ByXpath("//a[@id='btn-deploy']/span").Click();      // deploy

                PrintStep(sIONodeName[i - 1] + " Test");
            }

            return(bTestResult);
        }
示例#6
0
文件: Form1.cs 项目: IAGDQA/WA
        private bool bNodeREDMathNodeTest(string sProjectName)
        {
            bool bTestResult = true;

            string[] sMathNodeName = { "FilterTagValue", "ABS", "ADD", "SUB", "MUL", "DIV", "EXP", "LN", "LOG", "MAX", "MIN", "SQRT", "COS", "SIN", "TAN" };
            string[] sOutputType   = { "array", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number", "number" };
            string[] sOutputValue  = { "\"AT_AI0050\", \"AT_AI0100\", \"AT_AI0200\", \"AT_AI0250\", \"AT_AI0150\"", "4.57", "0", "0", "-100", "1", "7.39", "0.69", "1", "4.58", "-4.58", "2", "1", "1", "1" };

            for (int i = 1; i <= sMathNodeName.Length; i++)
            {
                //Step1: add workspace
                api.ByXpath("//a[contains(@href, '#debug')]").Click();      //切到debug視窗
                api.ByXpath("//a[@id='btn-workspace-add-tab']/i").Click();  //新增Sheet2 (主要操作區)

                //Step2: import test case
                string       sCurrentFilePath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(this.GetType()).Location);
                string       sourceFile       = sCurrentFilePath + string.Format("\\NodeREDSample\\{0}.txt", sMathNodeName[i - 1]);
                StreamReader sr = new StreamReader(sourceFile, Encoding.Default);
                string       line;
                string       sNodeRED_Sample = "";
                while ((line = sr.ReadLine()) != null)
                {
                    sNodeRED_Sample += line.ToString();
                    //Console.WriteLine(line.ToString());
                }
                //Replace project name here
                sNodeRED_Sample = sNodeRED_Sample.Replace("TestProjectName", sProjectName);

                /* this method doesn't work...WTF
                 * api.ByXpath("//a[@id='btn-sidemenu']/i").Click(); // click side menu
                 * api.ByXpath("//a[@id='menu-item-import']").MoveToEle(); // moveToElement
                 * Thread.Sleep(2000);
                 * api.ById("menu-item-import-clipboard").Click(); // click Import
                 * Thread.Sleep(2000);
                 * */
                SendKeys.SendWait("^{i}");  // import tag
                Thread.Sleep(2000);

                if (sNodeRED_Sample.Length > 700)   // 如果要寫入的字串太長 會出錯 故用關鍵字wires拆開字串並分別寫入
                {
                    string[] sNodeRED_SampleTemp = sNodeRED_Sample.Split(new string[] { "wires" }, StringSplitOptions.RemoveEmptyEntries);
                    for (int gg = 0; gg < sNodeRED_SampleTemp.Length; gg++)
                    {
                        if (gg == 0)
                        {
                            api.ById("clipboard-import").Enter(sNodeRED_SampleTemp[gg]).Exe();
                        }
                        else
                        {
                            api.ById("clipboard-import").Enter("wires" + sNodeRED_SampleTemp[gg]).Exe();
                        }
                    }
                }
                else
                {
                    api.ById("clipboard-import").Enter(sNodeRED_Sample).Exe();
                }

                api.ById("clipboard-dialog-ok").Click();                   // click ok

                api.ByXpath("//a[@id='btn-workspace-add-tab']/i").Click(); //新增Sheet3
                Thread.Sleep(500);
                api.ByXpath("//div[2]/ul/li[3]/a").DoubleClick();          //點擊Sheet3 -> 為了使貼上去的資料固定住
                api.ByXpath("//button[@type='button']").Click();           //刪除Sheet3

                api.ByXpath("//div[2]/ul/li[2]/a").Click();                //點擊Sheet2
                Thread.Sleep(2000);
                api.ByXpath("//div[2]/ul/li[2]/a").DoubleClick();
                Thread.Sleep(2000);
                api.ById("node-input-workspace-name").Clear();
                Thread.Sleep(2000);
                api.ById("node-input-workspace-name").Enter(sMathNodeName[i - 1]).Exe();
                Thread.Sleep(2000);
                api.ByXpath("(//button[@type='button'])[2]").Click();
                Thread.Sleep(2000);

                //Step3: Deploy setting
                api.ByXpath("//a[@id='btn-deploy']/span").Click();  // deploy
                Thread.Sleep(3000);

                //Step4: Trigger
                api.ByCss("g.node_button.node_left_button > rect.node_button_button").Click();

                //Step5: catch debug message and judgment
                string sDebugMessageDate    = api.ByCss("#debug-content > div:nth-child(1) > span.debug-message-date").GetText();
                string sDebugMessageName    = api.ByCss("#debug-content > div > span.debug-message-name").GetText();
                string sDebugMessageTopic   = api.ByCss("#debug-content > div > span.debug-message-topic").GetText();
                string sDebugMessagePayload = api.ByCss("#debug-content > div > span.debug-message-payload").GetText();

                EventLog.AddLog(sMathNodeName[i - 1] + " Math test");
                EventLog.AddLog("-------------Debug Message--------------");
                EventLog.AddLog(sDebugMessageDate + " " + sDebugMessageName);
                EventLog.AddLog(sDebugMessageTopic);
                EventLog.AddLog(sDebugMessagePayload);
                EventLog.AddLog("----------------------------------------");
                string[] sType = sDebugMessageTopic.Split(new string[] { ": " }, StringSplitOptions.RemoveEmptyEntries); // 切割文字抓取回傳type

                if (sType[1] != sOutputType[i - 1])
                {
                    bTestResult = false;
                    EventLog.AddLog("Output type ERROR!!");
                    EventLog.AddLog("Correct type is: " + sOutputType[i - 1]);
                }

                if (sMathNodeName[i - 1] == "FilterTagValue")   // special case 先將預計要得到的值拆解 再分別去確認sDebugMessagePayload裡面有沒有包含
                {
                    string[] ss = sOutputValue[i - 1].Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);

                    bool bFilterDisp = true;

                    for (int c = 0; c < ss.Length; c++)
                    {
                        bFilterDisp = bFilterDisp && sDebugMessagePayload.Contains(ss[c]);
                    }

                    if (!bFilterDisp)
                    {
                        bTestResult = false;
                        EventLog.AddLog("Output value ERROR!!");
                        EventLog.AddLog("Correct value should include the following: " + sOutputValue[i - 1]);
                    }
                }
                else
                {
                    if (sDebugMessagePayload != sOutputValue[i - 1])
                    {
                        bTestResult = false;
                        EventLog.AddLog("Output value ERROR!!");
                        EventLog.AddLog("Correct value is: " + sOutputValue[i - 1]);
                    }
                }

                //Step6: clear debug message
                api.ByXpath("//a[@id='debug-tab-clear']/i").Click();    // clear debug message

                //Step7: delete test sheet
                api.ByXpath("//div[2]/ul/li[2]/a").DoubleClick();       //點擊Sheet2
                api.ByXpath("//button[@type='button']").Click();        //刪除Sheet2
                api.ByXpath("(//button[@type='button'])[4]").Click();   //確認刪除Sheet2
                api.ByXpath("//a[@id='btn-deploy']/span").Click();      // deploy

                PrintStep(sMathNodeName[i - 1] + " Test");
                if (sNodeRED_Sample.Length > 700)
                {
                    Thread.Sleep(5000);
                }
            }

            return(bTestResult);
        }