Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(playwrighttesting): Added runName feature #47062

Merged
merged 7 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public partial class RunSettingKey
public static readonly string NumberOfTestWorkers;
public static readonly string Os;
public static readonly string RunId;
public static readonly string RunName;
public static readonly string ServiceAuthType;
public static readonly string UseCloudHostedBrowsers;
public RunSettingKey() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public class RunSettingKey
/// Number of NUnit test workers.
/// </summary>
public static readonly string NumberOfTestWorkers = "NumberOfTestWorkers";

/// <summary>
/// The run name setting key.
/// </summary>
public static readonly string RunName = "RunName";
}

internal class Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ internal class CloudRunMetadata
{
internal string? WorkspaceId { get; set; }
internal string? RunId { get; set; }
internal string? RunName { get; set; }
internal Uri? BaseUri { get; set; }
internal string? PortalUrl
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ internal void InitializePlaywrightReporter(string xmlSettings)
runParameters.TryGetValue(RunSettingKey.EnableGitHubSummary, out var enableGithubSummary);
runParameters.TryGetValue(RunSettingKey.EnableResultPublish, out var enableResultPublish);
nunitParameters.TryGetValue(RunSettingKey.NumberOfTestWorkers, out var numberOfTestWorkers);
runParameters.TryGetValue(RunSettingKey.RunName, out var runName);

string? enableGithubSummaryString = enableGithubSummary?.ToString();
string? enableResultPublishString = enableResultPublish?.ToString();

Expand Down Expand Up @@ -148,6 +150,7 @@ internal void InitializePlaywrightReporter(string xmlSettings)
var cloudRunMetadata = new CloudRunMetadata
{
RunId = cloudRunId,
RunName = runName?.ToString(),
WorkspaceId = workspaceId,
BaseUri = baseUri,
EnableResultPublish = _enableResultPublish,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@ public TestRunDto GetTestRun()
{
var startTime = _cloudRunMetadata.TestRunStartTime.ToString("yyyy-MM-ddTHH:mm:ssZ");
var gitBasedRunName = ReporterUtils.GetRunName(CiInfoProvider.GetCIInfo())?.Trim();
string runName = string.IsNullOrEmpty(gitBasedRunName) ? _cloudRunMetadata.RunId! : gitBasedRunName!;
string runName;
if (!string.IsNullOrEmpty(_cloudRunMetadata.RunName))
{
runName = _cloudRunMetadata.RunName!;
}
else if (!string.IsNullOrEmpty(gitBasedRunName))
{
runName = gitBasedRunName!;
}
else
{
runName = _cloudRunMetadata.RunId!;
}
var run = new TestRunDto
{
TestRunId = _cloudRunMetadata.RunId!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Processor;
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Utility;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Moq;

namespace Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Tests.Processor
{
Expand Down Expand Up @@ -68,6 +69,32 @@ public void GetTestRun_ReturnsTestRunDto()
Assert.IsNotNull(result.TestRunConfig!.Shards);
Assert.AreEqual(1, result.TestRunConfig!.Shards!.Total);
}
[Test]
public void GetTestRun_ShouldUseRunName_WhenRunNameIsNotEmpty()
{
var cloudRunMetadata = new CloudRunMetadata
{
RunName = "runName",
WorkspaceId = "workspaceId",
RunId = "runId",
AccessTokenDetails = new()
{
oid = "oid",
userName = " userName "
}
};
var cIInfo = new CIInfo
{
Branch = "branch_name",
Author = "author",
CommitId = "commitId",
RevisionUrl = "revisionUrl",
Provider = CIConstants.s_gITHUB_ACTIONS
};
var dataProcessor = new DataProcessor(cloudRunMetadata, cIInfo);
TestRunDto result = dataProcessor.GetTestRun();
Assert.AreEqual("runName", result.DisplayName);
}

[Test]
public void GetTestRunShard_ReturnsTestRunShardDto()
Expand Down Expand Up @@ -151,7 +178,58 @@ public void GetTestCaseResultData_WithNonNullTestResult_ReturnsTestResults()
Assert.AreEqual(TestCaseResultStatus.s_iNCONCLUSIVE, result.ResultsSummary.Status);
Assert.AreEqual(TestCaseResultStatus.s_iNCONCLUSIVE, result.Status);
}

[Test]
[Ignore("Need to mock GetRunName response")]
public void GetTestRun_ShouldUseGitBasedRunName_WhenRunNameIsEmptyAndGitBasedRunNameIsNotEmpty()
{
var cloudRunMetadata = new CloudRunMetadata
{
RunName = "",
WorkspaceId = "workspaceId",
RunId = "runId",
AccessTokenDetails = new()
{
oid = "oid",
userName = " userName "
}
};
var cIInfo = new CIInfo
{
Branch = "branch_name",
Author = "author",
CommitId = "commitId",
RevisionUrl = "revisionUrl",
Provider = CIConstants.s_gITHUB_ACTIONS
};
var gitBasedRunName = ReporterUtils.GetRunName(cIInfo);
var dataProcessor = new DataProcessor(cloudRunMetadata, cIInfo);
TestRunDto result = dataProcessor.GetTestRun();
Assert.AreEqual(gitBasedRunName, result.DisplayName);
}
[Test]
[Ignore("Need to mock GetRunName response")]
public void GetTestRun_ShouldUseRunId_WhenRunNameAndGitBasedRunNameAreEmpty()
{
var cloudRunMetadata = new CloudRunMetadata
{
RunName = "",
WorkspaceId = "workspaceId",
RunId = "runId",
AccessTokenDetails = new()
{
oid = "oid",
userName = " userName "
}
};
var cIInfo = new CIInfo
{
};
var reporterUtilsMock = new Mock<ReporterUtils>();
reporterUtilsMock.Setup(r => ReporterUtils.GetRunName(cIInfo)).Returns(string.Empty);
var dataProcessor = new DataProcessor(cloudRunMetadata, cIInfo);
TestRunDto result = dataProcessor.GetTestRun();
Assert.AreEqual("runId", result.DisplayName);
}
[Test]
public void GetRawResultObject_WithNullTestResult_ReturnsRawTestResultWithEmptyErrorsAndStdErr()
{
Expand Down