Skip to content

Commit 9963891

Browse files
authored
Merge pull request #731 from Lombiq/issue/NEST-644
NEST-644: Fixing that setting AccessibilityCheckingConfiguration.CreateReportAlways failed if the test had more than one page
2 parents 148bb18 + 94cbbbd commit 9963891

4 files changed

Lines changed: 109 additions & 7 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Lombiq.Tests.UI.Constants;
2+
3+
internal static class AccessibilityCheckingConstants
4+
{
5+
public const string AccessibilityReportFileNameWithoutExtension = "AccessibilityReport";
6+
public const string AccessibilityReportFileName = AccessibilityReportFileNameWithoutExtension + ".html";
7+
}

Lombiq.Tests.UI/Extensions/AccessibilityCheckingUITestContextExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Deque.AxeCore.Commons;
22
using Deque.AxeCore.Selenium;
3+
using Lombiq.Tests.UI.Constants;
34
using Lombiq.Tests.UI.Exceptions;
45
using Lombiq.Tests.UI.Helpers;
56
using Lombiq.Tests.UI.Services;
@@ -48,13 +49,11 @@ public static void AssertAccessibility(
4849
var reportDirectoryPath = DirectoryHelper.CreateEnumeratedDirectory(
4950
context.GetTempSubDirectoryPath("AxeHtmlReport"));
5051

51-
var reportPath = Path.Combine(
52-
reportDirectoryPath,
53-
context.TestManifest.Name.MakeFileSystemFriendly() + ".html");
52+
var reportPath = Path.Combine(reportDirectoryPath, AccessibilityCheckingConstants.AccessibilityReportFileName);
5453

5554
context.Driver.CreateAxeHtmlReport(axeResult, reportPath);
5655

57-
context.AppendTestDump(reportPath);
56+
context.AppendTestDumpKeepingDuplicates(reportPath);
5857
}
5958
}
6059

Lombiq.Tests.UI/Extensions/TestDumpUITestContextExtensions.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,101 @@ public static void AppendTestDump(
108108
_ => Task.FromResult(image.ToStream()),
109109
messageIfExists: messageIfExists);
110110

111+
/// <summary>
112+
/// Appends a local file's content to be collected in the test dump. Suffixes the file name with an index in case of
113+
/// duplicates.
114+
/// </summary>
115+
/// <param name="filePath">The full file system path of the file.</param>
116+
public static void AppendTestDumpKeepingDuplicates(
117+
this UITestContext context,
118+
string filePath) =>
119+
context.AppendTestDumpKeepingDuplicatesInternal(
120+
Path.GetFileName(filePath),
121+
new TestDumpItem(() => Task.FromResult((Stream)File.OpenRead(filePath))));
122+
123+
/// <summary>
124+
/// Appends stream as file content to be collected in the test dump. Suffixes the file name with an index in case of
125+
/// duplicates.
126+
/// </summary>
127+
/// <param name="fileName">The name of the file.</param>
128+
/// <param name="action">Gets called in test dump collection.</param>
129+
public static void AppendTestDumpKeepingDuplicates(
130+
this UITestContext context,
131+
string fileName,
132+
Func<UITestContext, Task<Stream>> action) =>
133+
context.AppendTestDumpKeepingDuplicatesInternal(
134+
fileName,
135+
new TestDumpItem(() => action(context)));
136+
137+
/// <summary>
138+
/// Appends string as file content to be collected in the test dump. Suffixes the file name with an index in case of
139+
/// duplicates.
140+
/// </summary>
141+
/// <param name="fileName">The name of the file.</param>
142+
/// <param name="content">File content.</param>
143+
public static void AppendTestDumpKeepingDuplicates(
144+
this UITestContext context,
145+
string fileName,
146+
string content) =>
147+
context.AppendTestDumpKeepingDuplicatesInternal(
148+
fileName,
149+
new TestDumpItem(
150+
() => Task.FromResult(
151+
new MemoryStream(
152+
Encoding.UTF8.GetBytes(content)) as Stream)));
153+
154+
/// <summary>
155+
/// Appends generic content as file content to be collected in the test dump. Suffixes the file name with an index
156+
/// in case of duplicates.
157+
/// </summary>
158+
/// <param name="fileName">The name of the file.</param>
159+
/// <param name="content">File content.</param>
160+
/// <param name="getStream">Function to get a new <see cref="Stream"/> from content.</param>
161+
/// <param name="dispose">Action to dispose the content, if required. Can be null.</param>
162+
public static void AppendTestDumpKeepingDuplicates<TContent>(
163+
this UITestContext context,
164+
string fileName,
165+
TContent content,
166+
Func<TContent, Task<Stream>> getStream,
167+
Action<TContent> dispose = null) =>
168+
context.AppendTestDumpKeepingDuplicatesInternal(
169+
fileName,
170+
new TestDumpItemGeneric<TContent>(content, getStream, dispose));
171+
172+
/// <summary>
173+
/// Appends <see cref="Image"/> as file content to be collected in the test dump. Suffixes the file name with an
174+
/// index in case of duplicates. The <see cref="Image"/> will be disposed at the end.
175+
/// </summary>
176+
/// <param name="fileName">The name of the file.</param>
177+
/// <param name="image">File content. The <see cref="Image"/> will be disposed at the end.</param>
178+
public static void AppendTestDumpKeepingDuplicates(
179+
this UITestContext context,
180+
string fileName,
181+
Image image) => context
182+
.AppendTestDumpKeepingDuplicates(
183+
fileName,
184+
image,
185+
_ => Task.FromResult(image.ToStream()));
186+
187+
private static void AppendTestDumpKeepingDuplicatesInternal(
188+
this UITestContext context,
189+
string fileName,
190+
ITestDumpItem item)
191+
{
192+
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
193+
var extension = Path.GetExtension(fileName);
194+
var uniqueFileName = fileName;
195+
var i = 0;
196+
197+
while (context.TestDumpContainer.ContainsKey(uniqueFileName))
198+
{
199+
i++;
200+
uniqueFileName = $"{fileNameWithoutExtension}_{i.ToTechnicalString()}.{extension}";
201+
}
202+
203+
context.AppendTestDumpInternal(uniqueFileName, item);
204+
}
205+
111206
private static void AppendTestDumpInternal(
112207
this UITestContext context,
113208
string fileName,

Lombiq.Tests.UI/Services/UITestExecutionSession.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,13 @@ private void CaptureMarkupValidationResults(Exception ex, string debugInformatio
468468
if (ex is AccessibilityAssertionException accessibilityAssertionException
469469
&& _configuration.AccessibilityCheckingConfiguration.CreateReportOnFailure)
470470
{
471-
var accessibilityReportPath = Path.Combine(debugInformationPath, "AccessibilityReport.html");
471+
var accessibilityReportPath = Path.Combine(debugInformationPath, AccessibilityCheckingConstants.AccessibilityReportFileName);
472472
_context.Driver.CreateAxeHtmlReport(accessibilityAssertionException.AxeResult, accessibilityReportPath);
473473

474474
if (_configuration.ReportTeamCityMetadata)
475475
{
476-
TeamCityMetadataReporter.ReportArtifactLink(_testManifest, "AccessibilityReport", accessibilityReportPath);
476+
TeamCityMetadataReporter.ReportArtifactLink(
477+
_testManifest, AccessibilityCheckingConstants.AccessibilityReportFileNameWithoutExtension, accessibilityReportPath);
477478
}
478479
}
479480

@@ -823,7 +824,7 @@ async Task SqlServerManagerBeforeAppStartHandlerAsync(OrchardCoreAppStartContext
823824
" wasn't found. This most possibly means that the tenant's setup failed.");
824825
}
825826

826-
var appSettings = JsonNode.Parse(await File.ReadAllTextAsync(appSettingsPath, _configuration.TestCancellationToken))!;
827+
var appSettings = JsonNode.Parse(await File.ReadAllTextAsync(appSettingsPath, _configuration.TestCancellationToken));
827828
appSettings[nameof(sqlServerContext.ConnectionString)] = sqlServerContext.ConnectionString;
828829
await File.WriteAllTextAsync(appSettingsPath, appSettings.ToString(), _configuration.TestCancellationToken);
829830
}

0 commit comments

Comments
 (0)