public static Hashtable GetMyLastRunResults(string machineName) { using ( var connection = SqlServer.GetConnection()) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = "select fMasterRunId from rsmast where fStartTime = (select MAX(fStartTime) from rsmast where fmachinename = '" + machineName + "')"; string masterrunid; try { masterrunid = command.ExecuteScalar().ToString(); } catch (Exception exception) { throw new ArgumentException("Invalid User", exception); } var totalTestcasecommand = connection.CreateCommand(); totalTestcasecommand.CommandText = "Select COUNT(fOutCome) from rsitem where fMasterRunId='" + masterrunid + "'"; var passedTestcasecommand = connection.CreateCommand(); passedTestcasecommand.CommandText = "Select COUNT(fOutCome) from rsitem where fMasterRunId='" + masterrunid + "' and fOutCome='Passed'"; var failedTestcasecommand = connection.CreateCommand(); failedTestcasecommand.CommandText = "Select COUNT(fOutCome) from rsitem where fMasterRunId='" + masterrunid + "' and fOutCome='Failed'"; var roicommand = connection.CreateCommand(); roicommand.CommandText = "Select fRoi from rsmast where fMasterRunId='" + masterrunid + "'"; var dataHashtable = new Hashtable(); try { var totaltestcase = totalTestcasecommand.ExecuteScalar().ToString(); var passedtestcase = passedTestcasecommand.ExecuteScalar().ToString(); var failedtestcase = failedTestcasecommand.ExecuteScalar().ToString(); var roi = roicommand.ExecuteScalar().ToString(); dataHashtable.Add("TotalTC", totaltestcase); dataHashtable.Add("Passed", passedtestcase); dataHashtable.Add("Failed", failedtestcase); dataHashtable.Add("Roi", roi); } catch (Exception exception) { LoggerUtil.LogMessageToFile("Error encountered while getting the last run results is : " + exception.ToString()); throw new ArgumentException("Invalid User", exception); } finally { connection.Close(); } LoggerUtil.LogMessageToFile("Getting last run results was successful"); return(dataHashtable); } }
public static string GetLastSuccededDropLocation(string projName, string buildDefinitionName) { projName = GetProjectName(projName); var cred = new NetworkCredential("SERVICE_ACCOUNT_NAME", "SERVICE_ACCOUNT_PASSWORD", "SERVICE_ACCOUNT_DOMAIN"); var configurationServerUri = new Uri("TFS_URL_TILL_COLLECTION"); TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(configurationServerUri); CatalogNode configurationServerNode = configurationServer.CatalogNode; // Query the children of the configuration server node for all of the team project collection nodes ReadOnlyCollection <CatalogNode> tpcNodes = configurationServerNode.QueryChildren( new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None); foreach (CatalogNode tpcNode in tpcNodes) { ServiceDefinition tpcServiceDefinition = tpcNode.Resource.ServiceReferences["Location"]; ILocationService configLocationService = configurationServer.GetService <ILocationService>(); Uri tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition)); // Actually connect to the team project collection TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(tpcUri); ITestManagementService tms = tpc.GetService <ITestManagementService>(); ITestManagementTeamProject proj = tms.GetTeamProject(projName); IBuildServer tfsBuildServer = tpc.GetService <IBuildServer>(); // Reading from XML try { IBuildServer buildServer = (IBuildServer)tpc.GetService(typeof(IBuildServer)); //Specify query IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(projName.Trim(), buildDefinitionName.Trim()); spec.InformationTypes = null; // for speed improvement spec.QueryOrder = BuildQueryOrder.FinishTimeAscending; //get the latest build only spec.QueryOptions = QueryOptions.All; IBuildDetail bDetail = buildServer.QueryBuilds(spec).Builds.OrderBy(x => x.CompilationStatus == BuildPhaseStatus.Succeeded).Last(); LatestTestBuild = bDetail.DropLocation; LoggerUtil.LogMessageToFile("The ip resolve"); IPAddress ip = null; string arr2 = LatestTestBuild.Split('\\')[2]; Network.GetResolvedConnecionIPAddress(LatestTestBuild.Split('\\')[2], out ip); string temp = string.Join(@"\", LatestTestBuild.Split('\\').Select(s => s.Replace(arr2, ip.ToString())).ToArray()); LatestTestBuild = temp; LoggerUtil.LogMessageToFile(LatestTestBuild); break; } catch { } } return(LatestTestBuild); }
public static void SendEmailTemplate(string comments, string emailId) { string[] address = new string[] { "<EMAIL_ID>", "<EMAIL_ID>" }; string fullName = null; try { fullName = UserPrincipal.Current.DisplayName; } catch (Exception ex) { LoggerUtil.LogMessageToFile("Issue while fetching Display Name is : " + ex.ToString()); } foreach (string addr in address) { MailMessage msg = new MailMessage(); msg.From = new MailAddress("DLNAME" + "@DOMAIN.com"); if (fullName.Contains(' ')) { msg.CC.Add(fullName.Split(' ')[0] + "." + fullName.Split(' ')[1] + "@DOMAIN.com"); } else if (fullName != null) { msg.CC.Add(fullName + "@DOMAIN.com"); } msg.Bcc.Add(addr); msg.Bcc.Add("<BCC_EMAIL_ID>"); msg.Subject = "Test Mate Issue"; msg.IsBodyHtml = true; msg.BodyEncoding = Encoding.ASCII; msg.Body = "Issue has been reported by the User : "******" On the machine " + Environment.MachineName + "<br>" + "Comment Entered by User is : " + comments + "<br>" + " Environment Details are as follows : " + "<br>" + " OS Version : " + Environment.OSVersion + "<br>" + " UserName : "******"<br>" + " SystemDirectory : " + Environment.SystemDirectory + "<br>" + " TEMP Variable : " + LoggerUtil.GetTempPath() + "<br>" + " PFA the logfile : " + LoggerUtil.GetTempPath() + "."; if (File.Exists(LoggerUtil.GetTempPath() + "TestMateLogFile.txt")) { string logFilePath = LoggerUtil.GetTempPath() + "TestMateLogFile.txt"; msg.Attachments.Add(new Attachment(logFilePath)); } sendMail(msg); System.Threading.Thread.Sleep(2000); } }
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 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); }