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

OSOE-59: Make UI Testing Toolbox UITestManifest more generic step 1 #114

Merged
merged 60 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
0336c69
Making TeamCiry metadata reporting more flexible
Piedone Jan 9, 2022
4db86d9
Removing the parameters from the test name for TC metadata reporting,…
Piedone Jan 9, 2022
e5e3d29
Refactoring UITestManifest
Piedone Jan 9, 2022
5d7f0ff
Testing TC metadata name
Piedone Jan 9, 2022
293b37b
More TC metadata name variations as a test
Piedone Jan 9, 2022
c63faf4
Typo
Piedone Jan 9, 2022
a50a5d5
Typo
Piedone Jan 9, 2022
52e4d6a
Trying to report without test name too
Piedone Jan 9, 2022
444c383
More TC metadata reporting exploration
Piedone Jan 9, 2022
f3b86f8
Code styling
Piedone Jan 9, 2022
6d925bf
Fixing metadata type
Piedone Jan 9, 2022
7567eba
More metadata name formats
Piedone Jan 9, 2022
03c2efd
More TC metadata testing
Piedone Jan 9, 2022
a82e6a5
More TC metadata testing
Piedone Jan 9, 2022
5e27d4c
Implementing fixed TeamCity metadata reporting
Piedone Jan 9, 2022
54bf10d
And again
Piedone Jan 9, 2022
1e6fdd0
Merge remote-tracking branch 'origin/dev' into issue/OSOE-59
Piedone Jan 9, 2022
869c073
Merge remote-tracking branch 'origin/dev' into issue/OSOE-59
Piedone Jan 13, 2022
36df112
Making the UITestManifest available in the UITestContext too
Piedone Jan 13, 2022
199be34
Reporting TC metadata via ITestOutputHelper
Piedone Jan 13, 2022
1e233e8
Revert TeamCityMetadataReporter
Piedone Jan 13, 2022
1cddb0b
Using JetBrains-provided TC metadata escaping logic
Piedone Jan 13, 2022
8c40589
Intentionally failing test
Piedone Jan 13, 2022
aeb8ec7
Reverting TC metadata name generation logic
Piedone Jan 14, 2022
d06a596
Attempting TC metadata reporting with enums in quotes
Piedone Jan 14, 2022
8fa6064
Merge branch 'dev' into issue/OSOE-59
Piedone Jan 25, 2022
3ef3f2d
Only debug BasicTests remains
Piedone Jan 25, 2022
cb51ecf
Revert "Only debug BasicTests remains"
Piedone Jan 25, 2022
774b995
Merge branch 'dev' into issue/OSOE-59
Piedone Feb 3, 2022
4066b5f
Removing debug code from test name generation for TC metadata
Piedone Feb 3, 2022
294d142
Merge remote-tracking branch 'origin/dev' into issue/OSOE-59
Piedone Feb 4, 2022
980a4c5
Debug code for temporarily prefixing TC metadata
Piedone Feb 4, 2022
034d376
Revert "Debug code for temporarily prefixing TC metadata"
Piedone Feb 4, 2022
2865f77
Merge branch 'dev' into issue/OSOE-59
Piedone Feb 7, 2022
87ecb37
Adding TeamCity.VSTest.TestAdapter in attempt to fix TC metadata not …
Piedone Feb 7, 2022
e6f9d7e
Writing TC metadata with ITestOutputHelper instead
Piedone Feb 8, 2022
dda4e18
Adding debug TC metadata prefix
Piedone Feb 8, 2022
6436bda
Fixing analyzer violation
Piedone Feb 8, 2022
5b9e4c8
Revert "Adding debug TC metadata prefix"
Piedone Feb 8, 2022
f6a58d8
Removing all but a debug test
Piedone Feb 8, 2022
a9ee479
Making one debug test fail
Piedone Feb 8, 2022
49f4273
Merge branch 'dev' into issue/OSOE-59
Piedone Feb 9, 2022
fe83523
Removing "Lombiq.Tests.UI.Samples: " prefix from TC metadata
Piedone Feb 9, 2022
479a08a
Restoring sample tests
Piedone Feb 9, 2022
22d8c92
Merge branch 'dev' into issue/OSOE-59
Piedone Feb 9, 2022
715684d
Writing TC metadata to the console again
Piedone Feb 9, 2022
56f4db1
Revert "Adding TeamCity.VSTest.TestAdapter in attempt to fix TC metad…
Piedone Feb 9, 2022
c606e84
Let's see if TC metadata reporting works with TestOutputHelper withou…
Piedone Feb 10, 2022
534c5f1
Adding TeamCity.VSTest.TestAdapter and debug TC metadata prefix
Piedone Feb 10, 2022
7206430
Merge remote-tracking branch 'origin/dev' into issue/OSOE-59
BenedekFarkas Feb 11, 2022
60f7b13
Setting IsPublishable to false on the projects that don't actually co…
BenedekFarkas Feb 11, 2022
2e4a0a1
Merge branch 'dev' into issue/OSOE-59
Piedone Feb 16, 2022
a59fed7
Typo
Piedone Feb 16, 2022
7623719
TeamCityMetadataReporter: Removing double encoding from testname
BenedekFarkas Feb 17, 2022
6f11884
TeamCityMetadataReporter: Fixing escaping for NewLine character
BenedekFarkas Feb 17, 2022
46af8e6
TeamCityMetadataReporter: Removing debug code
BenedekFarkas Feb 17, 2022
37f7734
Revert "TeamCityMetadataReporter: Removing debug code"
BenedekFarkas Feb 17, 2022
42cb956
Moving "Lombiq.Tests.UI.Samples: " prefix in the service message in f…
BenedekFarkas Feb 17, 2022
09ebbed
Merge remote-tracking branch 'origin/dev' into issue/OSOE-59
Piedone Apr 4, 2022
ec84b85
Removing duplicated IsPublishable
Piedone Apr 4, 2022
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
1 change: 1 addition & 0 deletions Lombiq.Tests.UI.Samples/Lombiq.Tests.UI.Samples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="TeamCity.VSTest.TestAdapter" Version="1.0.34" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add this to the wiki if it remains necessary.

</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI.Samples/Tests/BasicTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Task AnonymousHomePageShouldExist(Browser browser) =>
{
// Is the title correct?
context
.Get(By.ClassName("navbar-brand"))
.Get(By.ClassName("navbar-brandsdfds"))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug code needs to be removed.

.Text
.ShouldBe("Lombiq's OSOCE - UI Testing");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void AssertAccessibility(
axeResult,
Path.Combine(
accessibilityConfiguration.AlwaysCreatedAccessibilityReportsDirectoryPath,
context.TestName.MakeFileSystemFriendly() + ".html"));
context.TestManifest.Name.MakeFileSystemFriendly() + ".html"));
}
}

Expand Down
20 changes: 19 additions & 1 deletion Lombiq.Tests.UI/Models/UITestManifest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
using Lombiq.Tests.UI.Services;
using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Xunit.Abstractions;

namespace Lombiq.Tests.UI.Models;

/// <summary>
/// Provides data about the currently executing test.
/// </summary>
public class UITestManifest
{
public string Name { get; set; }
public ITestOutputHelper TestOutputHelper { get; }
public ITest XunitTest { get; }
public string Name => XunitTest.DisplayName;
public Func<UITestContext, Task> TestAsync { get; set; }

public UITestManifest(ITestOutputHelper testOutputHelper)
{
TestOutputHelper = testOutputHelper;

XunitTest = testOutputHelper.GetType()
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault(field => field.FieldType == typeof(ITest))
?.GetValue(testOutputHelper) as ITest;
}
}
9 changes: 1 addition & 8 deletions Lombiq.Tests.UI/OrchardCoreUITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Lombiq.Tests.UI.Services;
using System;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Xunit.Abstractions;

Expand Down Expand Up @@ -240,13 +238,8 @@ protected virtual async Task ExecuteTestAsync(
Func<UITestContext, Task<Uri>> setupOperation,
Func<OrchardCoreUITestExecutorConfiguration, Task> changeConfigurationAsync)
{
var testManifest = new UITestManifest
var testManifest = new UITestManifest(_testOutputHelper)
{
Name = (_testOutputHelper.GetType()
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
.FirstOrDefault(field => field.FieldType == typeof(ITest))
?.GetValue(_testOutputHelper) as ITest)
?.DisplayName,
TestAsync = testAsync,
};

Expand Down
40 changes: 20 additions & 20 deletions Lombiq.Tests.UI/Services/TeamCityMetadataReporter.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Lombiq.Tests.UI.Models;
using System;
using System.IO;

Expand All @@ -15,32 +16,31 @@ namespace Lombiq.Tests.UI.Services;
/// </remarks>
public static class TeamCityMetadataReporter
{
public static void ReportInt(string testName, string name, int number) =>
ReportNumber(testName, name, number.ToTechnicalString());
public static void ReportInt(UITestManifest uiTestManifest, string name, int number) =>
ReportNumber(uiTestManifest, name, number.ToTechnicalString());

public static void ReportNumber(string testName, string name, string number) =>
Report(testName, name, "number", number);
public static void ReportNumber(UITestManifest uiTestManifest, string name, string number) =>
Report(uiTestManifest, name, "number", number);

public static void ReportText(string testName, string name, string text) =>
Report(testName, name, "text", text);
public static void ReportText(UITestManifest uiTestManifest, string name, string text) =>
Report(uiTestManifest, name, "text", text);

public static void ReportExternalLink(string testName, string name, string url) =>
Report(testName, name, "link", url);
public static void ReportExternalLink(UITestManifest uiTestManifest, string name, string url) =>
Report(uiTestManifest, name, "link", url);

public static void ReportArtifactLink(string testName, string name, string artifactPath) =>
Report(testName, name, "artifact", PreparePath(artifactPath));
public static void ReportArtifactLink(UITestManifest uiTestManifest, string name, string artifactPath) =>
Report(uiTestManifest, name, "artifact", PreparePath(artifactPath));

public static void ReportImage(string testName, string name, string imageArtifactPath) =>
Report(testName, name, "image", PreparePath(imageArtifactPath));
public static void ReportImage(UITestManifest uiTestManifest, string name, string imageArtifactPath) =>
Report(uiTestManifest, name, "image", PreparePath(imageArtifactPath));

public static void ReportVideo(string testName, string name, string videoArtifactPath) =>
Report(testName, name, "video", PreparePath(videoArtifactPath));
public static void ReportVideo(UITestManifest uiTestManifest, string name, string videoArtifactPath) =>
Report(uiTestManifest, name, "video", PreparePath(videoArtifactPath));

public static void Report(string testName, string name, string type, string value) =>
// Starting with a line break is sometimes necessary not to mix up these messages in the build output.
Console.WriteLine(
Environment.NewLine +
$"##teamcity[testMetadata testName='{Escape(testName)}' name='{Escape(name)}' type='{type}' value='{Escape(value)}']");
public static void Report(UITestManifest uiTestManifest, string name, string type, string value) =>
uiTestManifest.TestOutputHelper.WriteLine(
$"##teamcity[testMetadata testName='Lombiq.Tests.UI.Samples: {Escape(uiTestManifest.Name)}' " +
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug "Lombiq.Tests.UI.Samples:" prefix needs to be removed.

$"name='{Escape(name)}' type='{type}' value='{Escape(value)}']");

// TeamCity needs forward slashes to replacing backslashes if the platform uses that.
private static string PreparePath(string artifactPath) => artifactPath.Replace(Path.DirectorySeparatorChar, '/');
Expand All @@ -49,7 +49,7 @@ public static void Report(string testName, string name, string type, string valu
private static string Escape(string value) => value
.Replace("|", "||", StringComparison.Ordinal)
.Replace("'", "|'", StringComparison.Ordinal)
.Replace("\n", "n", StringComparison.Ordinal)
.Replace("\n", "|n", StringComparison.Ordinal)
.Replace("\r", "|r", StringComparison.Ordinal)
.Replace(@"\uNNNN", "|0xNNNN", StringComparison.Ordinal)
.Replace("[", "|[", StringComparison.Ordinal)
Expand Down
9 changes: 5 additions & 4 deletions Lombiq.Tests.UI/Services/UITestContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Lombiq.HelpfulLibraries.OrchardCore.Mvc;
using Lombiq.Tests.UI.Exceptions;
using Lombiq.Tests.UI.Extensions;
using Lombiq.Tests.UI.Models;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System;
Expand All @@ -16,9 +17,9 @@ public class UITestContext
private readonly List<BrowserLogMessage> _historicBrowserLog = new();

/// <summary>
/// Gets the technical name of the current test.
/// Gets data about the currently executing test.
/// </summary>
public string TestName { get; }
public UITestManifest TestManifest { get; }

/// <summary>
/// Gets the configuration of the test execution.
Expand Down Expand Up @@ -78,15 +79,15 @@ public class UITestContext
public string TenantName { get; set; } = "Default";

public UITestContext(
string testName,
UITestManifest testManifest,
OrchardCoreUITestExecutorConfiguration configuration,
SqlServerRunningContext sqlServerContext,
IWebApplicationInstance application,
AtataScope scope,
SmtpServiceRunningContext smtpContext,
AzureBlobStorageRunningContext blobStorageContext)
{
TestName = testName;
TestManifest = testManifest;
Configuration = configuration;
SqlServerRunningContext = sqlServerContext;
Application = application;
Expand Down
14 changes: 7 additions & 7 deletions Lombiq.Tests.UI/Services/UITestExecutionSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ string GetScreenshotPath(int index) =>
if (_configuration.ReportTeamCityMetadata)
{
TeamCityMetadataReporter.ReportImage(
_testManifest.Name, "FailureScreenshot", GetScreenshotPath(_screenshots.Count - 1));
_testManifest, "FailureScreenshot", GetScreenshotPath(_screenshots.Count - 1));
}
}

Expand All @@ -228,7 +228,7 @@ string GetScreenshotPath(int index) =>

if (_configuration.ReportTeamCityMetadata)
{
TeamCityMetadataReporter.ReportArtifactLink(_testManifest.Name, "PageSource", htmlPath);
TeamCityMetadataReporter.ReportArtifactLink(_testManifest, "PageSource", htmlPath);
}
}

Expand All @@ -242,7 +242,7 @@ await File.WriteAllLinesAsync(

if (_configuration.ReportTeamCityMetadata)
{
TeamCityMetadataReporter.ReportArtifactLink(_testManifest.Name, "BrowserLog", browserLogPath);
TeamCityMetadataReporter.ReportArtifactLink(_testManifest, "BrowserLog", browserLogPath);
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ private async Task SaveTestOutputAsync(string debugInformationPath)

if (_configuration.ReportTeamCityMetadata)
{
TeamCityMetadataReporter.ReportArtifactLink(_testManifest.Name, "TestOutput", testOutputPath);
TeamCityMetadataReporter.ReportArtifactLink(_testManifest, "TestOutput", testOutputPath);
}
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ private void CaptureMarkupValidationResults(Exception ex, string debugInformatio

if (_configuration.ReportTeamCityMetadata)
{
TeamCityMetadataReporter.ReportArtifactLink(_testManifest.Name, "AccessibilityReport", accessbilityReportPath);
TeamCityMetadataReporter.ReportArtifactLink(_testManifest, "AccessibilityReport", accessbilityReportPath);
}
}

Expand All @@ -353,7 +353,7 @@ private void CaptureMarkupValidationResults(Exception ex, string debugInformatio

if (_configuration.ReportTeamCityMetadata)
{
TeamCityMetadataReporter.ReportArtifactLink(_testManifest.Name, "HtmlValidationReport", htmlValidationReportPath);
TeamCityMetadataReporter.ReportArtifactLink(_testManifest, "HtmlValidationReport", htmlValidationReportPath);
}
}
else
Expand Down Expand Up @@ -566,7 +566,7 @@ Task UITestingBeforeAppStartHandlerAsync(string contentRootPath, ArgumentsBuilde
_configuration);

return new UITestContext(
_testManifest.Name,
_testManifest,
_configuration,
sqlServerContext,
_applicationInstance,
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/Services/UITestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static async Task ExecuteOrchardCoreTestInnerAsync(UITestManifest testMa
{
if (configuration.ReportTeamCityMetadata && (passed || retryCount == configuration.MaxRetryCount))
{
TeamCityMetadataReporter.ReportInt(testManifest.Name, "TryCount", retryCount + 1);
TeamCityMetadataReporter.ReportInt(testManifest, "TryCount", retryCount + 1);
}
}

Expand Down