11namespace Motus . Samples . Tests ;
22
33/// <summary>
4- /// Performance testing showcase: budget assertions, individual metric assertions,
5- /// the [PerformanceBudget] attribute, and .Not negation. Uses inline HTML fixtures
6- /// that trigger real navigations so the performance metrics collector fires.
4+ /// Performance testing showcase demonstrating Phase 2 features:
5+ /// budget assertions, individual metric assertions (LCP, FCP, TTFB, CLS),
6+ /// the [PerformanceBudget] attribute with class/method override, and .Not negation.
7+ ///
8+ /// Uses real HTTP navigations so the PerformanceObserver collects actual web vitals.
9+ /// When run in the visual runner, navigate steps appear as annotated timeline markers
10+ /// with LCP, FCP, and CLS values, and the step detail panel shows a Performance section.
711/// </summary>
812[ TestClass ]
13+ [ TestCategory ( "Integration" ) ]
914[ PerformanceBudget ( Lcp = 5000 , Fcp = 5000 , Cls = 1.0 ) ]
1015public class PerformanceTests : MotusTestBase
1116{
12- private const string SimplePage = """
13- <!DOCTYPE html>
14- <html lang="en">
15- <head><title>Performance Sample</title></head>
16- <body>
17- <main>
18- <h1>Performance Test Page</h1>
19- <p>A lightweight page for budget validation.</p>
20- <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="pixel" />
21- </main>
22- </body>
23- </html>
24- """ ;
17+ private const string ExampleUrl = "https://example.com" ;
2518
2619 [ TestMethod ]
27- public async Task SimplePage_MeetsPerformanceBudget ( )
20+ public async Task ExampleDotCom_MeetsPerformanceBudget ( )
2821 {
29- await Fixtures . SetPageContentAsync ( Page , SimplePage ) ;
22+ await Page . GotoAsync ( ExampleUrl ) ;
3023 await Expect . That ( Page ) . ToMeetPerformanceBudgetAsync ( ) ;
3124 }
3225
@@ -35,36 +28,55 @@ public async Task SimplePage_MeetsPerformanceBudget()
3528 public async Task MethodAttribute_OverridesClassBudget ( )
3629 {
3730 // The method-level budget (LCP = 10000ms) overrides the class-level budget.
38- await Fixtures . SetPageContentAsync ( Page , SimplePage ) ;
31+ await Page . GotoAsync ( ExampleUrl ) ;
3932 await Expect . That ( Page ) . ToMeetPerformanceBudgetAsync ( ) ;
4033 }
4134
4235 [ TestMethod ]
4336 public async Task LcpBelow_IndividualMetricAssertion ( )
4437 {
45- await Fixtures . SetPageContentAsync ( Page , SimplePage ) ;
38+ await Page . GotoAsync ( ExampleUrl ) ;
4639 await Expect . That ( Page ) . ToHaveLcpBelowAsync ( 5000 ) ;
4740 }
4841
4942 [ TestMethod ]
5043 public async Task FcpBelow_IndividualMetricAssertion ( )
5144 {
52- await Fixtures . SetPageContentAsync ( Page , SimplePage ) ;
45+ await Page . GotoAsync ( ExampleUrl ) ;
5346 await Expect . That ( Page ) . ToHaveFcpBelowAsync ( 5000 ) ;
5447 }
5548
49+ [ TestMethod ]
50+ public async Task TtfbBelow_ServerResponseTime ( )
51+ {
52+ await Page . GotoAsync ( ExampleUrl ) ;
53+ await Expect . That ( Page ) . ToHaveTtfbBelowAsync ( 3000 ) ;
54+ }
55+
5656 [ TestMethod ]
5757 public async Task ClsBelow_NoLayoutShift ( )
5858 {
59- await Fixtures . SetPageContentAsync ( Page , SimplePage ) ;
59+ await Page . GotoAsync ( ExampleUrl ) ;
6060 await Expect . That ( Page ) . ToHaveClsBelowAsync ( 0.5 ) ;
6161 }
6262
6363 [ TestMethod ]
6464 public async Task Not_LcpBelow_NegationAssertsThatLcpIsAtLeastThreshold ( )
6565 {
66- await Fixtures . SetPageContentAsync ( Page , SimplePage ) ;
67- // A 1x1 inline page will have LCP well above 0ms
66+ await Page . GotoAsync ( ExampleUrl ) ;
67+ // A real page will have LCP well above 0ms
6868 await Expect . That ( Page ) . Not . ToHaveLcpBelowAsync ( 0 ) ;
6969 }
70+
71+ [ TestMethod ]
72+ public async Task MultipleNavigations_EachProducesTimelineMetrics ( )
73+ {
74+ // Each GotoAsync fires the PerformanceMetricsCollector, creating a
75+ // separate annotated navigate marker on the visual runner timeline.
76+ await Page . GotoAsync ( ExampleUrl ) ;
77+ await Expect . That ( Page ) . ToHaveLcpBelowAsync ( 5000 ) ;
78+
79+ await Page . GotoAsync ( "https://www.iana.org/domains/reserved" ) ;
80+ await Expect . That ( Page ) . ToMeetPerformanceBudgetAsync ( ) ;
81+ }
7082}
0 commit comments