Ejemplo n.º 1
0
        /// <summary>
        /// TCM Function to export the trx file from the test run
        /// </summary>
        /// <returns></returns>
        public static string TCMExport()
        {
            LogMessageToFile("TCM Export Function started");
            Console.WriteLine("TCM Export Function started...");
            resultFile = curDir + tmp + @"\latest" + DateTime.Now.ToFileTime().ToString().Substring(0, 6) + ".trx";
            string[] cntrlines = { "cd " + tcmPath,
                                   "tcm run /export /id:" + sp.runId + " /resultsfile:" + "\"" + resultFile + "\""
                                   + " /collection:" + ConfigFile.col + " /teamproject:" + "\"" + ConfigFile.proj + "\"" };
            string   tcmExportBat = curDir + tmp + "tcmExport.bat";

            LogBatFileOutput(cntrlines, tcmExportBat);
            System.IO.File.WriteAllLines(tcmExportBat, cntrlines);
            string tcmExport = CmdLine.GetCmdOut(tcmExportBat, true);

            LogMessageToFile("The Command Output is : " + tcmExport);
            Console.WriteLine("Done");
            if (tcmExport.Contains("Completed"))
            {
                Console.WriteLine("Initiated TRX File parsing");
                TRXFileParser.TRXParser();
                firstTry = true;
                Console.WriteLine("The value of the first try of parsing is : " + firstTry.ToString());
            }
            return(tcmExport);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// TCM Command line to execute the test run using TCM Create Command
        /// </summary>
        /// <returns>Output of the command line</returns>
        public static string TCMExecute(string rId)
        {
            LogMessageToFile("TCM Execute Function started");
            Console.WriteLine("TCM Execute Function started...");

            string[] cntrlines = { "cd " + tcmPath,
                                   "for /f " + "\"" + "delims=" + "\"" + " %%a in ('" + "\"" + "powershell get-date -format G" + "\"" + "') do set t=%%a",
                                   "call:While",
                                   ":While",
                                   "tcm run /execute /id:" + rId + " /collection:" + ConfigFile.col + " /teamproject:" + "\"" + ConfigFile.proj + "\"",
                                   "if %ERRORLEVEL% GTR 0 goto While",
                                   "cd %windir%",
                                   "cd system32",
                                   "Taskkill /F /IM IEDriverServer.exe",
                                   "Taskkill /F /IM iexplore.exe",
                                   "Taskkill /F /IM chromedriver.exe",
                                   "Taskkill /F /IM chrome.exe",
                                   "Taskkill /F /IM firefox.exe",
                                   "exit" };
            string   tcmExecuteBat = curDir + tmp + "tcmExecute.bat";

            LogBatFileOutput(cntrlines, tcmExecuteBat);
            System.IO.File.WriteAllLines(tcmExecuteBat, cntrlines);
            string tcmExecuteOut = CmdLine.GetCmdOut(tcmExecuteBat, true);

            LogMessageToFile("The Command Output is : " + tcmExecuteOut);
            Console.WriteLine("Done");
            Console.WriteLine("The Output of the execution is : " + tcmExecuteOut);
            return(tcmExecuteOut);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// TCM Command line to execute the test run using TCM Create Command
        /// </summary>
        /// <returns>Output of the command line</returns>
        public static string TCMPrExecute(string rId)
        {
            LogMessageToFile("TCM Execute Function started");
            Console.WriteLine("TCM Execute Function started...");

            string[] cntrlines = { "cd " + tcmPath,
                                   "tcm run /execute /id:" + rId + " /collection:" + ConfigFile.col + " /teamproject:" + "\"" + ConfigFile.proj + "\"",
                                   "cd %windir%",
                                   "cd system32",
                                   "Taskkill /F /IM IEDriverServer.exe",
                                   "Taskkill /F /IM iexplore.exe",
                                   "Taskkill /F /IM chromedriver.exe",
                                   "Taskkill /F /IM chrome.exe",
                                   "Taskkill /F /IM firefox.exe",
                                   "exit" };
            string   tcmExecuteBat = curDir + tmp + "tcmExecute.bat";

            LogBatFileOutput(cntrlines, tcmExecuteBat);
            System.IO.File.WriteAllLines(tcmExecuteBat, cntrlines);
            string tcmExecuteOut = CmdLine.GetCmdOut(tcmExecuteBat, true);

            LogMessageToFile("The Command Output is : " + tcmExecuteOut);
            Console.WriteLine("Done");
            Console.WriteLine("The Output of the execution is : " + tcmExecuteOut);
            return(tcmExecuteOut);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// TCM function to create test run for particular suite.
        /// Could be used to run pre-requisite flows
        /// </summary>
        /// <param name="testMode"></param>
        /// <returns></returns>
        public static string TCMPRCreateAndExecuteM2M(string sId, string pId, string cId)
        {
            string prTitle = "Pre-Requisite_" + recent;

            string[] lines = { "cd /",
                               "cd " + tcmPath,
                               "tcm run /create /title:" + "\"" + prTitle + "\"" + " /planid:"
                               + pId + " /suiteid:" + sId + " /configid:" + cId
                               + " /builddir:" + "\"" + destFilepath + "\"" + " /collection:" + ConfigFile.col + " /teamproject:"
                               + "\"" + ConfigFile.proj + "\"" + " /settingsname:" + "\"" + ConfigFile.settingsnme + "\"" + " /include" };
            string   tcmPRBat = curDir + tmp + "tcmPRCreate.bat";

            System.IO.File.WriteAllLines(tcmPRBat, lines);
            LogBatFileOutput(lines, tcmPRBat);
            string strTmp = CmdLine.GetCmdOut(tcmPRBat, true);

            if (strTmp.Contains("created with ID: "))
            {
                LogMessageToFile("Pre Requisite run Id was created successfully using tcm create overload function");
                sp.prRunId = strTmp.Split(new string[] { "created with ID: " }, StringSplitOptions.None)[1].Split('.')[0].Trim();
                Console.WriteLine("Pre Requisite run ID generated is : " + sp.prRunId);
                LogMessageToFile("Pre Requisite run ID generated is : " + sp.prRunId);
            }
            TCMPrExecute(sp.prRunId);

            if (!TFSFunctions.GetTestRunState(prTitle).Contains("Completed"))
            {
                throw new Exception("PR Suite Failed");
            }

            return(sp.prRunId);
        }
Ejemplo n.º 5
0
        public static void ReRunCustomization()
        {
            Console.WriteLine("Initiating Re Run Customization.....");

            switch (ConfigFile.proj.ToUpper())
            {
            case "<SPL_RERUN_CASES>":
                LogMessageToFile("Running the precondition BAT file for Factory MES Project");
                try
                {
                    string echo = CmdLine.GetCmdOut(ConfigFile.restoreDbPath);
                    Console.WriteLine(echo);

                    System.Threading.Thread.Sleep(300000);
                }
                catch (Exception ex)
                {
                    LogMessageToFile("Exception found while running precondition BAT file for Factory MES is " + ex.ToString());
                }

                break;


            default:
                break;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// TCM function to create a test run using query method
        /// </summary>
        /// <returns></returns>
        public static string TCMCreateByPriority()
        {
            LogMessageToFile("TCMCreateByPriority Function started");
            Console.WriteLine("TCMCreateByPriority Function started...");

            string[] lines = { "cd /",
                               "cd " + tcmPath,
                               "tcm run /create /title:" + "\"" + "Daily Run_" + recent + "\"" + " /planid:"
                               + ConfigFile.pId + " /querytext:" + "\""
                               + "SELECT * FROM TestPoint WHERE PlanId=" + ConfigFile.pId + " and ConfigurationId=" + ConfigFile.cId + " order by Priority\""
                               + " /builddir:" + "\"" + destFilepath + "\"" + " /collection:" + ConfigFile.col + " /teamproject:"
                               + "\"" + ConfigFile.proj + "\"" + " /settingsname:" + "\"" + ConfigFile.settingsnme + "\"" + " /include" };
            string   tcmBat = curDir + tmp + "tcmCreate.bat";

            LogBatFileOutput(lines, tcmBat);
            System.IO.File.WriteAllLines(tcmBat, lines);
            string strTmp = CmdLine.GetCmdOut(tcmBat, true);

            if (strTmp.Contains("created with ID: "))
            {
                LogMessageToFile("Run Id was created successfully using tcm create function");
                sp.curRunId = sp.runId = strTmp.Split(new string[] { "created with ID: " }, StringSplitOptions.None)[1].Split('.')[0].Trim();
                Console.WriteLine("Run ID generated is : " + sp.runId);
                LogMessageToFile("The Run ID generated was : " + sp.runId);
            }
            else
            {
                LogMessageToFile("Run Id was created successfully using tcm create function for controller triggered run");
                sp.curRunId = sp.runId = TCMCreateController();
                Console.WriteLine("Run ID generated is : " + sp.runId);
            }
            Console.WriteLine("Done");
            return(sp.runId);
        }
        public static string GetTcmPath()
        {
            Console.WriteLine("Initiated search for TCM Path...");
            string[] cntrlines = { "cd /",
                                   "dir tcm.exe /s /p",
                                   "exit" };
            string   tcmPathBat = curDir + tmp + "tcmpath.bat";

            LogBatFileOutput(cntrlines, tcmPathBat);
            System.IO.File.WriteAllLines(tcmPathBat, cntrlines);
            Console.WriteLine("Done");
            return(CmdLine.GetCmdOut(tcmPathBat));
        }
Ejemplo n.º 8
0
 public static void ConsoleSession()
 {
     LogMessageToFile("Putting Back The Machine Back To Console Session");
     psBat = curDir + tmp + "PSExecution.bat";
     string[] lines =
     {
         "cd /",
         "cd " + psExecPath,
         "psexec \\\\" + Environment.MachineName + " -u DOMAIN\\SERVICE_ACCOUNT_NAME -p SERVICE_ACCOUNT_PASSWORD -s tscon" + GetSessionId() + "/dest:console",
     };
     LogBatFileOutput(lines, psBat);
     System.IO.File.WriteAllLines(psBat, lines);
     CmdLine.GetCmdOut(psBat);
     LogMessageToFile("Machine Has Been Put Back To Console Session");
 }
Ejemplo n.º 9
0
        private static string GetSessionId()
        {
            batOutput = curDir + tmp + "output.txt";
            System.IO.File.Create(batOutput).Close();

            //psExec Command To Get The Session Id Of The User
            LogMessageToFile("Getting The User Session ID");
            string[] lines = { "cd /",
                               "cd " + psExecPath,
                               "psexec \\\\" + Environment.MachineName + "-u DOMAIN\\SERVICE_ACCOUNT_NAME -p SERVICE_ACCOUNT_PASSWORD query session 1>" + batOutput };

            LogBatFileOutput(lines, psBat);
            System.IO.File.WriteAllLines(psBat, lines);
            CmdLine.GetCmdOut(psBat);
            LogMessageToFile("The Bat File Was Executed Properly And OutPut Is Redirected" + batOutput);
            HashSet <string> strings = new HashSet <string>(File.ReadAllLines(batOutput));

            return(strings.Single(x => x.Contains(ConfigFile.userName.Split("\\".ToCharArray())[1])).Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[2]);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// TCM function to create a test run using query method
        /// </summary>
        /// <returns></returns>
        public static string TCMCreateUsingSuiteId(string sId)
        {
            LogMessageToFile("TCM Create Using Suite Id Function started");
            Console.WriteLine("TCM Create Using Suite Id Function started...");
            string queryText = null;

            queryText = ExtractQueryForSuiteIDs(sId, queryText);

            LogMessageToFile("The Query Text that was passed to TCM run create function is : " + queryText);

            string[] lines = { "cd /",
                               "cd " + tcmPath,
                               "tcm run /create /title:" + "\"" + ConfigFile.Runtitle + recent + "\"" + " /planid:"
                               + ConfigFile.pId + " /querytext:" + queryText
                               + " /builddir:" + "\"" + destFilepath + "\"" + " /collection:" + ConfigFile.col + " /teamproject:"
                               + "\"" + ConfigFile.proj + "\"" + " /settingsname:" + "\"" + ConfigFile.settingsnme + "\"" + " /include" };
            string   tcmBat = curDir + tmp + "tcmCreate.bat";

            LogBatFileOutput(lines, tcmBat);
            System.IO.File.WriteAllLines(tcmBat, lines);
            string strTmp = CmdLine.GetCmdOut(tcmBat, true);

            LogMessageToFile(strTmp);
            if (strTmp.Contains("created with ID: "))
            {
                LogMessageToFile("Run Id was created successfully using tcm create using suite id function");

                sp.curRunId = sp.runId = strTmp.Split(new string[] { "created with ID: " }, StringSplitOptions.None)[1].Split('.')[0].Trim();
                Console.WriteLine("Run ID generated is : " + sp.runId);
                LogMessageToFile("The Run ID generated was : " + sp.runId);
            }
            else
            {
                LogMessageToFile("Run Id was created successfully using tcm create using suite id function for controller triggered run");
                sp.curRunId = sp.runId = TCMCreateController();
                Console.WriteLine("Run ID generated is : " + sp.runId);
            }
            Console.WriteLine("Done");
            return(sp.runId);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creating Controller triggered test run
        /// </summary>
        /// <returns></returns>
        public static string TCMCreateController()
        {
            string[] cntrlines = { "cd /",
                                   "cd " + tcmPath,
                                   "tcm run /create /title:" + "\"" + "Daily Run_" + recent + "\"" + " /planid:"
                                   + ConfigFile.pId + " /querytext:" + "\""
                                   + "SELECT * FROM TestPoint WHERE PlanId=" + ConfigFile.pId + " and ConfigurationId=" + ConfigFile.cId + "\""
                                   + " /builddir:" + "\"" + destFilepath + "\"" + " /collection:" + ConfigFile.col + " /teamproject:"
                                   + "\"" + ConfigFile.proj + "\"" + " /flavor:" + ConfigFile.Flav + " /platform:" + ConfigFile.platfrm
                                   + " /testenvironment:" + ConfigFile.environmnt + " /settingsname:" + "\"" + ConfigFile.settingsnme + "\"" + " /include" };
            string   tcmControllerBat = curDir + tmp + "tcmControlCreate.bat";

            LogBatFileOutput(cntrlines, tcmControllerBat);
            System.IO.File.WriteAllLines(tcmControllerBat, cntrlines);
            string tcmCreateControllerOut = CmdLine.GetCmdOut(tcmControllerBat, true);

            LogMessageToFile("The Command Output is : " + tcmCreateControllerOut);
            if (tcmCreateControllerOut.Contains("created with ID: "))
            {
                controller  = true;
                sp.curRunId = sp.runId = tcmCreateControllerOut.Split(new string[] { "created with ID: " }, StringSplitOptions.None)[1].Split('.')[0].Trim();
            }
            return(sp.runId);
        }
Ejemplo n.º 12
0
        public static void firewall()
        {
            try
            {
                //Output.txt File Is Created To Hold All The CommandLine Output
                batOutput = curDir + tmp + "output.txt";
                System.IO.File.Create(batOutput).Close();

                //tcmExecutionBatFile Is Created To Copy It To Remote Mahchine And Trigger It Interactivly
                string tcmExecution = curDir + tmp + "tcmExecution.bat";
                System.IO.File.Create(tcmExecution).Close();

                firewallStatus = true;

                //psExec Command To Find The FireWall Status (Whether Its Turned Off Or On)

                string[] lines = { "cd /",
                                   "cd " + psExecPath,
                                   "psexec " + ConfigFile.remoteMachineName + " -u " + ConfigFile.userName + " -p " + ConfigFile.passWord + " netsh advfirewall show allprofiles state 1>" + batOutput };

                //Creating The Bat To Execute the psExec Commands
                psBat = curDir + tmp + "PSExecution.bat";
                LogBatFileOutput(lines, psBat);
                System.IO.File.WriteAllLines(psBat, lines);
                CmdLine.GetCmdOut(psBat);

                //Reading The OutPut.txt file
                LogMessageToFile("The Bat File:" + psBat + "Executed Successfully");
                HashSet <string> strings = new HashSet <string>(File.ReadAllLines(batOutput));

                if (strings.Any(x => x.Contains(firewallState)))
                {
                    firewallStatus = false;
                }
                if (firewallStatus)
                {
                    //Cmd To Execute The TCM Bat File
                    string[] lines2 =
                    {
                        "NetSh Advfirewall set allprofiles state off",
                        tcmBatFilePath,
                        "NetSh Advfirewall set allprofiles state on",
                    };

                    //Cmd To Copy File To Remote Machine And Execute Interactively
                    string[] script =
                    {
                        "cd /",
                        "cd " + psExecPath,
                        "psexec " + ConfigFile.remoteMachineName + " -u " + ConfigFile.userName + " -p " + ConfigFile.passWord + " -i " + GetSessionId() + " -c -v " + tcmExecution,
                    };
                    LogBatFileOutput(script, psBat);
                    System.IO.File.WriteAllLines(psBat, script);
                    LogBatFileOutput(lines2, tcmExecution);
                    System.IO.File.WriteAllLines(tcmExecution, lines2);
                    LogMessageToFile("The Execution Of TCM Starting.....");
                    CmdLine.GetCmdOut(psBat);
                }
                else
                {
                    MessageBox.Show("Please Turn On the firewall on the system : " + ConfigFile.remoteMachineName);
                }
            }
            catch (Exception exe)
            {
                MessageBox.Show("Exception : " + exe.ToString());
            }
        }