/// <summary>Add a single RemoteAutomatedTestRun to the collection.</summary> /// <param name="testRun">The testRun to add.</param> /// <returns>The current number of testruns in this set.</returns> public int AddPendingTestRun(RemoteAutomatedTestRun testRun) { if (this._testRuns == null) { this._testRuns = new List <RemoteAutomatedTestRun>(); } if (this._testRuns.Count == 0) { this.ScheduledDate = testRun.ScheduledDate; if (this.TestSetId == -1) { this._testSetId = testRun.TestSetId.Value; } if (this.ProjectId == -1) { this._projectId = testRun.ProjectId.Value; } } this._testRuns.Add(testRun); return(this.Count); }
/// <summary> /// Retrieves the automated test script from the server for the provided automated test run and populates /// the test run info as well as the test script attachment info /// </summary> /// <param name="remoteAutomatedTestRun">The api data object from the server</param> /// <param name="projectId">The id of the current project</param> /// <returns>The automated test run object that will be passed to the plugins</returns> public AutomatedTestRun PopulateAutomatedTestScript(RemoteAutomatedTestRun remoteAutomatedTestRun, int projectId) { try { //Create a new automated test run object AutomatedTestRun automatedTestRun = new AutomatedTestRun(); if (this._client.Connection_ConnectToProject(projectId)) { if (remoteAutomatedTestRun.AutomationAttachmentId.HasValue) { RemoteDocument remoteDocument = this._client.Document_RetrieveById(remoteAutomatedTestRun.AutomationAttachmentId.Value); if (remoteDocument == null) { string strMessage = "Could not retrieve attachment for TC:" + remoteAutomatedTestRun.TestCaseId + "."; Logger.LogMessage(strMessage, System.Diagnostics.EventLogEntryType.Warning); return(null); } else { //Populate the automated test run object from api test run object automatedTestRun.TestRunId = new Guid(); //Generates new random GUID //Standard Fields automatedTestRun.Name = remoteAutomatedTestRun.Name; automatedTestRun.AutomationEngineId = remoteAutomatedTestRun.AutomationEngineId; automatedTestRun.AutomationHostId = remoteAutomatedTestRun.AutomationHostId; automatedTestRun.AutomationEngineToken = remoteAutomatedTestRun.AutomationEngineToken; automatedTestRun.ReleaseId = remoteAutomatedTestRun.ReleaseId; automatedTestRun.TestCaseId = remoteAutomatedTestRun.TestCaseId; automatedTestRun.TestSetId = remoteAutomatedTestRun.TestSetId; automatedTestRun.TestSetTestCaseId = remoteAutomatedTestRun.TestSetTestCaseId; automatedTestRun.TestRunTypeId = remoteAutomatedTestRun.TestRunTypeId; automatedTestRun.TestSetTestCaseId = remoteAutomatedTestRun.TestSetTestCaseId; //Parameters if (remoteAutomatedTestRun.Parameters != null) { automatedTestRun.Parameters = new List <TestRunParameter>(); foreach (RemoteTestSetTestCaseParameter parameter in remoteAutomatedTestRun.Parameters) { TestRunParameter testRunParameter = new TestRunParameter(); testRunParameter.Name = parameter.Name; testRunParameter.Value = parameter.Value; automatedTestRun.Parameters.Add(testRunParameter); } } //Custom Properties automatedTestRun.Text01 = remoteAutomatedTestRun.Text01; automatedTestRun.Text02 = remoteAutomatedTestRun.Text02; automatedTestRun.Text03 = remoteAutomatedTestRun.Text03; automatedTestRun.Text04 = remoteAutomatedTestRun.Text04; automatedTestRun.Text05 = remoteAutomatedTestRun.Text05; automatedTestRun.Text06 = remoteAutomatedTestRun.Text06; automatedTestRun.Text07 = remoteAutomatedTestRun.Text07; automatedTestRun.Text08 = remoteAutomatedTestRun.Text08; automatedTestRun.Text09 = remoteAutomatedTestRun.Text09; automatedTestRun.Text10 = remoteAutomatedTestRun.Text10; automatedTestRun.List01 = remoteAutomatedTestRun.List01; automatedTestRun.List02 = remoteAutomatedTestRun.List02; automatedTestRun.List03 = remoteAutomatedTestRun.List03; automatedTestRun.List04 = remoteAutomatedTestRun.List04; automatedTestRun.List05 = remoteAutomatedTestRun.List05; automatedTestRun.List06 = remoteAutomatedTestRun.List06; automatedTestRun.List07 = remoteAutomatedTestRun.List07; automatedTestRun.List08 = remoteAutomatedTestRun.List08; automatedTestRun.List09 = remoteAutomatedTestRun.List09; automatedTestRun.List10 = remoteAutomatedTestRun.List10; //Populate the script info automatedTestRun.FilenameOrUrl = remoteDocument.FilenameOrUrl; automatedTestRun.Type = (AutomatedTestRun.AttachmentType)remoteDocument.AttachmentTypeId; automatedTestRun.Size = remoteDocument.Size; if (automatedTestRun.Type == AutomatedTestRun.AttachmentType.File) { //Need to actually download the test script automatedTestRun.TestScript = this._client.Document_OpenFile(remoteDocument.AttachmentId.Value); } //Return the populated test run return(automatedTestRun); } } else { string strMessage = "Could not find attachment for TC:" + remoteAutomatedTestRun.TestCaseId + ", ID #" + remoteAutomatedTestRun.AutomationAttachmentId + "."; Logger.LogMessage(strMessage, System.Diagnostics.EventLogEntryType.Warning); return(null); } } else { string strMessage = "Could not log on to system."; Logger.LogMessage(strMessage, System.Diagnostics.EventLogEntryType.Warning); return(null); } } catch (Exception ex) { Logger.LogMessage(ex); return(null); } }
/// <summary>Takes an automated test run and creates a test run in the application.</summary> /// <param name="automatedTestRun">An automated test run.</param> /// <param name="projectId">The projectId of the test run.</param> /// <returns>Status on updating.</returns> public bool UpdateAutomatedTestRun(AutomatedTestRun automatedTestRun, int projectId) { try { if (this._client.Connection_ConnectToProject(projectId)) { //Create the RemoteTestRun. RemoteAutomatedTestRun updTestRun = new RemoteAutomatedTestRun(); updTestRun.AutomationEngineId = updTestRun.AutomationEngineId; updTestRun.AutomationHostId = automatedTestRun.AutomationHostId; updTestRun.AutomationEngineToken = automatedTestRun.AutomationEngineToken; updTestRun.EndDate = automatedTestRun.EndDate; updTestRun.ExecutionStatusId = (int)automatedTestRun.ExecutionStatus; updTestRun.List01 = automatedTestRun.List01; updTestRun.List02 = automatedTestRun.List02; updTestRun.List03 = automatedTestRun.List03; updTestRun.List04 = automatedTestRun.List04; updTestRun.List05 = automatedTestRun.List05; updTestRun.List06 = automatedTestRun.List06; updTestRun.List07 = automatedTestRun.List07; updTestRun.List08 = automatedTestRun.List08; updTestRun.List09 = automatedTestRun.List09; updTestRun.List10 = automatedTestRun.List10; updTestRun.Name = automatedTestRun.Name; //Copy parameters.. if (automatedTestRun.Parameters != null) { List <RemoteTestSetTestCaseParameter> trParms = new List <RemoteTestSetTestCaseParameter>(); foreach (TestRunParameter parameter in automatedTestRun.Parameters) { RemoteTestSetTestCaseParameter testRunParam = new RemoteTestSetTestCaseParameter(); testRunParam.Name = parameter.Name; testRunParam.Value = parameter.Value; trParms.Add(testRunParam); } updTestRun.Parameters = trParms.ToArray(); } updTestRun.ProjectId = projectId; updTestRun.ReleaseId = automatedTestRun.ReleaseId; updTestRun.RunnerAssertCount = automatedTestRun.RunnerAssertCount; updTestRun.RunnerMessage = automatedTestRun.RunnerMessage; updTestRun.RunnerName = automatedTestRun.RunnerName; updTestRun.RunnerStackTrace = automatedTestRun.RunnerStackTrace; updTestRun.RunnerTestName = automatedTestRun.RunnerTestName; updTestRun.StartDate = automatedTestRun.StartDate; updTestRun.TestCaseId = automatedTestRun.TestCaseId; updTestRun.TesterId = automatedTestRun.TesterId; //updTestRun.TestRunId = automatedTestRun.TestRunId; updTestRun.TestRunTypeId = automatedTestRun.TestRunTypeId; updTestRun.TestSetId = automatedTestRun.TestSetId; updTestRun.TestSetTestCaseId = automatedTestRun.TestSetTestCaseId; updTestRun.Text01 = automatedTestRun.Text01; updTestRun.Text02 = automatedTestRun.Text02; updTestRun.Text03 = automatedTestRun.Text03; updTestRun.Text04 = automatedTestRun.Text04; updTestRun.Text05 = automatedTestRun.Text05; updTestRun.Text06 = automatedTestRun.Text06; updTestRun.Text07 = automatedTestRun.Text07; updTestRun.Text08 = automatedTestRun.Text08; updTestRun.Text09 = automatedTestRun.Text09; updTestRun.Text10 = automatedTestRun.Text10; //That's it, go create the test run.. this._client.TestRun_RecordAutomated1(updTestRun); //Return true. return(true); } else { Logger.LogMessage("Could not connect to ProjectId " + projectId + ".", System.Diagnostics.EventLogEntryType.Warning); return(false); } } catch (Exception ex) { Logger.LogMessage(ex); return(false); } }
/// <summary>Creates a new instance of the class.</summary> /// <param name="testRun">The first RemoteAutomatedTestRun for the list.</param> public PendingSet(string name, RemoteAutomatedTestRun testRun) : this(name) { this.AddPendingTestRun(testRun); }
public void Execute() { const string METHOD = "Execute()"; Logger.LogTrace(CLASS + METHOD + " Enter"); //Loop through each test, execute it and then finally raise the event. bool isBlocked = false; for (int i = 0; i < this._testsToRun.TestRuns.Count() && !isBlocked; i++) { //DEBUG: Is it contained? RemoteAutomatedTestRun automatedTestRun = this._testsToRun.TestRuns.ElementAt(i); int testCaseId = automatedTestRun.TestCaseId; string strLog2 = " Checking TC:" + testCaseId + ", RunnerName: '" + automatedTestRun.AutomationEngineToken; Logger.LogTrace(CLASS + METHOD + strLog2); //Get the test details. Copy to the return set in case there's an error. int projectId = this._testsToRun.TestRuns.ElementAt(i).ProjectId.Value; AutomatedTestRun testToExecute = this._client.PopulateAutomatedTestScript(automatedTestRun, projectId); AutomatedTestRun testComplete = testToExecute; //Execute the test. try { if (testToExecute != null) { try { Logger.LogTrace(CLASS + METHOD + " Executing test TC:" + testCaseId); //Create an instance of the automation engine AutomationEngine engine = new AutomationEngine(); engine.ApplicationLog = Logger.EventLog; //Download any documents attached to the test case //Since they need to be passed to the test engine List <AttachedDocument> attachedDocs = this._client.GetAttachedDocuments(projectId, testCaseId); //Execute test. testComplete.StartDate = DateTime.Now; testComplete = engine.StartExecution(testToExecute, projectId, attachedDocs); } catch (Exception ex) { //Log it first. Logger.LogMessage(ex, CLASS + METHOD + " Error running test."); //Mark test as blocked, insert data. testComplete.ExecutionStatus = TestRun.TestStatusEnum.Blocked; testComplete.RunnerName = automatedTestRun.AutomationEngineToken; testComplete.EndDate = testComplete.StartDate; //Get exception message. string strStack = "Stack Trace:" + Environment.NewLine + ex.StackTrace; string strMsg = ex.Message; while (ex.InnerException != null) { strMsg += Environment.NewLine + ex.InnerException.Message; ex = ex.InnerException; } testComplete.RunnerMessage = strMsg; testComplete.RunnerStackTrace = "Exception:" + Environment.NewLine + strMsg + Environment.NewLine + Environment.NewLine + strStack; Logger.LogTrace(CLASS + METHOD + " Sending result to server."); try { this._client.UpdateAutomatedTestRun(testComplete, this._testsToRun.ProjectId); } catch (Exception ex2) { Logger.LogMessage(ex2, CLASS + METHOD + " Could not send result to server."); } } } else { Logger.LogMessage(CLASS + METHOD + " Retrieved test was null. Cannot execute." + Environment.NewLine + "Skipping TC:" + testCaseId + " in TX:" + automatedTestRun.TestSetId, System.Diagnostics.EventLogEntryType.Error); } //Record test. if (testComplete != null) { Logger.LogMessage(CLASS + METHOD + " Test finished. Recording results."); try { this._client.UpdateAutomatedTestRun(testComplete, this._testsToRun.ProjectId); } catch (Exception ex) { Logger.LogMessage(ex, CLASS + METHOD + " Error saving results."); } } else { Logger.LogMessage(CLASS + METHOD + " Returned tstComplete variable null! Not recording.", EventLogEntryType.Error); } } catch (Exception ex) { Logger.LogMessage(ex, CLASS + METHOD + " Uncaught error occurred when running test! Cancelling rest of pending tests."); this.WorkCompleted(this, new WorkCompletedArgs(this._testsToRun, ex, WorkCompletedArgs.WorkCompletedStatusEnum.Error)); isBlocked = true; } //Now, report on specific test. this.WorkProgress(this, new WorkProgressArgs()); } if (!isBlocked) { this.WorkCompleted(this, new WorkCompletedArgs(this._testsToRun, null, WorkCompletedArgs.WorkCompletedStatusEnum.OK)); } }