public void Run(SpiraTestConfigurationAttribute testConfigAttribute, TestCaseResult result) { const string METHOD_NAME = "Run: "; try { //Get the DefaultConfigPrefix from the config file string defaultConfigPrefix = ConfigurationSettings.AppSettings["DefaultConfigPrefix"]; //Get the URL, Login, Password and ProjectId from the // config file string url = Properties.Settings.Default.Url; string login = Properties.Settings.Default.Login; string password = Properties.Settings.Default.Password; int projectId = Properties.Settings.Default.ProjectId; Nullable <int> releaseId = null; int tempReleaseId; if (Int32.TryParse(Properties.Settings.Default.ReleaseId, out tempReleaseId)) { releaseId = tempReleaseId; } Nullable <int> testSetId = null; int tempTestSetId; if (Int32.TryParse(Properties.Settings.Default.TestSetId, out tempTestSetId)) { testSetId = tempTestSetId; } //See if we need to override the default configuration settings if (testConfigAttribute != null) { url = testConfigAttribute.Url; login = testConfigAttribute.Login; password = testConfigAttribute.Password; projectId = testConfigAttribute.ProjectId; releaseId = testConfigAttribute.ReleaseId; testSetId = testConfigAttribute.TestSetId; } //Now we need to extract the result information int executionStatusId = -1; if (!result.Executed) { //Set status to 'Not Run' executionStatusId = 3; } else { if (result.IsFailure) { //Set status to 'Failed' executionStatusId = 1; } if (result.IsSuccess) { //Set status to 'Passed' executionStatusId = 2; } } //Extract the other information string testCaseName = result.Name; string message = result.Message; string stackTrace = result.StackTrace; int assertCount = result.AssertCount; DateTime startDate = DateTime.Now.AddSeconds(-result.Time); DateTime endDate = DateTime.Now; //Instantiate the web-service proxy class and set the URL from the text box bool success = false; SpiraImportExport.ImportExport spiraTestExecuteProxy = new SpiraImportExport.ImportExport(); spiraTestExecuteProxy.Url = url + TEST_EXECUTE_WEB_SERVICES_URL; //Create a new cookie container to hold the session handle CookieContainer cookieContainer = new CookieContainer(); spiraTestExecuteProxy.CookieContainer = cookieContainer; //Attempt to authenticate the user success = spiraTestExecuteProxy.Connection_Authenticate(login, password); if (!success) { throw new Exception( "Cannot authenticate with SpiraTest, check the URL, login and password"); } //Now connect to the specified project success = spiraTestExecuteProxy.Connection_ConnectToProject(projectId); if (!success) { throw new Exception( "Cannot connect to the specified project, check permissions of user!"); } //Now actually record the test run itself SpiraImportExport.RemoteTestRun remoteTestRun = new SpiraImportExport.RemoteTestRun(); remoteTestRun.TestCaseId = testCaseId; remoteTestRun.ReleaseId = releaseId; remoteTestRun.TestSetId = testSetId; remoteTestRun.StartDate = startDate; remoteTestRun.EndDate = endDate; remoteTestRun.ExecutionStatusId = executionStatusId; remoteTestRun.RunnerName = TEST_RUNNER_NAME; remoteTestRun.RunnerTestName = testCaseName; remoteTestRun.RunnerAssertCount = assertCount; remoteTestRun.RunnerMessage = message; remoteTestRun.RunnerStackTrace = stackTrace; spiraTestExecuteProxy.TestRun_RecordAutomated1(remoteTestRun); //Close the SpiraTest connection spiraTestExecuteProxy.Connection_Disconnect(); } catch (Exception exception) { //Log error then rethrow System.Diagnostics.EventLog.WriteEntry( SOURCE_NAME, CLASS_NAME + METHOD_NAME + exception.Message, System.Diagnostics.EventLogEntryType.Error); throw exception; } }
/// <summary> /// Executes the NUnit test case /// </summary> /// <returns>The test result</returns> public override TestResult RunTest() { const string METHOD_NAME = "RunTest: "; try { //Call the base method to run the result within NUnit TestResult result = base.RunTest(); //Get the URL, Login, Password and ProjectId from the parent test fixture attribute Type type = testMethod.FixtureType; Attribute attribute = Reflect.GetAttribute(type, "Inflectra.SpiraTest.AddOns.SpiraTestNUnitAddIn.SpiraTestFramework.SpiraTestConfigurationAttribute", false); if (attribute == null) { throw new Exception("Cannot retrieve the SpiraTestConfiguration attribute from the test fixture"); } //Get the various properties from the attribute string url = (string)Reflect.GetPropertyValue(attribute, "Url", BindingFlags.Public | BindingFlags.Instance); string login = (string)Reflect.GetPropertyValue(attribute, "Login", BindingFlags.Public | BindingFlags.Instance); string password = (string)Reflect.GetPropertyValue(attribute, "Password", BindingFlags.Public | BindingFlags.Instance); int projectId = (int)Reflect.GetPropertyValue(attribute, "ProjectId", BindingFlags.Public | BindingFlags.Instance); Nullable <int> releaseId = null; if (Reflect.GetPropertyValue(attribute, "ReleaseId", BindingFlags.Public | BindingFlags.Instance) != null) { releaseId = (Nullable <int>)Reflect.GetPropertyValue(attribute, "ReleaseId", BindingFlags.Public | BindingFlags.Instance); } Nullable <int> testSetId = null; if (Reflect.GetPropertyValue(attribute, "TestSetId", BindingFlags.Public | BindingFlags.Instance) != null) { testSetId = (Nullable <int>)Reflect.GetPropertyValue(attribute, "TestSetId", BindingFlags.Public | BindingFlags.Instance); } string runnerName = Reflect.GetPropertyValue(attribute, "Runner", BindingFlags.Public | BindingFlags.Instance).ToString(); //Now we need to extract the result information int executionStatusId = -1; if (!result.Executed) { //Set status to 'Not Run' executionStatusId = 3; } else { //If no codes are found, default to blocked; executionStatusId = 5; if (result.IsFailure) { //Set status to 'Failed' executionStatusId = 1; } if (result.IsSuccess) { //Set status to 'Passed' executionStatusId = 2; } if (result.IsError) { //Set status to 'Failed' executionStatusId = 1; } } //Extract the other information string testCaseName = result.Name; string message = result.Message; string stackTrace = result.StackTrace; int assertCount = result.AssertCount; DateTime startDate = DateTime.Now.AddSeconds(-result.Time); DateTime endDate = DateTime.Now; //Specify that we will be using TLS 1.2 if this is HTTPS System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //Instantiate the web-service proxy class and set the URL from the text box bool success = false; SpiraImportExport.ImportExport spiraTestExecuteProxy = new SpiraImportExport.ImportExport(); spiraTestExecuteProxy.Url = url + TEST_EXECUTE_WEB_SERVICES_URL; //Create a new cookie container to hold the session handle CookieContainer cookieContainer = new CookieContainer(); spiraTestExecuteProxy.CookieContainer = cookieContainer; //Attempt to authenticate the user success = spiraTestExecuteProxy.Connection_Authenticate(login, password); if (!success) { throw new Exception("Cannot authenticate with SpiraTest, check the URL, login and password"); } //Now connect to the specified project success = spiraTestExecuteProxy.Connection_ConnectToProject(projectId); if (!success) { throw new Exception("Cannot connect to the specified project, check permissions of user!"); } //Now actually record the test run itself SpiraImportExport.RemoteTestRun remoteTestRun = new SpiraImportExport.RemoteTestRun(); remoteTestRun.TestCaseId = testCaseId; remoteTestRun.ReleaseId = releaseId; remoteTestRun.TestSetId = testSetId; remoteTestRun.StartDate = startDate; remoteTestRun.EndDate = endDate; remoteTestRun.ExecutionStatusId = executionStatusId; remoteTestRun.RunnerName = runnerName; remoteTestRun.RunnerTestName = testCaseName; remoteTestRun.RunnerAssertCount = assertCount; remoteTestRun.RunnerMessage = message; remoteTestRun.RunnerStackTrace = stackTrace; spiraTestExecuteProxy.TestRun_RecordAutomated1(remoteTestRun); //Close the SpiraTest connection spiraTestExecuteProxy.Connection_Disconnect(); //Return the result return(result); } catch (Exception exception) { //Log error then rethrow (catch any errors associated with the diagnostics) try { System.Diagnostics.EventLog.WriteEntry(SpiraTestAddin.SOURCE_NAME, CLASS_NAME + METHOD_NAME + exception.Message, System.Diagnostics.EventLogEntryType.Error); } catch {} throw exception; } }
public static void ReportResultToSpiraTeam(TestResult result, int testCaseId) { string url = SpiraTeam.WebServiceUrl; string login = SpiraTeam.Login; string password = SpiraTeam.Password; int projectId = Convert.ToInt32(SpiraTeam.ProjectId); Nullable<int> releaseId = Convert.ToInt32(SpiraTeam.ReleaseId); Nullable<int> testSetId = Convert.ToInt32(SpiraTeam.TestSetId); string runnerName = SpiraTeam.RunnerName; // Now we need to extract the result information ExecutionStatus executionStatus = ExecutionStatus.Unknown; if (!result.Executed) { // Set status to 'Not Run' executionStatus = ExecutionStatus.NotRun; } else { // If no codes are found, default to blocked; executionStatus = ExecutionStatus.Blocked; if (result.IsFailure) { // Set status to 'Failed' executionStatus = ExecutionStatus.Failed; } if (result.IsSuccess) { // Set status to 'Passed' executionStatus = ExecutionStatus.Passed; } if (result.IsError) { // Set status to 'Failed' executionStatus = ExecutionStatus.Failed; } } string testCaseName = result.Name; string message = result.Message; string stackTrace = result.StackTrace; int assertCount = result.AssertCount; DateTime startDate = DateTime.Now.AddSeconds(-result.Time); DateTime endDate = DateTime.Now; // Instantiate the web-service proxy class and set the URL from the text box bool success = false; SpiraImportExport.ImportExport spiraTestExecuteProxy = new SpiraImportExport.ImportExport(); spiraTestExecuteProxy.Url = url; // Create a new cookie container to hold the session handle CookieContainer cookieContainer = new CookieContainer(); spiraTestExecuteProxy.CookieContainer = cookieContainer; // Attempt to authenticate the user success = spiraTestExecuteProxy.Connection_Authenticate(login, password); if (!success) { throw new Exception("Cannot authenticate with SpiraTeam, check the URL, login and password"); } // Now connect to the specified project success = spiraTestExecuteProxy.Connection_ConnectToProject(projectId); if (!success) { throw new Exception("Cannot connect to the specified project, check permissions of user!"); } // Now actually record the test run itself SpiraImportExport.RemoteTestRun remoteTestRun = new SpiraImportExport.RemoteTestRun(); remoteTestRun.TestCaseId = testCaseId; remoteTestRun.ReleaseId = releaseId; remoteTestRun.TestSetId = testSetId; remoteTestRun.StartDate = startDate; remoteTestRun.EndDate = endDate; remoteTestRun.ExecutionStatusId = (int)executionStatus; remoteTestRun.RunnerName = runnerName; remoteTestRun.RunnerTestName = testCaseName; remoteTestRun.RunnerAssertCount = assertCount; remoteTestRun.RunnerMessage = message; remoteTestRun.RunnerStackTrace = stackTrace; spiraTestExecuteProxy.TestRun_RecordAutomated1(remoteTestRun); // Close the SpiraTest connection spiraTestExecuteProxy.Connection_Disconnect(); }