Skip to content

Commit ce525e5

Browse files
feat(ui-tests): add event log check element opacity
1 parent 6ef3533 commit ce525e5

File tree

5 files changed

+106
-7
lines changed

5 files changed

+106
-7
lines changed

ui-tests/PageObjects/LayoutPage.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UtTestsExperimentalConsoleAppication.PageObjects.Panes.EventLog;
77
using UtTestsExperimentalConsoleAppication.PageObjects.Panes.VariableState;
88
using UtTestsExperimentalConsoleAppication.PageObjects.Panes.CallTrace;
9+
using UtTestsExperimentalConsoleAppication.Utils;
910

1011
namespace UtTestsExperimentalConsoleAppication.PageObjects;
1112

@@ -20,6 +21,39 @@ public class LayoutPage : BasePage
2021

2122
public LayoutPage(IPage page) : base(page) { }
2223

24+
public Task WaitForFilesystemLoadedAsync() =>
25+
RetryHelpers.RetryAsync(async () =>
26+
await Page.Locator("div[id^='filesystemComponent-']").CountAsync() > 0);
27+
28+
public Task WaitForStateLoadedAsync() =>
29+
RetryHelpers.RetryAsync(async () =>
30+
await Page.Locator("div[id^='stateComponent-']").CountAsync() > 0);
31+
32+
public Task WaitForCallTraceLoadedAsync() =>
33+
RetryHelpers.RetryAsync(async () =>
34+
await Page.Locator("div[id^='calltraceComponent-']").CountAsync() > 0);
35+
36+
public Task WaitForEventLogLoadedAsync() =>
37+
RetryHelpers.RetryAsync(async () =>
38+
await Page.Locator("div[id^='eventLogComponent-']").CountAsync() > 0);
39+
40+
public Task WaitForEditorLoadedAsync() =>
41+
RetryHelpers.RetryAsync(async () =>
42+
await Page.Locator("div[id^='editorComponent-']").CountAsync() > 0);
43+
44+
public Task WaitForAllComponentsLoadedAsync()
45+
{
46+
var waits = new[]
47+
{
48+
// WaitForFilesystemLoadedAsync(),
49+
// WaitForStateLoadedAsync(),
50+
// WaitForCallTraceLoadedAsync(),
51+
// WaitForEventLogLoadedAsync(),
52+
WaitForEditorLoadedAsync()
53+
};
54+
return Task.WhenAll(waits);
55+
}
56+
2357
#region Debug Buttons
2458
public ILocator RunToEntryButton() => Page.Locator("#run-to-entry-debug");
2559
public ILocator ContinueButton() => Page.Locator("#continue-debug");

ui-tests/Tests/FailedTestException.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace UtTestsExperimentalConsoleAppication.Tests
4+
{
5+
/// <summary>
6+
/// Exception thrown when a test condition is not met.
7+
/// </summary>
8+
public class FailedTestException : Exception
9+
{
10+
public FailedTestException(string message) : base(message) { }
11+
}
12+
}
Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Threading.Tasks;
26
using Microsoft.Playwright;
37
using UtTestsExperimentalConsoleAppication.PageObjects;
8+
using UtTestsExperimentalConsoleAppication.PageObjects.Panes.EventLog;
9+
using UtTestsExperimentalConsoleAppication.Utils;
10+
using UtTestsExperimentalConsoleAppication.Tests;
411

512
public static class NoirSpaceShipTests
613
{
@@ -10,7 +17,11 @@ public static class NoirSpaceShipTests
1017
public static async Task EditorLoadedMainNrFile(IPage page)
1118
{
1219
var layout = new LayoutPage(page);
20+
21+
await layout.WaitForAllComponentsLoadedAsync();
22+
1323
var editors = await layout.EditorTabsAsync();
24+
1425
if (!editors.Any(e => e.TabButtonText == "src/main.nr"))
1526
{
1627
throw new Exception("Expected editor tab 'src/main.nr' not found.");
@@ -20,18 +31,59 @@ public static async Task EditorLoadedMainNrFile(IPage page)
2031
public static async Task JumpToAllEvents(IPage page)
2132
{
2233
var layout = new LayoutPage(page);
34+
await layout.WaitForAllComponentsLoadedAsync();
2335

2436
var eventLogs = await layout.EventLogTabsAsync();
2537
foreach (var tab in eventLogs)
2638
{
2739
if (!await tab.IsVisibleAsync()) { continue; }
2840

29-
var events = await tab.EventElementsAsync();
30-
foreach (var e in events)
41+
var events = (await tab.EventElementsAsync()).ToList();
42+
if (!await EventsInExpectedState(events, -1))
43+
{
44+
throw new FailedTestException("Events were expected to be greyed out initially.");
45+
}
46+
47+
for (int i = 0; i < events.Count; i++)
3148
{
32-
// jump to an event by clicking on it
33-
await e._root.ClickAsync();
49+
await events[i]._root.ClickAsync();
50+
await RetryHelpers.RetryAsync(async () =>
51+
(await events[i]._root.GetAttributeAsync("class"))?.Contains("active") == true);
52+
53+
if (!await EventsInExpectedState(events, i))
54+
{
55+
throw new FailedTestException($"Event state mismatch after jumping to index {i}.");
56+
}
3457
}
3558
}
3659
}
60+
61+
private static async Task<bool> EventsInExpectedState(IReadOnlyList<EventRow> events, int currentIndex)
62+
{
63+
for (int i = 0; i < events.Count; i++)
64+
{
65+
var classes = await events[i]._root.GetAttributeAsync("class") ?? string.Empty;
66+
var opacityStr = await events[i]._root.EvaluateAsync<string>("el => window.getComputedStyle(el).opacity");
67+
var opacity = double.Parse(opacityStr, CultureInfo.InvariantCulture);
68+
69+
if (currentIndex < 0)
70+
{
71+
if (!classes.Contains("future") || opacity >= 1) return false;
72+
}
73+
else if (i < currentIndex)
74+
{
75+
if (!classes.Contains("past") || opacity < 1) return false;
76+
}
77+
else if (i == currentIndex)
78+
{
79+
if (!classes.Contains("active") || opacity < 1) return false;
80+
}
81+
else
82+
{
83+
if (!classes.Contains("future") || opacity >= 1) return false;
84+
}
85+
}
86+
87+
return true;
88+
}
3789
}

ui-tests/Tests/TestRunner.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public static async Task RunAsync()
2424

2525
// await PageObjectTests.PageObjectsSmokeTestAsync(page);
2626

27-
await NoirSpaceShipTests.EditorLoadedMainNrFile(page);
2827
await NoirSpaceShipTests.JumpToAllEvents(page);
28+
await NoirSpaceShipTests.EditorLoadedMainNrFile(page);
29+
2930

3031
await browser.CloseAsync();
3132
}

ui-tests/Utils/RetryHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class RetryHelpers
1616
/// <param name="maxAttempts">Maximum number of attempts.</param>
1717
/// <param name="delayMs">Delay in milliseconds between attempts.</param>
1818
/// <exception cref="TimeoutException">Thrown when the condition never evaluates to <c>true</c>.</exception>
19-
public static async Task RetryAsync(Func<Task<bool>> condition, int maxAttempts = 50, int delayMs = 100)
19+
public static async Task RetryAsync(Func<Task<bool>> condition, int maxAttempts = 20, int delayMs = 500)
2020
{
2121
for (int attempt = 0; attempt < maxAttempts; attempt++)
2222
{

0 commit comments

Comments
 (0)