public async Task ShouldScrollAccordingToMouseWheel() { var waitForFunctionOptions = new WaitForFunctionOptions { PollingInterval = 50, Timeout = 1000 }; Task WaitForScrollPointAsync(DomPointInternal point) => Page.WaitForFunctionAsync( @"(x, y) => document.body.scrollLeft === x && document.body.scrollTop === y", waitForFunctionOptions, point.X, point.Y); await Page.GoToAsync( $@"{TestConstants.ServerUrl}/longText.html", WaitUntilNavigation.Networkidle0); var expectedWheelEvents = new[] { new WheelEventInternal(0, 500), new WheelEventInternal(0, -200), new WheelEventInternal(300, 0), new WheelEventInternal(-150, 0) }; var expectedScrollPoint = new DomPointInternal { X = 0, Y = 0 }; await WaitForScrollPointAsync(expectedScrollPoint); foreach (var @event in expectedWheelEvents) { await Page.Mouse.WheelAsync(@event.DeltaX, @event.DeltaY); expectedScrollPoint.Scroll(@event.DeltaX, @event.DeltaY); await WaitForScrollPointAsync(expectedScrollPoint); } }
public static async Task WaitForTruth(this Page page, string script, WaitForFunctionOptions opts = null) { var jsHandle = await page.WaitForExpressionAsync(script, opts); await jsHandle.DisposeAsync(); }