private void UploadReportTabToCI(TestSession session, string browserName) { if (reportUploaded) { return; } var visaulAssertionsDashboardUrl = GetVisualAssertionWebPath(); if (string.IsNullOrWhiteSpace(visaulAssertionsDashboardUrl)) { return; } var reportContent = $@"<html> <head> <script> window.location = ""{visaulAssertionsDashboardUrl}/Home/GetTestsFromSessionSession?sessionId={session.Id}&browserName={browserName}""; </script> </head><body></body> </html> "; var fullFilePath = Path.Combine(Environment.CurrentDirectory, "VisualAssertions.html"); File.WriteAllText(fullFilePath, reportContent); serviceMessage.PublishArtifact(fullFilePath); reportUploaded = true; }
public void OnTestResult(TestResultEventArgs ev) { if (ev == null) { throw new ArgumentNullException(nameof(ev)); } var result = ev.Result; var testCase = result.TestCase; if (!_testCaseFilter.IsSupported(testCase)) { return; } var suiteName = _suiteNameProvider.GetSuiteName(_options.TestRunDirectory, testCase.Source); var testSuiteWriter = GetTestSuiteWriter(suiteName); var testName = testCase.FullyQualifiedName ?? testCase.DisplayName ?? testCase.Id.ToString(); using (var testWriter = testSuiteWriter.OpenTest(testName)) { // ReSharper disable once SuspiciousTypeConversion.Global testWriter.WriteDuration(result.Duration); if (result.Messages != null && result.Messages.Count > 0) { foreach (var message in result.Messages) { if (TestResultMessage.StandardOutCategory.Equals(message.Category, StringComparison.CurrentCultureIgnoreCase) || TestResultMessage.AdditionalInfoCategory.Equals(message.Category, StringComparison.CurrentCultureIgnoreCase) || TestResultMessage.DebugTraceCategory.Equals(message.Category, StringComparison.CurrentCultureIgnoreCase)) { testWriter.WriteStdOutput(message.Text); continue; } if (TestResultMessage.StandardErrorCategory.Equals(message.Category, StringComparison.CurrentCultureIgnoreCase)) { testWriter.WriteErrOutput(message.Text); } } } foreach (var attachments in result.Attachments) { foreach (var attachment in attachments.Attachments) { if (!_options.MetadataEnable || !_options.AllowExperimental || _options.Version.CompareTo(_options.TestMetadataSupportVersion) < 0) { testWriter.WriteStdOutput($"Attachment \"{attachment.Description}\": \"{attachment.Uri}\""); continue; } if (!attachment.Uri.IsFile) { continue; } var filePath = attachment.Uri.LocalPath; if (string.IsNullOrEmpty(filePath)) { continue; } var description = attachment.Description ?? string.Empty; if (description == filePath) { description = string.Empty; } var fileName = Path.GetFileName(filePath); var fileExtension = Path.GetExtension(fileName).ToLowerInvariant(); string artifactDir = null; if (!string.IsNullOrEmpty(description)) { var match = AttachmentDescriptionRegex.Match(description); if (match.Success) { description = match.Groups[1].Value.Trim(); artifactDir = match.Groups[2].Value.Trim(); } } if (artifactDir == null) { var testDirName = new string(testName.Select(c => InvalidPathChars.Contains(c) ? '_' : c).ToArray()); artifactDir = ".teamcity/VSTest/" + testDirName + "/" + _idGenerator.NewId(); } _rootWriter.PublishArtifact(filePath + " => " + artifactDir); var artifact = artifactDir + "/" + fileName; switch (fileExtension) { case ".bmp": case ".gif": case ".ico": case ".jng": case ".jpeg": case ".jpg": case ".jfif": case ".jp2": case ".jps": case ".tga": case ".tiff": case ".tif": case ".svg": case ".wmf": case ".emf": case ".png": testWriter.WriteImage(artifact, description); break; default: testWriter.WriteFile(artifact, description); break; } } } switch (result.Outcome) { case TestOutcome.Passed: break; case TestOutcome.Failed: testWriter.WriteFailed(result.ErrorMessage ?? string.Empty, result.ErrorStackTrace ?? string.Empty); break; case TestOutcome.Skipped: case TestOutcome.None: // https://github.com/JetBrains/TeamCity.VSTest.TestAdapter/issues/23 case TestOutcome.NotFound: if (string.IsNullOrEmpty(result.ErrorMessage)) { testWriter.WriteIgnored(); } else { testWriter.WriteIgnored(result.ErrorMessage); } break; default: throw new ArgumentOutOfRangeException(nameof(result.Outcome), result.Outcome, "Invalid value"); } } }
public void SendAttachment(string testName, UriDataAttachment attachment, ITeamCityTestWriter testWriter) { if (testName == null) { throw new ArgumentNullException(nameof(testName)); } if (attachment == null) { throw new ArgumentNullException(nameof(attachment)); } if (testWriter == null) { throw new ArgumentNullException(nameof(testWriter)); } if (!_options.MetadataEnable || !_options.AllowExperimental || _options.Version.CompareTo(_options.TestMetadataSupportVersion) < 0) { testWriter.WriteStdOutput($"Attachment \"{attachment.Description}\": \"{attachment.Uri}\""); return; } if (!attachment.Uri.IsFile) { return; } var filePath = attachment.Uri.LocalPath; if (string.IsNullOrEmpty(filePath)) { return; } var description = attachment.Description ?? string.Empty; if (description == filePath) { description = string.Empty; } var fileName = Path.GetFileName(filePath); var fileExtension = Path.GetExtension(fileName).ToLowerInvariant(); string artifactDir = null; if (!string.IsNullOrEmpty(description)) { var match = AttachmentDescriptionRegex.Match(description); if (match.Success) { description = match.Groups[1].Value.Trim(); artifactDir = match.Groups[2].Value.Trim(); } } if (artifactDir == null) { var testDirName = new string(NormalizeTestName(testName).ToArray()); artifactDir = ".teamcity/VSTest/" + testDirName + "/" + _idGenerator.NewId(); } _rootWriter.PublishArtifact(filePath + " => " + artifactDir); var artifact = artifactDir + "/" + fileName; switch (fileExtension) { case ".bmp": case ".gif": case ".ico": case ".jng": case ".jpeg": case ".jpg": case ".jfif": case ".jp2": case ".jps": case ".tga": case ".tiff": case ".tif": case ".svg": case ".wmf": case ".emf": case ".png": testWriter.WriteImage(artifact, description); break; default: testWriter.WriteFile(artifact, description); break; } }
/// <summary> /// Attaches new artifact publishing rules as described in /// http://confluence.jetbrains.net/display/TCD7/Build+Artifact /// </summary> /// <param name="fileDirectoryName"> /// Filename to publish. The file name should be relative to the build checkout directory. /// Directory name to publish all the files and subdirectories within the directory specified. The directory name should be a path relative to the build checkout directory. The files will be published preserving the directories structure under the directory specified (the directory itself will not be included). /// </param> public void PublishArtifact(string fileDirectoryName) { m_TeamCityWriter.PublishArtifact(fileDirectoryName); }