예제 #1
0
        public string ResultTest(string service, string nameTest, string resultPath, string data, string version, string stend)
        {
            // в конце - статус теста
            // каждый элемент - результат выполнения теста
            // в каждом элементе содержатся шаги и время
            // они идут через один (ШАГ ВРЕМЯ ШАГ...)
            // бывают момент, когда времени 2
            // 2-ое время - это потерянное время

            /*XmlElement xRoot = LoadFile(resultPath);
             * if (xRoot == null)
             * {
             *      Console.WriteLine("cannot_open1");
             *      return ResultTest(service, nameTest, resultPath, data, "time_out", version, stend);
             *      //return "cannot_open";
             * }
             * int flag = 0;
             * Step step = new Step();
             * step.innerSteps = new List<string>();
             * foreach (XmlNode xNode in xRoot)
             * {
             *      foreach (XmlNode children in xNode.ChildNodes)
             *      {
             *              if (children.Name == "ReportNode")
             *              {
             *                      foreach (XmlNode reports in children.ChildNodes)
             *                      {
             *                              foreach (XmlNode steps in reports.ChildNodes)
             *                              {
             *                                      if (steps.Name != "Data")
             *                                      {
             *                                              foreach (XmlNode datas in steps.ChildNodes)
             *                                              {
             *                                                      foreach (XmlNode dataCh in datas.ChildNodes)
             *                                                      {
             *                                                              if (dataCh.Name == "Name" && flag == 0 && dataCh.InnerText.StartsWith("Step"))
             *                                                              {
             *                                                                      flag = 1;
             *                                                                      step = new Step();
             *                                                                      step.innerSteps = new List<string>();
             *                                                                      step.name = dataCh.InnerText;
             *
             *                                                              }
             *                                                              else
             *                                                              if (dataCh.Name == "Name" && flag == 1 && dataCh.InnerText.StartsWith("Step"))
             *                                                              {
             *                                                                      listSteps.Add(step);
             *                                                                      flag = 0;
             *
             *                                                              }
             *                                                              if (dataCh.Name == "Name" && !dataCh.InnerText.StartsWith("Step") && flag == 1)
             *                                                              {
             *                                                                      step.innerSteps.Add(dataCh.InnerText);
             *                                                                      if (dataCh.InnerText.Contains("Stop Run"))
             *                                                                      {
             *                                                                              flag = 0;
             *                                                                              step.time = dataCh.InnerText;
             *                                                                              listSteps.Add(step);
             *                                                                      }
             *                                                              }
             *                                                              if (dataCh.Name == "Description" && dataCh.InnerText.Contains("Total Duration:"))
             *                                                              {
             *                                                                      string dur = dataCh.InnerText.Substring(dataCh.InnerText.LastIndexOf("Total Duration: "));
             *                                                                      step.time = dur.Split(' ')[2];
             *                                                              }
             *                                                      }
             *                                              }
             *                                      }
             *                              }
             *                      }
             *              }
             *              if (children.Name == "Data")
             *              {
             *                      foreach (XmlNode dataChildren in children.ChildNodes)
             *                      {
             *                              if (dataChildren.Name == "Duration")
             *                              {
             *                                      duration = dataChildren.InnerText;
             *                              }
             *                              if (dataChildren.Name == "Result")
             *                              {
             *                                      result = dataChildren.InnerText;
             *                              }
             *                              if (dataChildren.Name == "StartTime")
             *                              {
             *                                      dateofStart = dataChildren.InnerText;
             *                              }
             *                      }
             *              }
             *      }
             * }*/
            List <Step> listSteps = new List <Step>();
            string      result    = TypeResultTest(resultPath);

            logger.WriteLog(nameTest + " = " + result);
            ICollection <string> Iduration = FindNext("<Duration>", resultPath);
            ICollection <string> Idate     = FindNext("<StartTime>", resultPath);

            string[] Aduration = new string[Iduration.Count];
            string[] Adate     = new string[Idate.Count];

            Iduration.CopyTo(Aduration, 0);
            Idate.CopyTo(Adate, 0);

            string duration    = Aduration[Aduration.Length - 1].Split('<')[1].Split('>')[1];
            string dateofStart = Adate[Adate.Length - 1].Split('<')[1].Split('>')[1];

            Steps   steps1 = new Steps();
            Message mess   = new Message();

            /*steps1.innerSteps = new List<List<string>>();
             * steps1.name = new List<string>();*/
            /*for (int i = 0; i < listSteps.Count; i++)
             * {
             *      steps1.name.Add(listSteps[i].name);
             *      steps1.innerSteps.Add(listSteps[i].innerSteps);
             *      mess.Add(listSteps[i].time);
             * }*/

            message = new Message();

            message.Add(nameTest);
            message.Add(nameTest);
            message.Add(result);
            message.Add(JsonConvert.SerializeObject(mess));
            message.Add(duration);
            message.Add("0");
            message.Add(JsonConvert.SerializeObject(steps1));
            message.Add(data);
            message.Add(version);
            message.Add(stend);

            message.Add(DateTime.Now.ToString("dd MMMM yyyy | HH:mm:ss"));
            message.Add(Convert.ToDateTime(dateofStart).ToString("dd MMMM yyyy | HH:mm:ss"));
            message.Add(Convert.ToDateTime(dateofStart).AddSeconds(Int32.Parse(duration)).ToString("dd MMMM yyyy | HH:mm:ss"));
            request  = JsonConvert.SerializeObject(message);
            response = database.SendMsg("AddStatisticDemon", service, request);

            return(result);
        }
예제 #2
0
        public void Init(object RESPONSE)
        {
            flager = 0;
            string data = DateTime.Now.ToString("dd MMMM yyyy | HH:mm:ss");

            Response = (Message)RESPONSE;

            if (Response.args.Count > 0)
            {
                try
                {
                    for (int i = 0; i < Response.args.Count; i += 9)
                    {
                        PackStart pack = new PackStart();
                        pack.Name        = Response.args[i + 1];
                        pack.Service     = Response.args[i];
                        pack.Browser     = Response.args[i + 6];
                        pack.Restart     = Response.args[i + 7];
                        pack.Stend       = Response.args[i + 8];
                        pack.Time        = Response.args[i + 4];
                        pack.IP          = Response.args[i + 3].Split(' ')[2];
                        pack.PathToTests = JsonConvert.DeserializeObject <Message>(Response.args[i + 2]).args[0];
                        pack.TestsInPack = JsonConvert.DeserializeObject <Tests>(Response.args[i + 5]);

                        ConfigStartTest(pack, data);
                        packs.Add(pack);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Ошибка разбора набора " + ex.Message);
                }
                Console.WriteLine("Производится удаление папок");
                packs.ForEach(pack =>
                {
                    for (int i = 0; i < pack.TestsInPack.id.Count; i++)
                    {
                        if (pack.TestsInPack.restart[i].Equals("default"))
                        {
                            pack.TestsInPack.restart[i] = pack.Restart;
                        }
                        if (pack.TestsInPack.time[i].Equals("default"))
                        {
                            pack.TestsInPack.time[i] = pack.Time;
                        }

                        int indexFolder = 1;
                        while (true)
                        {
                            try
                            {
                                Console.WriteLine("\\\\pur-test01\\\\ATST" + pack.PathToTests.Replace("Z:", "") + "\\\\" + pack.TestsInPack.id[i] + "\\\\Res" + indexFolder);
                                Directory.Delete("\\\\pur-test01\\\\ATST" + pack.PathToTests.Replace("Z:", "") + "\\\\" + pack.TestsInPack.id[i] + "\\\\Res" + indexFolder, true);
                                indexFolder++;
                            }
                            catch (Exception ex)
                            {
                                logger.WriteLog("Не удалось удалить папку \\\\pur-test01\\\\ATST" + pack.PathToTests.Replace("Z:", "") + "\\\\" + pack.TestsInPack.id[i] + "\\\\Res" + indexFolder
                                                + " по причине " + ex.Message, "ERROR");
                                break;
                            }
                        }
                    }
                });
                Console.WriteLine("Удаление папок завершено");
            }
            else
            {
                return;
            }

            packs.ForEach(pack =>
            {
                int indexElement = 0;
                for (int i = 0; i < pack.TestsInPack.id.Count; i++)
                {
                    if (flager == 1)
                    {
                        return;
                    }
                    while (Int32.Parse(pack.TestsInPack.restart[indexElement]) >= 0)
                    {
                        CloseUFT();
                        if (flager == 1)
                        {
                            return;
                        }
                        Message message = new Message();

                        message.Add(pack.IP, pack.TestsInPack.id[i]);
                        request     = JsonConvert.SerializeObject(message);
                        response    = database.SendMsg("updateTestsNow", pack.Service, request);
                        FlagStarted = true;
                        string ver  = "";

                        myReg   = new Regex(@"http:\/\/.*\/");
                        ver     = GetVersionStend(myReg.Match(pack.Stend).Value);
                        message = new Message();
                        message.Add(pack.Service, ver, data);
                        pack.VersionStends.Add(ver);
                        Console.WriteLine("ver = " + ver);

                        if (ver == "no_version")
                        {
                            if (Int32.Parse(pack.TestsInPack.restart[indexElement]) == 0)
                            {
                                if (!pack.ResultTest.ContainsKey(pack.TestsInPack.id[indexElement]))
                                {
                                    pack.ResultTest.Add(pack.TestsInPack.id[indexElement], fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, "no_verson", pack.VersionStends[indexElement], pack.Stend));
                                }
                                else
                                {
                                    pack.ResultTest[pack.TestsInPack.id[indexElement]] = fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, "no_verson", pack.VersionStends[indexElement], pack.Stend);
                                }
                            }
                            pack.TestsInPack.restart[indexElement] = (Int32.Parse(pack.TestsInPack.restart[indexElement]) - 1).ToString();
                            FlagStarted = true;
                            logger.WriteLog("Не получена версия стенда", "WARNING");
                            continue;
                        }
                        else if (!ver.Equals("no_version"))
                        {
                            string bufDependons = JsonConvert.DeserializeObject <Message>(pack.TestsInPack.dependon[indexElement]).args[0];
                            try
                            {
                                if (pack.ResultTest[bufDependons].Equals("Failed"))
                                {
                                    if (!pack.ResultTest.ContainsKey(pack.TestsInPack.id[indexElement]))
                                    {
                                        pack.ResultTest.Add(pack.TestsInPack.id[indexElement], fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, "dependen_error", pack.VersionStends[indexElement], pack.Stend));
                                    }
                                    else
                                    {
                                        pack.ResultTest[pack.TestsInPack.id[indexElement]] = fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, "dependen_error", pack.VersionStends[indexElement], pack.Stend);
                                    }

                                    FlagStarted = true;
                                    break;
                                }
                            }
                            catch { }

                            fs.ClearScreenshot(pack.ResultFolders[indexElement]);

                            StartScript(pack.FilesToStart[indexElement], pack);
                            pack.TestsInPack.restart[indexElement] = (Int32.Parse(pack.TestsInPack.restart[indexElement]) - 1).ToString();
                            FlagStarted = true;

                            try
                            {
                                string bufResult = fs.TypeResultTest(pack.ResultFolders[indexElement]);

                                logger.WriteLog("Результат теста " + pack.ResultFolders[indexElement] + " - " + fs.TypeResultTest(pack.ResultFolders[indexElement]), "RESULT");

                                if (bufResult.Equals("Passed") || bufResult.Equals("Warning") || bufResult.Equals("Failed"))
                                {
                                    if (!pack.ResultTest.ContainsKey(pack.TestsInPack.id[indexElement]))
                                    {
                                        pack.ResultTest.Add(pack.TestsInPack.id[indexElement], fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, pack.VersionStends[indexElement], pack.Stend));
                                    }
                                    else
                                    {
                                        pack.ResultTest[pack.TestsInPack.id[indexElement]] = fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, pack.VersionStends[indexElement], pack.Stend);
                                    }
                                    FlagStarted = true;
                                    if (bufResult.Equals("Passed") || bufResult.Equals("Warning"))
                                    {
                                        break;
                                    }
                                    else
                                    {
                                        continue;
                                    }
                                }
                                else if (bufResult.Equals("cannot_open"))
                                {
                                    fs.MakeScreenshot(pack.ResultFolders[indexElement]);
                                    if (!pack.ResultTest.ContainsKey(pack.TestsInPack.id[indexElement]))
                                    {
                                        pack.ResultTest.Add(pack.TestsInPack.id[indexElement], fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, "time_out", pack.VersionStends[indexElement], pack.Stend));
                                    }
                                    else
                                    {
                                        pack.ResultTest[pack.TestsInPack.id[indexElement]] = fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, "time_out", pack.VersionStends[indexElement], pack.Stend);
                                    }
                                    FlagStarted = true;
                                    continue;
                                }
                            }
                            catch (Exception ex)
                            {
                                logger.WriteLog("Ошибка при запуске тестов " + ex.Message, "ERROR");

                                string opt;

                                // ЭТОТ БЛОК НУЖЕН, ЕСЛИ ФАЙЛ XML НЕ БЫЛ СФОРМИРОВАН, НЕ УДАЛЯТЬ
                                if (File.Exists(pack.ResultFolders[indexElement]))
                                {
                                    opt = "Failed";
                                }
                                else
                                {
                                    opt = "no_file";
                                }

                                fs.MakeScreenshot(pack.ResultFolders[indexElement]);
                                if (!pack.ResultTest.ContainsKey(pack.TestsInPack.id[indexElement]))
                                {
                                    pack.ResultTest.Add(pack.TestsInPack.id[indexElement], fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, opt, pack.VersionStends[indexElement], pack.Stend));
                                }
                                else
                                {
                                    pack.ResultTest[pack.TestsInPack.id[indexElement]] = fs.ResultTest(pack.Service, pack.TestsInPack.id[indexElement], pack.ResultFolders[indexElement], data, opt, pack.VersionStends[indexElement], pack.Stend);
                                }
                                FlagStarted = true;
                                continue;
                                //-------------------------
                            }
                        }
                    }
                    Console.WriteLine("Тест " + pack.FilesToStart[indexElement] + " выполнен!");
                    logger.WriteLog("Выполнен тест " + pack.FilesToStart[indexElement], "END");
                    FlagStarted = true;

                    indexElement++;
                    //File.Delete(pack.FilesToStart[indexElement]);
                }
                message = new Message();

                try
                {
                    message.Add(pack.IP, "not");
                    request = JsonConvert.SerializeObject(message);
                    logger.WriteLog("Обновление теста " + request);
                    response = database.SendMsg("updateTestsNow", pack.Service, request);
                }
                catch (Exception ex)
                {
                    logger.WriteLog("Ошибка в обновлении тестов по причине " + ex.Message, "ERROR");
                }

                try
                {
                    message = new Message();
                    message.Add(pack.Service);
                    request = JsonConvert.SerializeObject(message);
                    logger.WriteLog("Удаление автостарта " + request);
                    response = database.SendMsg("DeleteAutostart", pack.Service, request);
                }
                catch (Exception ex)
                {
                    logger.WriteLog("Ошибка в удаления автостарта по причине " + ex.Message, "ERROR");
                }

                try
                {
                    message = new Message();
                    message.Add(pack.Name, pack.Service);
                    request = JsonConvert.SerializeObject(message);
                    logger.WriteLog("Обновление статуса автостарта " + request);
                    response = database.SendMsg("UpdateStatusAutostart", pack.Service, request);
                }
                catch (Exception ex)
                {
                    logger.WriteLog("Ошибка в обновлении статуса автостарта по причине " + ex.Message, "ERROR");
                }

                try
                {
                    message = new Message();
                    message.Add(pack.Name);
                    request = JsonConvert.SerializeObject(message);
                    logger.WriteLog("Обновление статуса набора " + request);
                    response = database.SendMsg("UpdateStatusPack", pack.Service, request);
                }
                catch (Exception ex)
                {
                    logger.WriteLog("Ошибка в обновлении статуса набора по причине " + ex.Message, "ERROR");
                }

                FlagStarted = true;
                Finish(pack);

                try
                {
                    Directory.Delete(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\test\\");
                }
                catch (Exception ex)
                {
                    logger.WriteLog("Невозможно удалить папку с vbs тестов по причине " + ex.Message, "ERROR");
                }
            });
        }