/// <summary> /// This method is used to initiate execution in test manager, create test run and results and set required parameters /// </summary> /// <returns></returns> public static void InitTestCaseExecution() { //Send instructions to individual test managers for initialization of execution //Current implementation only for Visual Studio test manager, should be extended to others also try { switch (Property.ManagerType.ToLower()) { case "mstestmanager": TestManager msTestManager = new TestManager(); msTestManager.InitExecution(); break; } } catch (Exception e) { throw e; } }
/// <summary> /// This method will set the path of the the test case, test data & object repository files /// according to the test manager (FileSystem, QC, XStudio etc.) used by the Krypton. /// </summary> public static void SetTestFilesLocation(string managerType, string testCasefilename = null) { _strManagerType = managerType; char strSeprator = char.Parse(Property.TestCaseIdSeperator); switch (_strManagerType.ToLower()) { //For file system, it will get the test files paths from property.cs case "filesystem": if (IsTestSuite) { _testCaseFilePath = Path.GetFullPath(Property.TestCaseFilepath + "/" + _strTestCaseId + Property.ExcelSheetExtension); } else { if (string.IsNullOrWhiteSpace(testCasefilename)) { _testCaseFilePath = Path.GetFullPath(Property.TestCaseFilepath + "/" + _strTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension); } else { _testCaseFilePath = Path.GetFullPath(Property.TestCaseFilepath + "/" + testCasefilename); } } if (string.IsNullOrWhiteSpace(testCasefilename)) { _testDataFilePath = Path.GetFullPath(Property.TestDataFilepath + "/" + "TD_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension); //New } else { _testDataFilePath = Path.GetFullPath(Property.TestDataFilepath + "/" + "TD_" + testCasefilename); } if (string.IsNullOrWhiteSpace(testCasefilename)) { _dbTestDataFilePath = Path.GetFullPath(Property.DBTestDataFilepath + "/" + "DB_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension); } else { _dbTestDataFilePath = Path.GetFullPath(Property.DBTestDataFilepath + "/" + "DB_" + testCasefilename); } _objectRepositoryFilePath = Path.GetFullPath(Property.ObjectRepositoryFilepath + "/" + Property.ObjectRepositoryFilename); _recoverFromPopupFilePath = Path.GetFullPath(Property.RecoverFromPopupFilepath + "/" + Property.RecoverFromPopupFilename); _recoverFromBrowserFilePath = Path.GetFullPath(Property.RecoverFromBrowserFilePath + "/" + Property.RecoverFromBrowserFilename); break; //for QC, it will get the test files paths from the TMQC module. case "qc": TestManager objExtManager = new TestManager(); //Call DownloadAttachment from TMQC TestManager class to get the path of test files. if (IsTestSuite) { _testCaseFilePath = objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], _strTestCaseId + Property.ExcelSheetExtension); } else { _testCaseFilePath = string.IsNullOrWhiteSpace(testCasefilename) ? objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Regex.Split(_strTestCaseId, Property.TestCaseIdSeperator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension) : objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], testCasefilename); } _testDataFilePath = string.IsNullOrWhiteSpace(testCasefilename) ? objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Regex.Split(_strTestCaseId, Property.TestCaseIdSeperator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension) : objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], testCasefilename); _dbTestDataFilePath = objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Regex.Split(_strTestCaseId, Property.TestCaseIdSeperator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension); _objectRepositoryFilePath = objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Property.ObjectRepositoryFilename); _recoverFromPopupFilePath = Property.RecoverFromPopupFilepath + "/" + Property.RecoverFromPopupFilename; _recoverFromBrowserFilePath = Property.RecoverFromBrowserFilePath + "/" + Property.RecoverFromBrowserFilename; break; case "mstestmanager": // Not Functional yet. if (IsTestSuite) { _testCaseFilePath = Property.TestCaseFilepath + "/" + _strTestCaseId + Property.ExcelSheetExtension; } else { if (string.IsNullOrWhiteSpace(testCasefilename)) { _testCaseFilePath = Property.TestCaseFilepath + "/" + _strTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension; } else { _testCaseFilePath = Property.TestCaseFilepath + "/" + testCasefilename; } } if (string.IsNullOrWhiteSpace(testCasefilename)) { _testDataFilePath = Property.TestDataFilepath + "/" + "TD_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension; } else { _testDataFilePath = Property.TestDataFilepath + "/" + "TD_" + testCasefilename; } _dbTestDataFilePath = Property.DBTestDataFilepath + "/" + "DB_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension; _objectRepositoryFilePath = Property.ObjectRepositoryFilepath + "/" + Property.ObjectRepositoryFilename; _recoverFromPopupFilePath = Property.RecoverFromPopupFilepath + "/" + Property.RecoverFromPopupFilename; _recoverFromBrowserFilePath = Property.RecoverFromBrowserFilePath + "/" + Property.RecoverFromBrowserFilename; break; } }
/// <summary> /// This method will set the path of the the test case, test data & object repository files /// according to the test manager (FileSystem, QC, XStudio etc.) used by the Krypton. /// </summary> public static void SetTestFilesLocation(string managerType, string testCasefilename = null) { _strManagerType = managerType; char strSeprator = char.Parse(Property.TestCaseIdSeperator); switch (_strManagerType.ToLower()) { //For file system, it will get the test files paths from property.cs case "filesystem": if (IsTestSuite) { _testCaseFilePath =Path.GetFullPath( Property.TestCaseFilepath + "/" + _strTestCaseId + Property.ExcelSheetExtension); } else { if (string.IsNullOrWhiteSpace(testCasefilename)) _testCaseFilePath = Path.GetFullPath(Property.TestCaseFilepath + "/" + _strTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension); else _testCaseFilePath = Path.GetFullPath(Property.TestCaseFilepath + "/" + testCasefilename); } if (string.IsNullOrWhiteSpace(testCasefilename)) _testDataFilePath = Path.GetFullPath(Property.TestDataFilepath + "/" + "TD_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension);//New else { _testDataFilePath = Path.GetFullPath(Property.TestDataFilepath + "/" + "TD_" + testCasefilename); } if (string.IsNullOrWhiteSpace(testCasefilename)) { _dbTestDataFilePath = Path.GetFullPath(Property.DBTestDataFilepath + "/" + "DB_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension); } else { _dbTestDataFilePath = Path.GetFullPath(Property.DBTestDataFilepath + "/" + "DB_" + testCasefilename); } _objectRepositoryFilePath = Path.GetFullPath(Property.ObjectRepositoryFilepath + "/" + Property.ObjectRepositoryFilename); _recoverFromPopupFilePath = Path.GetFullPath( Property.RecoverFromPopupFilepath + "/" + Property.RecoverFromPopupFilename); _recoverFromBrowserFilePath = Path.GetFullPath(Property.RecoverFromBrowserFilePath + "/" + Property.RecoverFromBrowserFilename); break; //for QC, it will get the test files paths from the TMQC module. case "qc": TestManager objExtManager = new TestManager(); //Call DownloadAttachment from TMQC TestManager class to get the path of test files. if (IsTestSuite) { _testCaseFilePath = objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], _strTestCaseId + Property.ExcelSheetExtension); } else { _testCaseFilePath = string.IsNullOrWhiteSpace(testCasefilename) ? objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Regex.Split(_strTestCaseId, Property.TestCaseIdSeperator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension) : objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], testCasefilename); } _testDataFilePath = string.IsNullOrWhiteSpace(testCasefilename) ? objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Regex.Split(_strTestCaseId, Property.TestCaseIdSeperator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension) : objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], testCasefilename); _dbTestDataFilePath = objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Regex.Split(_strTestCaseId, Property.TestCaseIdSeperator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension); _objectRepositoryFilePath = objExtManager.DownloadAttachment(Property.Parameterdic["qcfolder"], Property.ObjectRepositoryFilename); _recoverFromPopupFilePath = Property.RecoverFromPopupFilepath + "/" + Property.RecoverFromPopupFilename; _recoverFromBrowserFilePath = Property.RecoverFromBrowserFilePath + "/" + Property.RecoverFromBrowserFilename; break; case "mstestmanager": // Not Functional yet. if (IsTestSuite) { _testCaseFilePath = Property.TestCaseFilepath + "/" + _strTestCaseId + Property.ExcelSheetExtension; } else { if (string.IsNullOrWhiteSpace(testCasefilename)) _testCaseFilePath = Property.TestCaseFilepath + "/" + _strTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension; else _testCaseFilePath = Property.TestCaseFilepath + "/" + testCasefilename; } if (string.IsNullOrWhiteSpace(testCasefilename)) _testDataFilePath = Property.TestDataFilepath + "/" + "TD_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension; else { _testDataFilePath = Property.TestDataFilepath + "/" + "TD_" + testCasefilename; } _dbTestDataFilePath = Property.DBTestDataFilepath + "/" + "DB_" + _newTestCaseId.Split(strSeprator)[Property.TestCaseIdParameter] + Property.ExcelSheetExtension; _objectRepositoryFilePath = Property.ObjectRepositoryFilepath + "/" + Property.ObjectRepositoryFilename; _recoverFromPopupFilePath = Property.RecoverFromPopupFilepath + "/" + Property.RecoverFromPopupFilename; _recoverFromBrowserFilePath = Property.RecoverFromBrowserFilePath + "/" + Property.RecoverFromBrowserFilename; break; } }
/// <summary> /// This method will copy report files from a temporary location used by Reporting module /// to a given location that can be used by the QC or XStudio or similar test management modules. It also /// generates a text file containing all result files' path for XStudio. /// Source and destination paths will be fetched from the Property.cs file. /// </summary> /// <returns>True on success else False</returns> public static bool UploadTestExecutionResults(List <string> inputTestIds = null) { bool res; try { _strResultsSource = new DirectoryInfo(Property.ResultsSourcePath).Parent; _strResultsDestination = new DirectoryInfo(Property.ResultsDestinationPath); // Copy all result files from source directory to destination directory. res = CopyAll(_strResultsSource, _strResultsDestination); // Create a temporary file to make sure that the copy process has been completed. bool resFinished = true; if (_strResultsDestination.Parent != null) { StreamWriter sw = new StreamWriter(_strResultsDestination.Parent.FullName + "/ResultCopyCompleted.txt"); sw.WriteLine("Key: Copy Process Completed!"); sw.Close(); } var directoryInfo = new DirectoryInfo(Property.ResultsSourcePath).Parent; if (directoryInfo != null) { DirectoryInfo drParent = directoryInfo.Parent; //to check if user wants to keep report history string fileExt = string.Empty; if (_strResultsDestination.Name.LastIndexOf('-') >= 0 && Utility.GetParameter("KeepReportHistory").Equals("true", StringComparison.OrdinalIgnoreCase) == true) { fileExt = _strResultsDestination.Name.Substring(_strResultsDestination.Name.LastIndexOf('-'), _strResultsDestination.Name.Length - _strResultsDestination.Name.LastIndexOf('-')); } string rcProcessId = string.Empty; if (!string.IsNullOrWhiteSpace(Property.RcProcessId)) { rcProcessId = "-" + Property.RcProcessId; //Adding process id for Remote execution } if (drParent != null) { foreach (FileInfo fi in drParent.GetFiles()) { if (fi.Name.IndexOf("HtmlReport", StringComparison.OrdinalIgnoreCase) >= 0 || fi.Name.IndexOf("logo", StringComparison.OrdinalIgnoreCase) >= 0 || fi.Name.IndexOf(Property.ReportZipFileName, StringComparison.OrdinalIgnoreCase) >= 0 || fi.Name.IndexOf("." + Property.ScriptLanguage, StringComparison.OrdinalIgnoreCase) >= 0) { if (fi.Name.IndexOf("mail.html", StringComparison.OrdinalIgnoreCase) >= 0) // no need to copy this file to krypton result folder while sending mail through krypton { continue; } string fileName; if (fi.Name.IndexOf("logo", StringComparison.OrdinalIgnoreCase) >= 0) { fileName = fi.Name; } else if (fi.Name.IndexOf("HtmlReport", StringComparison.OrdinalIgnoreCase) >= 0) { string htmlFileExt; if (!string.IsNullOrWhiteSpace(Utility.GetParameter("TestSuite"))) { htmlFileExt = Utility.GetParameter("TestSuite"); } else { string[] testCaseIds = Utility.GetParameter("TestCaseId").Split(','); if (testCaseIds.Length > 1) { htmlFileExt = testCaseIds[0] + "...multiple"; } else { htmlFileExt = Utility.GetParameter("TestCaseId"); } } htmlFileExt = htmlFileExt + rcProcessId; if (fi.Name.IndexOf("HtmlReports", StringComparison.OrdinalIgnoreCase) >= 0) { fileName = fi.Name.Substring(0, fi.Name.LastIndexOf('.')) + "-" + htmlFileExt + fileExt + "s" + fi.Name.Substring(fi.Name.LastIndexOf('.'), fi.Name.Length - fi.Name.LastIndexOf('.')); } else { fileName = fi.Name.Substring(0, fi.Name.LastIndexOf('.')) + "-" + htmlFileExt + fileExt + fi.Name.Substring(fi.Name.LastIndexOf('.'), fi.Name.Length - fi.Name.LastIndexOf('.')); } } else { fileName = fi.Name.Substring(0, fi.Name.LastIndexOf('.')) + fileExt + fi.Name.Substring(fi.Name.LastIndexOf('.'), fi.Name.Length - fi.Name.LastIndexOf('.')); } if (_strResultsDestination.Parent != null) { fi.CopyTo(_strResultsDestination.Parent.FullName + "/" + fileName, true); //if user wants to keep report history, folder name will be different, so need to change links in the html file also if (string.IsNullOrWhiteSpace(fileExt) == false && fi.Name.Contains("HtmlReport")) { string htmlStr = File.ReadAllText(_strResultsDestination.Parent.FullName + "/" + fileName, Encoding.UTF8); string testCaseId = string.Empty; //Handle Test Case Id conditions #region check for test suite string testSuite = Utility.GetParameter("TestSuite"); if (!string.IsNullOrWhiteSpace(testSuite.Trim()) && string.IsNullOrWhiteSpace(Utility.GetParameter("TestCaseId").Trim())) { SetTestFilesLocation(Property.ManagerType); // get ManagerType from property.cs Manager objTestManagerSuite = new Manager(testSuite); var testSuiteData = objTestManagerSuite.GetTestCaseXml(Property.TestQuery, false, false); for (int testCaseCnt = 0; testCaseCnt < testSuiteData.Tables[0].Rows.Count; testCaseCnt++) { if (!string.IsNullOrWhiteSpace(testSuiteData.Tables[0].Rows[testCaseCnt][KryptonConstants.TEST_CASE_ID].ToString().Trim())) { if (string.IsNullOrWhiteSpace(testCaseId)) { testCaseId = testSuiteData.Tables[0].Rows[testCaseCnt][KryptonConstants.TEST_CASE_ID].ToString(); } else { testCaseId = testCaseId + "," + testSuiteData.Tables[0].Rows[testCaseCnt][KryptonConstants.TEST_CASE_ID]; } } } } else { testCaseId = Utility.GetParameter("TestCaseId");//override testcaseid parameter over test suite } #endregion var testCases = inputTestIds != null?inputTestIds.ToArray() : testCaseId.Split(','); string[] testCasesIds = new string[testCases.Length]; int k = 0; foreach (string testCase in testCases) { if (string.Join(";", testCasesIds).Contains(testCase + ";") == false) { testCasesIds[k] = testCase; htmlStr = htmlStr.Replace("href='" + testCase + "\\", "href='" + testCase + rcProcessId + fileExt + "\\"); k++; } } File.WriteAllText(_strResultsDestination.Parent.FullName + "/" + fileName, htmlStr, Encoding.UTF8); } } } } } } int resCheckLimit = 0; do { if (_strResultsDestination.Parent != null && File.Exists(_strResultsDestination.Parent.FullName + "/ResultCopyCompleted.txt")) { File.Delete(_strResultsDestination.Parent.FullName + "/ResultCopyCompleted.txt"); resFinished = false; } else { if (resCheckLimit++ < 6) { Thread.Sleep(5000); } else { resFinished = false; } } }while (resFinished); } catch (Exception exception) { throw new KryptonException("error", exception.Message); } var fileUploadPath = Property.ResultsDestinationPath + "/" + (new DirectoryInfo(Property.ResultsSourcePath).Name); // Extra actions are performed for particular test manager. switch (_strManagerType.ToLower()) { case "qc": // Not Functional yet break; case "xstudio": // XStudio requires a trigger that tells about the end of the execution. // Generation of test_completed.txt file will notify XStudio. TestManager.UploadTestResults(_resultFilesList, fileUploadPath); break; case "mstestmanager": // Not Functional yet TestManager.UploadTestResults(Property.FinalXmlPath, Property.FinalExecutionStatus); break; } return(res); }