/// <summary> /// Using in case of steps in teardown failed, it will take screenshot but store in property: ErrorTearDownScreenshot /// </summary> /// <param name="ex">Exception</param> public static void FailInTearDown(Exception ex) { _runType = TestContext.CurrentContext.Test.Properties.Get("RunType")?.ToString(); switch (_runType.ToUpper()) { case "DEV": GetDevTestCaseInfo(); ObjectId screenShotId = MongoDBHelpers.TakeScreenShotAndUpload(_devRunRecord.TestCaseCodeName); Console.WriteLine($"{DateTime.UtcNow}: {ex.GetType()} - {ex.Message}"); _devRunRecord.Status = TestStatus.Failed.ToString(); _devRunRecord.EndAt = DateTime.UtcNow; _devRunRecord.ExecuteTime = (_devRunRecord.EndAt - _devRunRecord.StartAt).Seconds; _devRunRecord.Log += $"\n{DateTime.UtcNow}: [Failed in teardown] {ex.GetType()} - {ex.Message}"; _devRunRecord.ErrorMessage += $"\n [Failed in teardown]: {_keywordName} - {ex.Message}"; _devRunRecord.ErrorScreenshot = screenShotId.ToString(); MongoDBHelpers.UpdateFailForDevRecord(_devRunRecord); break; case "REGRESSION": GetRegTestCaseInfo(); ObjectId screenShotRegId = MongoDBHelpers.TakeScreenShotAndUpload(_regRunRecord.RegressionTestId); Console.WriteLine($"{DateTime.UtcNow}: {ex.GetType()} - {ex.Message}"); _regRunRecord.Status = TestStatus.Failed.ToString(); _regRunRecord.EndAt = DateTime.UtcNow; _regRunRecord.ExecuteTime = (_regRunRecord.EndAt - _regRunRecord.StartAt).Seconds; _regRunRecord.Log += $"\n{DateTime.UtcNow}: [Failed in teardown] {ex.GetType()} - {ex.Message}"; _regRunRecord.ErrorMessage += $"\n [Failed in teardown]: {ex.GetType()} - {ex.Message}"; _regRunRecord.ErrorScreenshot = screenShotRegId.ToString(); MongoDBHelpers.UpdateFailForRegRecord(_regRunRecord); break; } }
public static string getValueFromBuffer(string sKey) { var result = MongoDBHelpers.getBufferValue(sKey); if (result == null) { throw new KeyNotFoundException($"[getValueFromBuffer] Not found buffer key: {sKey}"); } return(result); }
public static void Pass() { _runType = TestContext.CurrentContext.Test.Properties.Get("RunType")?.ToString(); switch (_runType.ToUpper()) { case "DEV": GetDevTestCaseInfo(); _devRunRecord.EndAt = DateTime.UtcNow; _devRunRecord.ExecuteTime = (_devRunRecord.EndAt - _devRunRecord.StartAt).Seconds; MongoDBHelpers.UpdatePassForDevRecord(_devRunRecord); break; case "REGRESSION": GetRegTestCaseInfo(); _regRunRecord.EndAt = DateTime.UtcNow; _regRunRecord.ExecuteTime = (_regRunRecord.EndAt - _regRunRecord.StartAt).Seconds; MongoDBHelpers.UpdatePassForRegRecord(_regRunRecord); break; } }
public static void Info(string message) { _runType = TestContext.CurrentContext.Test.Properties.Get("RunType")?.ToString(); switch (_runType.ToUpper()) { case "DEV": GetDevTestCaseInfo(); _devRunRecord.Log = $"{DateTime.UtcNow} - [{_keywordName}]: {message}"; Console.WriteLine($"{DateTime.UtcNow} - [{_keywordName}]: {message}"); MongoDBHelpers.AddInfoForDevRecord(_devRunRecord); break; case "REGRESSION": GetRegTestCaseInfo(); // Get call stack _regRunRecord.Log = $"{DateTime.UtcNow} - [{_keywordName}]: {message}"; Console.WriteLine($"{DateTime.UtcNow} - [{_keywordName}]: {message}"); MongoDBHelpers.AddInfoForRegRecord(_regRunRecord); break; } }
public static string processWithBuffer(string param) { if (param == null) { return(null); } string sValue = param; if (Regex.Match(param, @"^@.*@$").Success) { var sKey = param.Substring(1, param.Length - 2); var tempValue = MongoDBHelpers.getBufferValue(sKey); if (tempValue != null) { sValue = tempValue; } else { throw new KeyNotFoundException($"[processWithBuffer] Not found buffer key: {sKey}"); } } return(sValue); }
public static void Fail() { _runType = TestContext.CurrentContext.Test.Properties.Get("RunType")?.ToString(); switch (_runType.ToUpper()) { case "DEV": GetDevTestCaseInfo(); ObjectId debugScreenShotId = MongoDBHelpers.TakeScreenShotAndUpload($"dev{_devRunRecord.TestCaseCodeName}"); _devRunRecord.ErrorMessage = $"[{_keywordName}]: {TestContext.CurrentContext.Result.Message} {TestContext.CurrentContext.Result.StackTrace}"; Console.WriteLine($"{DateTime.UtcNow} - [{_keywordName}]: {TestContext.CurrentContext.Result.Message} {TestContext.CurrentContext.Result.StackTrace}"); _devRunRecord.EndAt = DateTime.UtcNow; _devRunRecord.ExecuteTime = (_devRunRecord.EndAt - _devRunRecord.StartAt).Seconds; _devRunRecord.ErrorScreenshot = debugScreenShotId.ToString(); _devRunRecord.Buffers = MongoDBHelpers.getDevBuffers(_devRunRecord); _devRunRecord.Log = $"\n{DateTime.UtcNow}: {_devRunRecord.ErrorMessage}"; _devRunRecord.Log += $"\n{DateTime.UtcNow}: Error Screenshot - {debugScreenShotId}"; MongoDBHelpers.UpdateFailForDevRecord(_devRunRecord); break; case "REGRESSION": GetRegTestCaseInfo(); ObjectId regressionScreenShotId = MongoDBHelpers.TakeScreenShotAndUpload($"regression_{_devRunRecord.TestCaseCodeName}"); _regRunRecord.ErrorMessage = $"[{_keywordName}]: {TestContext.CurrentContext.Result.Message} {TestContext.CurrentContext.Result.StackTrace}"; Console.WriteLine($"{DateTime.UtcNow} - [{_keywordName}]: {TestContext.CurrentContext.Result.Message} {TestContext.CurrentContext.Result.StackTrace}"); _regRunRecord.EndAt = DateTime.UtcNow; _regRunRecord.ExecuteTime = (_regRunRecord.EndAt - _regRunRecord.StartAt).Seconds; _regRunRecord.ErrorScreenshot = regressionScreenShotId.ToString(); _regRunRecord.Log = $"\n{DateTime.UtcNow}: {_regRunRecord.ErrorMessage}"; _regRunRecord.Log += $"\n{DateTime.UtcNow}: Error Screenshot - {regressionScreenShotId}"; MongoDBHelpers.UpdateFailForRegRecord(_regRunRecord); break; } }
public async Task Setup() { string runType = TestContext.CurrentContext.Test.Properties.Get("RunType")?.ToString(); // Start HubConnection HubConnectionFactory.InitHubConnection(); await HubConnectionFactory.SignalRConnection.StartAsync(); switch (runType.ToUpper()) { case "DEV": DevRunRecord devRunRecord = new DevRunRecord() { TestCaseId = TestContext.CurrentContext.Test.Properties.Get("TestCaseId")?.ToString(), TestCaseName = TestContext.CurrentContext.Test.Properties.Get("TestCaseName")?.ToString(), TestCaseCodeName = TestContext.CurrentContext.Test.Properties.Get("TestCaseCodeName")?.ToString(), Description = TestContext.CurrentContext.Test.Properties.Get("Description")?.ToString(), Category = TestContext.CurrentContext.Test.Properties.Get("Category")?.ToString(), TestSuite = TestContext.CurrentContext.Test.Properties.Get("TestSuite")?.ToString(), TestGroup = TestContext.CurrentContext.Test.Properties.Get("TestGroup")?.ToString(), Team = TestContext.CurrentContext.Test.Properties.Get("Team")?.ToString(), StartAt = DateTime.UtcNow, RunMachine = Environment.MachineName, WorkItem = TestContext.CurrentContext.Test.Properties.Get("WorkItem")?.ToString(), Status = TestContext.CurrentContext.Result.Outcome.Status.ToString(), TestCaseType = TestContext.CurrentContext.Test.Properties.Get("TestCaseType")?.ToString(), }; //TestCase Info Console.WriteLine( $"---------------------{new string('-', devRunRecord.TestCaseId.Length)}--{new string('-', devRunRecord.TestCaseName.Length)}-------"); Console.WriteLine( $"------ Run TestCase: {devRunRecord.TestCaseId}: {devRunRecord.TestCaseName} ------"); Console.WriteLine( $"---------------------{new string('-', devRunRecord.TestCaseId.Length)}--{new string('-', devRunRecord.TestCaseName.Length)}-------"); Console.WriteLine(""); devRunRecord.Log = $"{DateTime.UtcNow} - [Setup]: -------- Setup --------"; devRunRecord.Log += "\nTest Case attributes:"; IList <string> lstPros = TestContext.CurrentContext.Test.Properties.Keys.ToList <string>(); foreach (var key in lstPros) { if (!key.Equals("WebDriver")) //WebDriver attribute is multiple, so need to get list of it before action { Console.WriteLine($"[{key}]: {TestContext.CurrentContext.Test.Properties.Get(key)}"); devRunRecord.Log += $"\n[{key}]: {TestContext.CurrentContext.Test.Properties.Get(key)}"; } else { IList lstDriver = (IList)TestContext.CurrentContext.Test.Properties["WebDriver"]; foreach (string driver in lstDriver) { Console.WriteLine($"[{key}]: {driver}"); devRunRecord.Log += $"\n[{key}]: {driver}"; } } } devRunRecord.Log += "\n"; _runId = await MongoDBHelpers.InitDevRunRecord(devRunRecord); TestExecutionContext.CurrentContext.CurrentTest.Properties.Set("Id", _runId); TestExecutionContext.CurrentContext.CurrentTest.Properties.Set("StartAt", devRunRecord.StartAt); await HubConnectionFactory.SignalRConnection.InvokeAsync("DevRunningInfo", devRunRecord); break; case "REGRESSION": RegressionRunRecord regRunRecord = new RegressionRunRecord() { RegressionTestId = TestContext.CurrentContext.Test.Properties.Get("RegressionTestId")?.ToString(), ErrorMessage = string.Empty, Log = string.Empty, ErrorScreenshot = string.Empty, Screenshot1 = string.Empty, Screenshot2 = string.Empty, StartAt = DateTime.UtcNow, ClientName = string.Empty, RunMachine = Environment.MachineName, Status = TestContext.CurrentContext.Result.Outcome.Status.ToString(), }; _runId = await MongoDBHelpers.InitRegRunRecord(regRunRecord); TestExecutionContext.CurrentContext.CurrentTest.Properties.Set("Id", _runId); TestExecutionContext.CurrentContext.CurrentTest.Properties.Set("StartAt", regRunRecord.StartAt); break; } }
public static void setValueToBuffer(string sKey, string sValue) { MongoDBHelpers.setBufferValue(sKey, sValue); }