diff --git a/src/Common/Version.props b/src/Common/Version.props index 78ec838cdd..1457c97855 100644 --- a/src/Common/Version.props +++ b/src/Common/Version.props @@ -2,7 +2,7 @@ 1.45.0 $(AssemblyVersion) - 1.45.0-beta-1719505820000 + 1.45.1-beta-1719996498000 $(AssemblyVersion) $(AssemblyVersion) true diff --git a/src/Playwright.Tests/PageClockTests.cs b/src/Playwright.Tests/PageClockTests.cs index 9256fe7860..8213555cd3 100644 --- a/src/Playwright.Tests/PageClockTests.cs +++ b/src/Playwright.Tests/PageClockTests.cs @@ -54,8 +54,8 @@ public class RunForTests : PageClockTests [SetUp] public async Task RunForSetUp() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); } [PlaywrightTest("page-clock.spec.ts", "triggers immediately without specified delay")] @@ -120,7 +120,7 @@ public async Task TriggersWhenSomeThrow() [PlaywrightTest("page-clock.spec.ts", "creates updated Date while ticking")] public async Task CreatesUpdatedDateWhileTicking() { - await Page.Clock.SetSystemTimeAsync(0); + await Page.Clock.SetSystemTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime); await Page.EvaluateAsync("() => { setInterval(() => { window.stubWithNumberValue(new Date().getTime()); }, 10); }"); await Page.Clock.RunForAsync(100); Assert.AreEqual(new[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }, _calls.Select(c => c[0])); @@ -161,7 +161,7 @@ public async Task ThrowsForInvalidFormat() [PlaywrightTest("page-clock.spec.ts", "returns the current now value")] public async Task ReturnsTheCurrentNowValue() { - await Page.Clock.SetSystemTimeAsync(0); + await Page.Clock.SetSystemTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime); var value = 200; await Page.Clock.RunForAsync(value); Assert.AreEqual(value, await Page.EvaluateAsync("Date.now()")); @@ -173,8 +173,8 @@ public class FastForwardTests : PageClockTests [SetUp] public async Task FastForwardSetUp() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); } [PlaywrightTest("page-clock.spec.ts", "ignores timers which wouldn't be run")] @@ -209,14 +209,14 @@ public class StubTimersTests : PageClockTests [SetUp] public async Task StubTimersSetUp() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); } [PlaywrightTest("page-clock.spec.ts", "sets initial timestamp")] public async Task SetsInitialTimestamp() { - await Page.Clock.SetSystemTimeAsync(1400); + await Page.Clock.SetSystemTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(1400).UtcDateTime); Assert.AreEqual(1400, await Page.EvaluateAsync("Date.now()")); } @@ -288,8 +288,8 @@ public class StubTimerTests : PageClockTests [PlaywrightTest("page-clock.spec.ts", "replaces global performance.timeOrigin")] public async Task ReplacesGlobalPerformanceTimeOrigin() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 1000 }); - await Page.Clock.PauseAtAsync(2000); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime }); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(2000).UtcDateTime); var promise = Page.EvaluateAsync("async () => { const prev = performance.now(); await new Promise(f => setTimeout(f, 1000)); const next = performance.now(); return { prev, next }; }"); await Page.Clock.RunForAsync(1000); Assert.AreEqual(1000, await Page.EvaluateAsync("performance.timeOrigin")); @@ -304,7 +304,7 @@ public class PopupTests : PageClockTests [PlaywrightTest("page-clock.spec.ts", "should tick after popup")] public async Task ShouldTickAfterPopup() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); var now = new DateTime(2015, 9, 25); await Page.Clock.PauseAtAsync(now); var popupTask = Page.WaitForPopupAsync(); @@ -320,7 +320,7 @@ public async Task ShouldTickAfterPopup() [PlaywrightTest("page-clock.spec.ts", "should tick before popup")] public async Task ShouldTickBeforePopup() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); var now = new DateTime(2015, 9, 25); await Page.Clock.PauseAtAsync(now); await Page.Clock.RunForAsync(1000); @@ -357,8 +357,8 @@ public async Task ShouldNotRunTimeBeforePopupOnPause() context.Response.Headers["Content-Type"] = "text/html"; return context.Response.WriteAsync(""); }); - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); await Page.GotoAsync(Server.EmptyPage); // Wait for 2 seconds in real life to check that it is past in popup. await Page.WaitForTimeoutAsync(2000); @@ -375,7 +375,7 @@ public class SetFixedTimeTests : PageClockTests [PlaywrightTest("page-clock.spec.ts", "does not fake methods")] public async Task DoesNotFakeMethods() { - await Page.Clock.SetFixedTimeAsync(0); + await Page.Clock.SetFixedTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime); // Should not stall. await Page.EvaluateAsync("() => new Promise(f => setTimeout(f, 1))"); } @@ -383,16 +383,16 @@ public async Task DoesNotFakeMethods() [PlaywrightTest("page-clock.spec.ts", "allows setting time multiple times")] public async Task AllowsSettingTimeMultipleTimes() { - await Page.Clock.SetFixedTimeAsync(100); + await Page.Clock.SetFixedTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(100).UtcDateTime); Assert.AreEqual(100, await Page.EvaluateAsync("Date.now()")); - await Page.Clock.SetFixedTimeAsync(200); + await Page.Clock.SetFixedTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(200).UtcDateTime); Assert.AreEqual(200, await Page.EvaluateAsync("Date.now()")); } [PlaywrightTest("page-clock.spec.ts", "fixed time is not affected by clock manipulation")] public async Task FixedTimeIsNotAffectedByClockManipulation() { - await Page.Clock.SetFixedTimeAsync(100); + await Page.Clock.SetFixedTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(100).UtcDateTime); Assert.AreEqual(100, await Page.EvaluateAsync("Date.now()")); await Page.Clock.FastForwardAsync(20); Assert.AreEqual(100, await Page.EvaluateAsync("Date.now()")); @@ -401,9 +401,9 @@ public async Task FixedTimeIsNotAffectedByClockManipulation() [PlaywrightTest("page-clock.spec.ts", "allows installing fake timers after setting time")] public async Task AllowsInstallingFakeTimersAfterSettingTime() { - await Page.Clock.SetFixedTimeAsync(100); + await Page.Clock.SetFixedTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(100).UtcDateTime); Assert.AreEqual(100, await Page.EvaluateAsync("Date.now()")); - await Page.Clock.SetFixedTimeAsync(200); + await Page.Clock.SetFixedTimeAsync(DateTimeOffset.FromUnixTimeMilliseconds(200).UtcDateTime); await Page.EvaluateAsync("() => { setTimeout(() => window.stubWithNumberValue(Date.now()), 0); }"); await Page.Clock.RunForAsync(0); Assert.AreEqual(1, _calls.Count); @@ -416,7 +416,7 @@ public class WhileRunningTests : PageClockTests [PlaywrightTest("page-clock.spec.ts", "should progress time")] public async Task ShouldProgressTime() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); await Page.WaitForTimeoutAsync(1000); var now = await Page.EvaluateAsync("Date.now()"); @@ -427,7 +427,7 @@ public async Task ShouldProgressTime() [PlaywrightTest("page-clock.spec.ts", "should runFor")] public async Task ShouldRunFor() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); await Page.Clock.RunForAsync(10000); var now = await Page.EvaluateAsync("Date.now()"); @@ -438,7 +438,7 @@ public async Task ShouldRunFor() [PlaywrightTest("page-clock.spec.ts", "should fastForward")] public async Task ShouldFastForward() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); await Page.Clock.FastForwardAsync(10000); var now = await Page.EvaluateAsync("Date.now()"); @@ -449,7 +449,7 @@ public async Task ShouldFastForward() [PlaywrightTest("page-clock.spec.ts", "should fastForwardTo")] public async Task ShouldFastForwardTo() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); await Page.Clock.FastForwardAsync(10000); var now = await Page.EvaluateAsync("Date.now()"); @@ -460,9 +460,9 @@ public async Task ShouldFastForwardTo() [PlaywrightTest("page-clock.spec.ts", "should pause")] public async Task ShouldPause() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); await Page.WaitForTimeoutAsync(1000); await Page.Clock.ResumeAsync(); var now = await Page.EvaluateAsync("Date.now()"); @@ -473,9 +473,9 @@ public async Task ShouldPause() [PlaywrightTest("page-clock.spec.ts", "should pause and fastForward")] public async Task ShouldPauseAndFastForward() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); await Page.Clock.FastForwardAsync(1000); var now = await Page.EvaluateAsync("Date.now()"); Assert.AreEqual(2000, now); @@ -484,9 +484,9 @@ public async Task ShouldPauseAndFastForward() [PlaywrightTest("page-clock.spec.ts", "should set system time on pause")] public async Task ShouldSetSystemTimeOnPause() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); var now = await Page.EvaluateAsync("Date.now()"); Assert.AreEqual(1000, now); } @@ -497,9 +497,9 @@ public class WhileOnPauseTests : PageClockTests [PlaywrightTest("page-clock.spec.ts", "fastForward should not run nested immediate")] public async Task FastForwardShouldNotRunNestedImmediate() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); await Page.EvaluateAsync("() => { setTimeout(() => { window.stubWithStringValue('outer'); setTimeout(() => window.stubWithStringValue('inner'), 0); }, 1000); }"); await Page.Clock.FastForwardAsync(1000); Assert.AreEqual(1, _calls.Count); @@ -512,9 +512,9 @@ public async Task FastForwardShouldNotRunNestedImmediate() [PlaywrightTest("page-clock.spec.ts", "runFor should not run nested immediate")] public async Task RunForShouldNotRunNestedImmediate() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); await Page.EvaluateAsync("() => { setTimeout(() => { window.stubWithStringValue('outer'); setTimeout(() => window.stubWithStringValue('inner'), 0); }, 1000); }"); await Page.Clock.RunForAsync(1000); Assert.AreEqual(1, _calls.Count); @@ -527,9 +527,9 @@ public async Task RunForShouldNotRunNestedImmediate() [PlaywrightTest("page-clock.spec.ts", "runFor should not run nested immediate from microtask")] public async Task RunForShouldNotRunNestedImmediateFromMicrotask() { - await Page.Clock.InstallAsync(new() { TimeInt64 = 0 }); + await Page.Clock.InstallAsync(new() { TimeDate = DateTimeOffset.FromUnixTimeMilliseconds(0).UtcDateTime }); await Page.GotoAsync("data:text/html,"); - await Page.Clock.PauseAtAsync(1000); + await Page.Clock.PauseAtAsync(DateTimeOffset.FromUnixTimeMilliseconds(1000).UtcDateTime); await Page.EvaluateAsync("() => { setTimeout(() => { window.stubWithStringValue('outer'); Promise.resolve().then(() => setTimeout(() => window.stubWithStringValue('inner'), 0)); }, 1000); }"); await Page.Clock.RunForAsync(1000); Assert.AreEqual(1, _calls.Count); diff --git a/src/Playwright/API/Generated/IClock.cs b/src/Playwright/API/Generated/IClock.cs index f98361d791..48d30e3f7b 100644 --- a/src/Playwright/API/Generated/IClock.cs +++ b/src/Playwright/API/Generated/IClock.cs @@ -150,9 +150,8 @@ public partial interface IClock /// await page.Clock.PauseAtAsync("2020-02-02"); /// /// - /// - /// - Task PauseAtAsync(long time); + /// Time to pause at. + Task PauseAtAsync(DateTime time); /// /// @@ -170,30 +169,9 @@ public partial interface IClock /// await page.Clock.PauseAtAsync("2020-02-02"); /// /// - /// - /// + /// Time to pause at. Task PauseAtAsync(string time); - /// - /// - /// Advance the clock by jumping forward in time and pause the time. Once this method - /// is called, no timers are fired unless , , - /// or is called. - /// - /// - /// Only fires due timers at most once. This is equivalent to user closing the laptop - /// lid for a while and reopening it at the specified time and pausing. - /// - /// **Usage** - /// - /// await page.Clock.PauseAtAsync(DateTime.Parse("2020-02-02"));
- /// await page.Clock.PauseAtAsync("2020-02-02"); - ///
- ///
- /// - /// - Task PauseAtAsync(DateTime time); - /// /// /// Resumes timers. Once this method is called, time resumes flowing, timers are fired @@ -202,21 +180,6 @@ public partial interface IClock /// Task ResumeAsync(); - /// - /// - /// Makes Date.now and new Date() return fixed fake time at all times, - /// keeps all the timers running. - /// - /// **Usage** - /// - /// await page.Clock.SetFixedTimeAsync(DateTime.Now);
- /// await page.Clock.SetFixedTimeAsync(new DateTime(2020, 2, 2));
- /// await page.Clock.SetFixedTimeAsync("2020-02-02"); - ///
- ///
- /// Time to be set. - Task SetFixedTimeAsync(long time); - /// /// /// Makes Date.now and new Date() return fixed fake time at all times, @@ -256,21 +219,7 @@ public partial interface IClock /// await page.Clock.SetSystemTimeAsync("2020-02-02"); /// /// - /// - /// - Task SetSystemTimeAsync(long time); - - /// - /// Sets current system time but does not trigger any timers. - /// **Usage** - /// - /// await page.Clock.SetSystemTimeAsync(DateTime.Now);
- /// await page.Clock.SetSystemTimeAsync(new DateTime(2020, 2, 2));
- /// await page.Clock.SetSystemTimeAsync("2020-02-02"); - ///
- ///
- /// - /// + /// Time to be set. Task SetSystemTimeAsync(string time); /// @@ -282,8 +231,7 @@ public partial interface IClock /// await page.Clock.SetSystemTimeAsync("2020-02-02"); /// /// - /// - /// + /// Time to be set. Task SetSystemTimeAsync(DateTime time); } diff --git a/src/Playwright/API/Generated/Options/ClockInstallOptions.cs b/src/Playwright/API/Generated/Options/ClockInstallOptions.cs index 6bde6b4090..b13375f72e 100644 --- a/src/Playwright/API/Generated/Options/ClockInstallOptions.cs +++ b/src/Playwright/API/Generated/Options/ClockInstallOptions.cs @@ -42,7 +42,6 @@ public ClockInstallOptions(ClockInstallOptions clone) Time = clone.Time; TimeDate = clone.TimeDate; - TimeInt64 = clone.TimeInt64; TimeString = clone.TimeString; } @@ -54,10 +53,6 @@ public ClockInstallOptions(ClockInstallOptions clone) [JsonPropertyName("timeDate")] public DateTime? TimeDate { get; set; } - /// Time to initialize with, current system time by default. - [JsonPropertyName("timeInt64")] - public long? TimeInt64 { get; set; } - /// Time to initialize with, current system time by default. [JsonPropertyName("timeString")] public string? TimeString { get; set; } diff --git a/src/Playwright/Core/Clock.cs b/src/Playwright/Core/Clock.cs index c02e69ae55..189de09bc9 100644 --- a/src/Playwright/Core/Clock.cs +++ b/src/Playwright/Core/Clock.cs @@ -37,10 +37,6 @@ public async Task InstallAsync(ClockInstallOptions options = null) { args = ParseTime(options.Time ?? options.TimeString); } - else if (options.TimeInt64 != null) - { - args = ParseTime(options.TimeInt64.Value); - } else if (options.TimeDate != null) { args = ParseTime(options.TimeDate.Value); @@ -54,9 +50,6 @@ private static Dictionary ParseTime(string timeString) private static Dictionary ParseTime(DateTime? timeDate) => new() { ["timeNumber"] = ((DateTimeOffset)timeDate.Value).ToUnixTimeMilliseconds() }; - private static Dictionary ParseTime(long timeInt64) - => new() { ["timeNumber"] = timeInt64 }; - private Dictionary ParseTicks(long ticks) => new() { ["ticksNumber"] = ticks }; @@ -69,9 +62,6 @@ public Task FastForwardAsync(long ticks) public Task FastForwardAsync(string ticks) => browserContext.SendMessageToServerAsync("clockFastForward", ParseTicks(ticks)); - public Task PauseAtAsync(long time) - => browserContext.SendMessageToServerAsync("clockPauseAt", ParseTime(time)); - public Task PauseAtAsync(string time) => browserContext.SendMessageToServerAsync("clockPauseAt", ParseTime(time)); @@ -87,18 +77,12 @@ public Task RunForAsync(long ticks) public Task RunForAsync(string ticks) => browserContext.SendMessageToServerAsync("clockRunFor", ParseTicks(ticks)); - public Task SetFixedTimeAsync(long time) - => browserContext.SendMessageToServerAsync("clockSetFixedTime", ParseTime(time)); - public Task SetFixedTimeAsync(string time) => browserContext.SendMessageToServerAsync("clockSetFixedTime", ParseTime(time)); public Task SetFixedTimeAsync(DateTime time) => browserContext.SendMessageToServerAsync("clockSetFixedTime", ParseTime(time)); - public Task SetSystemTimeAsync(long time) - => browserContext.SendMessageToServerAsync("clockSetSystemTime", ParseTime(time)); - public Task SetSystemTimeAsync(string time) => browserContext.SendMessageToServerAsync("clockSetSystemTime", ParseTime(time));