public static async Task <string> InitRegRunRecord(RegressionRunRecord regRunRecord, string collection = "RegressionRunRecords", string collectRegTest = "RegressionTests") { var collect = _db.GetCollection <RegressionRunRecord>(collection); await collect.InsertOneAsync(regRunRecord); // Update RegressionTest var regTestCollection = _db.GetCollection <RegressionTest>(collectRegTest); var currentRegTest = regTestCollection.Find <RegressionTest>(rt => rt.Id == regRunRecord.RegressionTestId).FirstOrDefault(); currentRegTest.RegressionRunRecordIds.Add(regRunRecord.Id); currentRegTest.Status = "Running"; regTestCollection.FindOneAndReplace <RegressionTest>(doc => doc.Id == regRunRecord.RegressionTestId, currentRegTest); return(regRunRecord.Id); }
public static void AddInfoForRegRecord(RegressionRunRecord regRunRecord, string collectRunRecord = "RegressionRunRecords", string collectRegTest = "RegressionTests") { //Update RegressionRunRecord var regRunRecordCollection = _db.GetCollection <RegressionRunRecord>(collectRunRecord); var currentRegRecord = regRunRecordCollection.Find <RegressionRunRecord>(doc => doc.Id == regRunRecord.Id).FirstOrDefault(); currentRegRecord.Status = regRunRecord.Status; currentRegRecord.Log += "\n" + regRunRecord.Log; regRunRecordCollection.FindOneAndReplace <RegressionRunRecord>(doc => doc.Id == regRunRecord.Id, currentRegRecord); //Update Regression Test var regTestCollection = _db.GetCollection <RegressionTest>(collectRegTest); var currentRegTest = regTestCollection.Find <RegressionTest>(rt => rt.Id == regRunRecord.RegressionTestId).FirstOrDefault(); currentRegTest.Status = regRunRecord.Status; regTestCollection.FindOneAndReplace <RegressionTest>(doc => doc.Id == regRunRecord.RegressionTestId, currentRegTest); }
public static void UpdateFailForRegRecord(RegressionRunRecord regRunRecord, string collection = "RegressionRunRecords", string collectRegTest = "RegressionTests") { var regCollection = _db.GetCollection <RegressionRunRecord>(collection); var currRegRecord = regCollection.Find <RegressionRunRecord>(doc => doc.Id == regRunRecord.Id).FirstOrDefault(); currRegRecord.Status = regRunRecord.Status; currRegRecord.EndAt = regRunRecord.EndAt; currRegRecord.ExecuteTime = regRunRecord.ExecuteTime; currRegRecord.Log += regRunRecord.Log; currRegRecord.ErrorMessage = regRunRecord.ErrorMessage; currRegRecord.ErrorScreenshot = regRunRecord.ErrorScreenshot; regCollection.FindOneAndReplace <RegressionRunRecord>(doc => doc.Id == regRunRecord.Id, currRegRecord); //Update Regression Test var regTestCollection = _db.GetCollection <RegressionTest>(collectRegTest); var currentRegTest = regTestCollection.Find <RegressionTest>(rt => rt.Id == regRunRecord.RegressionTestId).FirstOrDefault(); currentRegTest.Status = regRunRecord.Status; regTestCollection.FindOneAndReplace <RegressionTest>(doc => doc.Id == regRunRecord.RegressionTestId, currentRegTest); }
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; } }