public void TestInitialize() { var dir = Path.GetDirectoryName(typeof(SetUpTests).Assembly.Location); Directory.SetCurrentDirectory(dir); TestRailClient = new TestRailAPIClient(_testRailUrl, TestUserData.GetTestrailUser().Username, TestUserData.GetTestrailUser().Password); if (!TestEnvironment.AreTestsRunningLocally()) { TestRailClient.CreateTestRun("Test run " + DateTime.Now); } }
public void TestInitialize() { var dir = Path.GetDirectoryName(typeof(SetUpTests).Assembly.Location); Directory.SetCurrentDirectory(dir); TestRailClient = new TestRailAPIClient(_testRailUrl, TestUserData.GetTestrailUser().Username, TestUserData.GetTestrailUser().Password); var asm = Assembly.GetExecutingAssembly(); var path = System.IO.Path.GetDirectoryName(asm.Location) + "/ProtonVpn.exe"; var version = Assembly.LoadFile(path).GetName().Version.ToString(); version = version.Substring(0, version.Length - 2); if (!TestEnvironment.AreTestsRunningLocally()) { TestRailClient.CreateTestRun(version + " test run " + DateTime.Now); } }
/// <summary> /// /// </summary> void ITestModule.Run() { var test = TestSuite.CurrentTestContainer; var parameters = TestSuite.Current.Parameters; var container = TestReport.CurrentTestContainerActivity; string testRailURL = parameters.Keys.Contains("TestRailURL") ? parameters["TestRailURL"] : ""; string testRailUsername = parameters.Keys.Contains("TestRailUsername") ? parameters["TestRailUsername"] : ""; string testRailPassword = parameters.Keys.Contains("TestRailPassword") ? parameters["TestRailPassword"] : ""; string testRunID = parameters.Keys.Contains("TestRailTestRunID") ? parameters["TestRailTestRunID"] : ""; if (!this.configValidator.IsValidCredentialData(testRailURL, testRailUsername, testRailPassword)) { Report.Error("No TestRail API credentials provided. Please configure your credentials in the TestRailSetup action!"); return; } if (string.IsNullOrEmpty(testRunID)) { Report.Error("No TestRail Tesst Run ID provided for this Test!"); return; } if (string.IsNullOrEmpty(this.TestCaseID)) { Report.Error("No TestRail TestCaseID provided for this Test!"); return; } // build our actual testrail api client // from the configured credentials var client = new TestRailAPIClient(testRailURL, testRailUsername, testRailPassword, this.testRailTimeoutSeconds); // create our reader to extract data like error messages // from our current test activity container var resultReader = new TestResultReader(container); string comment = ""; Task <TestRailResponse> task = null; switch (test.Status) { case ActivityStatus.Success: comment = "Automatic Ranorex Test Execution"; task = client.SendResult(testRunID, this.TestCaseID, (int)TestRailStatus.STATUS_PASSED, comment); break; case ActivityStatus.Failed: comment = resultReader.GetErrorMessage(); task = client.SendResult(testRunID, this.TestCaseID, (int)TestRailStatus.STATUS_FAILED, comment); break; default: comment = "Automatic Ranorex Test Execution"; task = client.SendResult(testRunID, this.TestCaseID, (int)TestRailStatus.STATUS_NOT_TESTED, comment); break; } if (task == null) { Report.Error("Error when verifying Test Result. No Result sent to TestRail!"); return; } // run our testrail api client and // wait for the result before continuing task.Wait(); TestRailResponse response = task.Result; if (response.StatusCode == System.Net.HttpStatusCode.OK) { // build our testrail deep link to our provided test run string testRunLink = this.BuildTestRunDeepLink(testRailURL, testRunID); Report.Success("Successfully sent Test Result for Test " + this.TestCaseID + " to TestRail!"); Report.Link("Open Test Run", testRunLink); } else { Report.Info("TestRail API Response: " + response.Content); Report.Error("Error when sending Result for Test " + this.TestCaseID + " to TestRail!"); } }