public static DataTable GetCompatibilityMatrix() { DataTable dt = new DataTable(); SqlConnection sCon = new SqlConnection(); try { sCon = Query.GetConnection(); SqlCommand sCmd = new SqlCommand("select * from Compatibility", sCon); SqlDataAdapter sData = new SqlDataAdapter(sCmd); sData.Fill(dt); } catch (Exception ex) { LoggerUtil.LogMessageToFile("Exception caught while Getting the compatibility matrix table from sql server is : " + ex.ToString()); } finally { sCon.Close(); } return(dt); }
public static Dictionary <string, string> GetCompatibilityMatrix(string productName) { Dictionary <string, string> cMatrix = new Dictionary <string, string>(); SqlConnection sCon = new SqlConnection(); try { sCon = SqlServer.GetConnection(); using (sCon) { SqlCommand command = new SqlCommand( "SELECT * from Compatibility where Product='" + productName + "';", sCon); sCon.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { for (int i = 0; i < reader.FieldCount; i++) { cMatrix.Add(reader.GetName(i), reader.GetValue(i).ToString()); } } } } catch (Exception ex) { LoggerUtil.LogMessageToFile("Exception caught while Getting the compatibility matrix for product '" + productName + "' from sql server is : " + ex.ToString()); sCon.Close(); throw new Exception("Server Connection Error"); } finally { sCon.Close(); } return(cMatrix); }
public static string GetAbsoluteTestName(string testName, string dllLocation) { Assembly assembly = Assembly.UnsafeLoadFrom(dllLocation); string testcaseFullName = null; Type[] types; try { types = assembly.GetTypes(); } catch (ReflectionTypeLoadException ex) { types = ex.Types.Where(t => t != null).ToArray <Type>(); } foreach (Type className in types) { var methods = className.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.InvokeMethod); try { testcaseFullName = className + "." + methods.Single(x => x.Name == testName).Name; if (testcaseFullName != null) { break; } } catch (Exception ex) { LoggerUtil.LogMessageToFile(ex.ToString()); testcaseFullName = ""; } } return(testcaseFullName); }
public static void Run(string dllName, string dllLocation, string category, string module, List <string> testCase) { LogMessageToFile("Killing MsTest.exe"); KillMsTest(); string path = ConfigurationManager.AppSettings["TestRunBatchFileLocation"] + "test" + DateTime.Now.ToString("hhmmss") + ".bat"; var contentBuilder = new StringBuilder(); string msTestPath = null; LoggerUtil.LogMessageToFile("Finding MSTest.exe on the system"); if (!File.Exists(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe")) { string[] msTestPaths = null; try { string temp = CommandUtils.GetMsTestPath().Split(new string[] { "Directory of" }, System.StringSplitOptions.None)[1]; LogMessageToFile("Split result of mstest path is : " + temp); msTestPaths = temp.Split(new string[] { @"\IDE" }, System.StringSplitOptions.None); msTestPath = msTestPaths[0].Trim() + @"\IDE\"; LogMessageToFile("MsTestPath found using enumeration is File is " + msTestPath); } catch (Exception ex) { LogMessageToFile("Exception caught at finding MSTest.exe path is : " + ex.ToString()); } finally { if (msTestPath == null) { LogMessageToFile("Throwing Custom Exception for mstestpath to be null."); throw new CustomException("Please Install Test Agent or Visual Studio to run test cases."); } } } else { msTestPath = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\"; } LoggerUtil.LogMessageToFile("The MSTest executable path is : " + msTestPath); contentBuilder.AppendLine(@"cd " + msTestPath); contentBuilder.Append(@"MSTest.exe /testcontainer:"""); string otLoc = OTGen.CreateOrderedTest(testCase, dllName, dllLocation, ConfigurationManager.AppSettings["XmlSchema"], ConfigurationManager.AppSettings["MSType"], dllLocation.Substring(0, dllLocation.LastIndexOf('\\'))); contentBuilder.Append(otLoc + "\""); contentBuilder.Append(" /testsettings:\""); string settingFilePath = @"C:\Automation\Automation.testsettings"; string loc = CreateNewTestResultpath(ConfigurationManager.AppSettings["TrxFileLocation"]).ToString(); contentBuilder.Append(settingFilePath + "\""); contentBuilder.Append(" /resultsfile:\""); contentBuilder.Append(loc + "\""); LogBatFileOutput(contentBuilder, path); CommandUtils.DeleteTestBatFiles(); using (var writer = new StreamWriter(path)) { writer.WriteLine(contentBuilder.ToString()); writer.Close(); } var start = new ProcessStartInfo { FileName = path, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; DateTime dt = DateTime.Now; using (Process process = Process.Start(start)) { if (process != null) { System.Threading.Thread.Sleep(2000); dt = DateTime.Now; LogMessageToFile("MSTest triggered without waiting for the process"); } } }
public static void UpdateResults(string productName, string productBuildNumber, string testBuildNumber, DateTime starttime, DateTime endtime) { string source = ConfigurationManager.AppSettings["TrxFileLocation"]; LogMessageToFile("The source path for GetShortResults is : " + source); source = GetLatestResultspath(source); if (!File.Exists(source)) { } else { LogMessageToFile("Trying to load the source"); XDocument xDoc = XDocument.Load(source); LogMessageToFile("Source loaded"); XNamespace defaultNs = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"; var dataHashtable = new Hashtable(); var testRunNode = (from data in xDoc.Descendants(defaultNs + "TestRun") select data).ToList(); var masterRecordSet1 = (from src in testRunNode select new { testRunId = src.Attribute("id").Value, testRunName = src.Attribute("name").Value, testRunUser = src.Attribute("runUser").Value }); foreach (var record in masterRecordSet1) { dataHashtable.Add("ID", record.testRunId); dataHashtable.Add("FMASTRUNID", record.testRunName); dataHashtable.Add("FRUNUSER", record.testRunUser); } var resultSummaryNode = (from data in xDoc.Descendants(defaultNs + "ResultSummary") select data).ToList(); var resultSummaryRecordSet1 = (from src in resultSummaryNode select new { outcome = src.Attribute("outcome").Value }); foreach (var record in resultSummaryRecordSet1) { dataHashtable.Add("FOUTCOME", record.outcome); } resultSummaryNode = (from data in xDoc.Descendants(defaultNs + "ResultSummary") select data).Descendants(defaultNs + "Counters").ToList(); var resultSummaryRecordSet2 = (from src in resultSummaryNode select new { totalTestCases = src.Attribute("total").Value, totalTestCasesExecuted = src.Attribute("executed").Value, totalTestCasesPassed = src.Attribute("passed").Value, totalTestCasesError = src.Attribute("error").Value, totalTestCasesFailed = src.Attribute("failed").Value, totalTestCasesTimeout = src.Attribute("timeout").Value, totalTestCasesAborted = src.Attribute("aborted").Value, totalTestCasesInconclusive = src.Attribute("inconclusive").Value }); foreach (var record in resultSummaryRecordSet2) { dataHashtable.Add("FTCTOTAL", record.totalTestCases); dataHashtable.Add("FTCEXECUTED", record.totalTestCasesExecuted); dataHashtable.Add("FTCPASSED", record.totalTestCasesPassed); dataHashtable.Add("FTCERROR", record.totalTestCasesError); dataHashtable.Add("FTCFAILED", record.totalTestCasesFailed); dataHashtable.Add("FTCTIMEOUT", record.totalTestCasesTimeout); dataHashtable.Add("FTCABORTED", record.totalTestCasesAborted); dataHashtable.Add("FTCINCONCLUSIVE", record.totalTestCasesInconclusive); } using (var connection = SqlServer.GetConnection()) { connection.Open(); var command = connection.CreateCommand(); double roiFactor = ProductConfiguration.GetProductRoiFactor(productName); var roi = Convert.ToDouble(dataHashtable["FTCPASSED"]) * roiFactor; command.CommandText = "INSERT INTO rsmast (fMasterRunId, fProductName, fProductBuildNumber, fTestBuildNumber, fOutCome, fRunBy, fStartTime, fEndTime, ftcTotal, ftcExecuted, ftcPassed, ftcFailed, ftcTimeout, ftcAborted, ftcError, ftcInconclusive, ftcUrl, ftcbrowser, ftcExePath, fRoi)" + "VALUES ('" + dataHashtable["FMASTRUNID"] + "','" + productName + "','" + productBuildNumber + "','" + testBuildNumber + "','" + dataHashtable["FOUTCOME"] + "','" + dataHashtable["FRUNUSER"] + "','" + starttime + "','" + endtime + "','" + dataHashtable["FTCTOTAL"] + "','" + dataHashtable["FTCEXECUTED"] + "','" + dataHashtable["FTCPASSED"] + "','" + dataHashtable["FTCFAILED"] + "','" + dataHashtable["FTCTIMEOUT"] + "','" + dataHashtable["FTCABORTED"] + "','" + dataHashtable["FTCERROR"] + "','" + dataHashtable["FTCINCONCLUSIVE"] + "','" + "url" + "','" + "browser" + "','" + "exepath" + "','" + roi + "');"; try { command.ExecuteNonQuery(); connection.Close(); LogMessageToFile("Updating results to SQL was successfully completed."); } catch (Exception ex) { LogMessageToFile("Exception caught while updating results to SQL Server is : " + ex.ToString()); throw new Exception("failed to update rsmast table"); } } var detailedTestRunNode = (from data in xDoc.Descendants(defaultNs + "Results") select data).Descendants(defaultNs + "UnitTestResult").ToList(); var detailedTestrecordSet1 = (from src in detailedTestRunNode select new { TestRunID = src.Attribute("testId").Value, testcaseRunId = src.Attribute("testId").Value, TestName = src.Attribute("testName").Value, TestOutcome = src.Attribute("outcome").Value, EnvirnomentName = src.Attribute("computerName").Value, //Duration = src.Attribute("duration").Value, StartTime = src.Attribute("startTime").Value, EndTime = src.Attribute("endTime").Value, Message = src .Descendants(defaultNs + "Output") .Descendants(defaultNs + "ErrorInfo") .Descendants(defaultNs + "Message"), StackTrace = src .Descendants(defaultNs + "Output") .Descendants(defaultNs + "ErrorInfo") .Descendants(defaultNs + "StackTrace") }); foreach (var record in detailedTestrecordSet1) { using (var connection = SqlServer.GetConnection()) { connection.Open(); var command0 = connection.CreateCommand(); command0.CommandText = "select fOutCome from rsitem where fMasterRunId='" + dataHashtable["FMASTRUNID"] + "' and fTestRunId='" + record.TestRunID + "'"; string result = null; try { result = command0.ExecuteScalar().ToString(); } catch (NullReferenceException) { var command1 = connection.CreateCommand(); command1.CommandText = "INSERT INTO rsitem (fMasterRunId, fTestRunId, fOutCome)" + "VALUES ('" + dataHashtable["FMASTRUNID"] + "','" + record.TestRunID + "','" + record.TestOutcome + "');"; try { command1.ExecuteNonQuery(); } catch (Exception) { throw new Exception("Failed to update rsitem table"); } } if (result != null && (result.ToUpper() != "Failed".ToUpper() && record.TestOutcome.ToUpper() == "Failed".ToUpper())) { var command2 = connection.CreateCommand(); command2.CommandText = "update rsitem set fOutCome = 'Failed' where fMasterRunId='" + dataHashtable["FMASTRUNID"] + "' and fTestRunId='" + record.TestRunID + "'"; } var command3 = connection.CreateCommand(); command3.CommandText = "update rsmast set fMachineName = '" + record.EnvirnomentName + "' where fMasterRunId='" + dataHashtable["FMASTRUNID"] + "'"; try { command3.ExecuteNonQuery(); } catch (Exception) { throw new Exception("Failed to update fMachineName in rsmast table"); } var duration = Convert.ToDateTime(record.EndTime) - Convert.ToDateTime(record.StartTime); var command = connection.CreateCommand(); command.CommandText = "INSERT INTO rsdetailtestview (fMasterRunId, fTestRunId, ftcName, ftcComputerName, ftcDuration, ftcStartTime, ftcEndTime, ftcOutcome, ftcDebugTrace, ftcStackTrace)" + "VALUES ('" + dataHashtable["FMASTRUNID"] + "','" + record.TestRunID + "','" + record.TestName + "','" + record.EnvirnomentName + "','" + duration.TotalMinutes + "','" + record.StartTime + "','" + record.EndTime + "','" + record.TestOutcome + "','" + record.Message + "','" + record.StackTrace + "');"; try { command.ExecuteNonQuery(); LogMessageToFile("Updating results to SQL was successfully completed."); } catch (Exception ex) { LogMessageToFile("Exception caught while updating results to SQL Server is : " + ex.ToString()); throw new Exception("Failed to update rsdetailtestview table"); } connection.Close(); } } LogMessageToFile("Updating Splog"); SplogUtils spUtils = new SplogUtils(); spUtils.splogPathLocal = LoggerUtil.GetTempPath(); spUtils.splogfileName = productName + "_" + dataHashtable["FMASTRUNID"].ToString().Replace("-", "_").Replace(":", "_") + ".splog"; LogMessageToFile("Splog file name is : " + spUtils.splogfileName); spUtils.CreateXMLFile(productName, testBuildNumber); LogMessageToFile("Created Splog file"); spUtils.Generate(dataHashtable, productName, productBuildNumber, testBuildNumber, "", ""); LogMessageToFile("Generated splog for the current run"); spUtils.ReportToSplunk(productName, testBuildNumber); } }
public static void RunDirectCall(string dllName, string dllLocation, string category, string module, List <string> testCase) { KillMsTest(); string path = ConfigurationManager.AppSettings["TestRunBatchFileLocation"] + "test" + DateTime.Now.ToString("hhmmss") + ".bat"; var contentBuilder = new StringBuilder(); string msTestPath = null; LoggerUtil.LogMessageToFile("Finding MSTest.exe on the system"); if (!File.Exists(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe")) { string[] msTestPaths = null; try { msTestPaths = CommandUtils.GetMsTestPath().Split(new string[] { "Directory of" }, System.StringSplitOptions.None)[1].Split(new string[] { "IDE" }, System.StringSplitOptions.None); } catch (Exception ex) { LogMessageToFile("Exception caught at finding MSTest.exe path is : " + ex.ToString()); } finally { if (msTestPath == null || !msTestPath.Contains("Visual Studio")) { throw new CustomException("Please Install Test Agent or Visual Studio to run test cases."); } msTestPath = msTestPaths[0].Trim() + @"IDE\"; } } else { msTestPath = @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\"; } contentBuilder.AppendLine(@"cd " + msTestPath); contentBuilder.Append(@"MSTest.exe /testcontainer:"""); string otLoc = OTGen.CreateOrderedTest(testCase, dllName, dllLocation, ConfigurationManager.AppSettings["XmlSchema"], ConfigurationManager.AppSettings["MSType"], dllLocation.Substring(0, dllLocation.LastIndexOf('\\'))); contentBuilder.Append(otLoc + "\""); //if (module == "All") //{ //} //else //{ // if (testCase == "All") // { // contentBuilder.Append(" /category:"); // contentBuilder.Append("\"" + module + "\""); // } // else // { // contentBuilder.Append(" /test:"); // contentBuilder.Append(testCase); // } //} contentBuilder.Append(" /testsettings:\""); string settingFilePath = @"C:\Automation\Automation.testsettings"; string loc = CreateNewTestResultpath(ConfigurationManager.AppSettings["TrxFileLocation"]).ToString(); contentBuilder.Append(settingFilePath + "\""); //string tempLoc = loc.ToString().Replace("Results.trx", ""); //string destFilePath = tempLoc + "Automation.testsettings"; //contentBuilder.Append("Automation.testsettings"+"\""); //File.Copy(settingFilePath, destFilePath); contentBuilder.Append(" /resultsfile:\""); //checkin comment contentBuilder.Append(loc + "\""); contentBuilder.AppendLine(" "); //contentBuilder.AppendLine("taskkill /F /IM CdcSmartClientContainer.exe /T"); contentBuilder.AppendLine("exit"); LogBatFileOutput(contentBuilder, path); CommandUtils.DeleteTestBatFiles(); using (var writer = new StreamWriter(path)) { writer.WriteLine(contentBuilder.ToString()); writer.Close(); } var start = new ProcessStartInfo { FileName = path, UseShellExecute = false, RedirectStandardOutput = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; using (Process process = Process.Start(start)) { LogMessageToFile("MSTest triggered without waiting for the process"); //if (process != null) //{ // //using (StreamReader reader = process.StandardOutput) // //{ // // string result = reader.ReadToEnd(); // // LogMessageToFile(result); // //} // process.WaitForExit(); //} } }
public static string ComparisonLogic(string pName) { string msg = null; string chVersion = null; string ffVersion = null; string ieVersion = null; try { string ieCompatibility = null; string ffCompatibility = null; string chCompatibility = null; Dictionary <string, string> matrix = Query.GetCompatibilityMatrix(pName); if (matrix.Count() != 0) { string ieReq = matrix["IE_Version"].Trim(); List <string> ieList = new List <string>(); if (ieReq.ToUpper() != "NA" || ieReq != null) { if (ieReq.Contains(',')) { string[] strArr = ieReq.Split(','); foreach (string str in strArr) { ieList.Add(str.Split('.')[0].Trim()); } } } string ffReq = matrix["Firefox_Version"].Trim(); List <string> ffList = new List <string>(); if (ffReq.ToUpper() != "NA" || ffReq != null) { if (ffReq.Contains(',')) { string[] strArr = ffReq.Split(','); foreach (string str in strArr) { ffList.Add(str.Split('.')[0].Trim()); } } } string chReq = matrix["Chrome_version"].Trim(); List <string> chList = new List <string>(); if (chReq.ToUpper() != "NA" || chReq != null) { if (chReq.Contains(',')) { string[] strArr = chReq.Split(','); foreach (string str in strArr) { chList.Add(str.Split('.')[0].Trim()); } } } try { ieVersion = GetIEVersion().Split('.')[0]; //Comparison for IE if (ieReq.Contains(',')) { if (ieList.Where(x => x.Contains(ieVersion)).Count() >= 1) { ieCompatibility = "Compatible"; } else { ieCompatibility = "May Not Be Compatible"; } } else if (ieReq.ToUpper() == "NA") { ieCompatibility = "May Not Be Compatible"; } else { if (ieReq.Split('.')[0].Contains(ieVersion)) { ieCompatibility = "Compatible"; } else { ieCompatibility = "May Not Be Compatible"; } } } catch (Exception ex) { LoggerUtil.LogMessageToFile("Exception caught while comparing IE Version is : " + ex.ToString()); ffCompatibility = "Not Installed"; } try { ffVersion = GetFirefoxVersion().Split('.')[0]; //Comparison for Firefox if (ffReq.Contains(',')) { if (ffList.Where(x => Convert.ToInt32(ffVersion) <= Convert.ToInt32(x.Split('.')[0])).Count() >= 1) { ffCompatibility = "Compatible"; } else { ffCompatibility = "May Not Be Compatible"; } } else if (ffReq.ToUpper() == "NA") { ffCompatibility = "May Not Be Compatible"; } else { if (Convert.ToInt32(ffVersion) <= Convert.ToInt32(ffReq.Split('.')[0])) { ffCompatibility = "Compatible"; } else { ffCompatibility = "May Not Be Compatible"; } } } catch (Exception ex) { LoggerUtil.LogMessageToFile("Exception caught while comparing FF Version is : " + ex.ToString()); ffCompatibility = "Not Installed"; } try { chVersion = GetChromeVersion().Split('.')[0]; //Comparison for Chrome if (chReq.Contains(',')) { if (chList.Where(x => Convert.ToInt32(chVersion) <= Convert.ToInt32(x.Split('.')[0])).Count() >= 1) { chCompatibility = "Compatible"; } else { chCompatibility = "May Not Be Compatible"; } } else if (chReq.ToUpper() == "NA") { chCompatibility = "May Not Be Compatible"; } else { if (Convert.ToInt32(chVersion) <= Convert.ToInt32(chReq.Split('.')[0])) { chCompatibility = "Compatible"; } else { chCompatibility = "May Not Be Compatible"; } } } catch (Exception ex) { LoggerUtil.LogMessageToFile("Exception caught while comparing Chrome Version is : " + ex.ToString()); chCompatibility = "Not Installed"; } msg = "IE - " + " Installed = " + ieVersion + " Required = " + ieReq + " Compatibility = " + ieCompatibility + "\r\n" + "FF - " + " Installed = " + ffVersion + " Required = " + ffReq + " Compatibility = " + ffCompatibility + "\r\n" + "CR - " + " Installed = " + chVersion + " Required = " + chReq + " Compatibility = " + chCompatibility + "\r\n" + "Please Ensure the browsers are compatible for running Test Cases."; } } catch (Exception ex) { LoggerUtil.LogMessageToFile("Exception caught while computing compatibility is : " + ex.ToString()); } return(msg); }