Пример #1
0
        private static void SetExecConfig(string userInput)
        {
            if (userInput.Contains("all") || (!userInput.Contains("testing") && !userInput.Contains("bvt")))
            {
                category = TestCategoryTypes.All;
            }
            else if (userInput.Contains("testing"))
            {
                category = TestCategoryTypes.Testing;
            }
            else if (userInput.Contains("bvt"))
            {
                category = TestCategoryTypes.BVT;
            }


            runApiTest    = userInput.Contains("api") ? true : false;
            runEnrollTest = userInput.Contains("enroll") ? true : false;

            // api test?
            if (runApiTest)
            {
                testCategories.Add("BillingApiTests.dll");
            }

            // enrollment tests?
            if (runEnrollTest)
            {
                testCategories.Add("EnrollmentTests.dll");
            }
        }
Пример #2
0
        public static string ExecTruExTest(string testDllName, string type, TestCategoryTypes category, out string emailMsg)
        {
            StringBuilder sbRet        = new StringBuilder();
            string        emailMessage = string.Empty;
            string        str          = BillingTestCommon.BillingTestCommon.RunTestMethod(testDllName, category, out sbRet, out emailMessage,
                                                                                           exResultName: $"{type}_{BillingTest.Default.TestEnvironment}_{category}"
                                                                                           );

            emailMsg = emailMessage;
            return(sbRet.ToString());
        }
Пример #3
0
        public static string RunTestMethod(string container, TestCategoryTypes category, out StringBuilder sbRet, out string emailMsg,
                                           string exResultName = "", int timeout = -1, bool SaveResult = true, bool email = true)
        {
            StringBuilder emailmsg = new StringBuilder();
            string        str = string.Empty, cmd = string.Empty, arg = string.Empty, sResultOutput = string.Empty;
            string        trxFile       = Path.Combine(currentDir, $"TestResults\\{BillingTestCommonSettings.Default.TestResultTempFilePrefix}.trx");
            string        htmlFile      = Path.Combine(currentDir, $"TestResults\\{BillingTestCommonSettings.Default.TestResultTempFilePrefix}.trx.html");
            string        trx2html      = Path.Combine(currentDir, @"TestResults\" + BillingTestCommonSettings.Default.TrxToHtmlTool);
            string        local         = Environment.CurrentDirectory;                                   // keep a local copy of the test result files
            string        containerName = container.Substring(0, container.IndexOf('.'));

            sbRet = new StringBuilder();

            // check test containers
            if (string.IsNullOrEmpty(container))
            {
                str = "Empty test container!";
                emailmsg.AppendLine($"<p><font color=red>&#160;&#160;&#160;&#160;&#160;&#160;&#160;{str}</font></p>");
                sbRet.AppendLine(str);
                emailMsg = emailmsg.ToString();
                return(email ? emailmsg.ToString() : sbRet.ToString());
            }

            // result file prefix only using the first container
            string rfileprefix  = container.Split('\\')[container.Split('\\').Length - 1];
            string testsuitefix = rfileprefix.Split('.')[0];

            // run test
            try
            {
                // delete result trx file
                DeleteTestResultsFiles();

                // add containers in arg
                cmd  = Path.Combine(GetVSIDSFolder(), "Common7\\IDE\\CommonExtensions\\Microsoft\\TestWindow");
                cmd  = $"\"{Path.Combine(cmd, "vstest.console.exe")}\"";
                arg += $" {container} /InIsolation";

                // add category in arg if needed
                if (category != TestCategoryTypes.Undefined && category != TestCategoryTypes.All)
                {
                    arg += $" /testCaseFilter:\"TestCategory={category}\"";
                }

                // add result in arg
                arg += $" /Logger:trx";

                // run test
                sbRet.AppendLine($"Executing - {cmd} {arg}");
                sResultOutput = ExecuteCommandCatchOutput(cmd, arg);

                sbRet.AppendLine("\t\t" + sResultOutput);
                if (sResultOutput.ToLower().Contains("exitcode = 0"))
                {
                    emailmsg.AppendLine($"<b><font color=green>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PASSED</font></b><br></br>");
                }

                // convert trx to html
                trxFile = GetTestResultFile(testsuitefix);
                //bool bTrxFile = WaitForFileBeenCreated(trxFile);
                if (!string.IsNullOrEmpty(trxFile))
                {
                    sbRet.AppendLine("\ttrx file was created, convert to html format.");
                    str = ExecuteCommand($"\"{trx2html}\"", $"\"{trxFile}\"");
                    sbRet.AppendLine("\t\t" + str);
                    htmlFile = $"{trxFile}.html";
                }
                else
                {
                    sbRet.AppendLine($"\ttrx file was not created.");
                    log.Error($"\ttrx file was not created.");
                    SaveResult = false;
                    emailmsg.AppendLine($"<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Result html may not created, check trx file or log file for details</p>");
                }

                // save test result file
                if (SaveResult)
                {
                    string target = string.IsNullOrEmpty(TestResutlsPath) ? SetTestResulsFolder() : TestResutlsPath;          // test result folder on server

                    try
                    {
                        sbRet.AppendLine("\tCopy trx and html files to result folder.");
                        // copy trx file
                        str = ExecuteCommandCatchOutput("cmd", $"/C copy \"{trxFile}\" \"{local}\" /Y /Z");
                        str = ExecuteCommandCatchOutput("cmd", $"/C copy \"{trxFile}\" \"{target}\" /Y /Z");
                        sbRet.AppendLine("\t\t" + str);
                        // remove some useless lines
                        //RemoveHTMLViewer(htmlFile);
                        // copy html file
                        str = ExecuteCommand("cmd", $"/C copy \"{htmlFile}\" \"{local}\" /Y /Z");
                        str = ExecuteCommand("cmd", $"/C copy \"{htmlFile}\" \"{target}\" /Y /Z");
                        sbRet.AppendLine("\t\t" + str);
                        // email msg
                        str = $"{target}\\{Path.GetFileNameWithoutExtension(htmlFile)}.html";
                        if (sResultOutput.ToLower().Contains("exitcode = 0"))
                        {
                            emailmsg.AppendLine($"<p><font color=light blue>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Please check details <a href=\"{str}\">here</a></font></p>");
                        }
                        else
                        {
                            emailmsg.AppendLine($"<p><font color=red>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Please check details <a href=\"{str}\">here</a></font></p>");
                        }
                    }
                    catch (System.Exception ex)
                    {
                        sbRet.AppendLine("\t\tException - " + ex.ToString());
                        throw new System.Exception("faied to copy result.");
                    }
                }
            }
            catch (System.Exception ex)
            {
                sbRet.AppendLine("\t\tException - " + ex.ToString());
                emailmsg.AppendLine($"<b><font color=red>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Exception: {ex}</font></b><br></br>");
            }
            emailMsg = emailmsg.ToString();
            return(email ? emailmsg.ToString() : sbRet.ToString());
        }