diff --git a/lib/PuppeteerSharp.Tests/PageTests/WaitForNetworkIdleTests.cs b/lib/PuppeteerSharp.Tests/PageTests/WaitForNetworkIdleTests.cs index 2ad1881bc..a6b638b40 100644 --- a/lib/PuppeteerSharp.Tests/PageTests/WaitForNetworkIdleTests.cs +++ b/lib/PuppeteerSharp.Tests/PageTests/WaitForNetworkIdleTests.cs @@ -18,11 +18,16 @@ public WaitForNetworkIdleTests(ITestOutputHelper output) : base(output) [PuppeteerFact] public async Task ShouldWork() { - var t1 = DateTime.Now; - var t2 = DateTime.Now; + var t1 = DateTime.UtcNow; + var t2 = DateTime.UtcNow; await Page.GoToAsync(TestConstants.EmptyPage); - var task = Page.WaitForNetworkIdleAsync().ContinueWith(x => t1 = DateTime.Now); + var task = Page.WaitForNetworkIdleAsync() + .ContinueWith(x => + { + if (x.IsFaulted) throw x.Exception; + return t1 = DateTime.UtcNow; + }); await Task.WhenAll( task, @@ -35,7 +40,11 @@ await Promise.all([ await fetch('/digits/3.png'); await new Promise((resolve) => setTimeout(resolve, 200)); await fetch('/digits/4.png'); - }").ContinueWith(x => t2 = DateTime.Now) + }").ContinueWith(x => + { + if (x.IsFaulted) throw x.Exception; + t2 = DateTime.UtcNow; + }) ); Assert.True(t1 > t2); @@ -59,11 +68,16 @@ public async Task ShouldRespectTimeout() [SkipBrowserFact(skipFirefox: true)] public async Task ShouldRespectIdleTimeout() { - var t1 = DateTime.Now; - var t2 = DateTime.Now; + var t1 = DateTime.UtcNow; + var t2 = DateTime.UtcNow; await Page.GoToAsync(TestConstants.EmptyPage); - var task = Page.WaitForNetworkIdleAsync(new WaitForNetworkIdleOptions { IdleTime = 10 }).ContinueWith(x => t1 = DateTime.Now); + var task = Page.WaitForNetworkIdleAsync(new WaitForNetworkIdleOptions { IdleTime = 10 }) + .ContinueWith(x => + { + if (x.IsFaulted) throw x.Exception; + return t1 = DateTime.UtcNow; + }); await Task.WhenAll( task, @@ -73,7 +87,11 @@ await Promise.all([ fetch('/digits/2.png'), ]); await new Promise((resolve) => setTimeout(resolve, 250)); - }").ContinueWith(x => t2 = DateTime.Now) + }").ContinueWith(x => + { + if (x.IsFaulted) throw x.Exception; + return t2 = DateTime.UtcNow; + }) ); Assert.True(t2 > t1); diff --git a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForFunctionTests.cs b/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForFunctionTests.cs index 11f22d781..e6d678170 100644 --- a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForFunctionTests.cs +++ b/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForFunctionTests.cs @@ -32,7 +32,7 @@ await Page.WaitForFunctionAsync(@"() => public async Task ShouldPollOnInterval() { var success = false; - var startTime = DateTime.Now; + var startTime = DateTime.UtcNow; var polling = 100; var watchdog = Page.WaitForFunctionAsync("() => window.__FOO === 'hit'", new WaitForFunctionOptions { PollingInterval = polling }) .ContinueWith(_ => success = true); @@ -40,7 +40,7 @@ public async Task ShouldPollOnInterval() Assert.False(success); await Page.EvaluateExpressionAsync("document.body.appendChild(document.createElement('div'))"); await watchdog; - Assert.True((DateTime.Now - startTime).TotalMilliseconds > polling / 2); + Assert.True((DateTime.UtcNow - startTime).TotalMilliseconds > polling / 2); } [PuppeteerTest("waittask.spec.ts", "Frame.waitForFunction", "should poll on interval async")] @@ -48,7 +48,7 @@ public async Task ShouldPollOnInterval() public async Task ShouldPollOnIntervalAsync() { var success = false; - var startTime = DateTime.Now; + var startTime = DateTime.UtcNow; var polling = 100; var watchdog = Page.WaitForFunctionAsync("async () => window.__FOO === 'hit'", new WaitForFunctionOptions { PollingInterval = polling }) .ContinueWith(_ => success = true); @@ -56,7 +56,7 @@ public async Task ShouldPollOnIntervalAsync() Assert.False(success); await Page.EvaluateExpressionAsync("document.body.appendChild(document.createElement('div'))"); await watchdog; - Assert.True((DateTime.Now - startTime).TotalMilliseconds > polling / 2); + Assert.True((DateTime.UtcNow - startTime).TotalMilliseconds > polling / 2); } [PuppeteerTest("waittask.spec.ts", "Frame.waitForFunction", "should poll on mutation")] diff --git a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForTimeoutTests.cs b/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForTimeoutTests.cs index 920b23a76..fbdbe41eb 100644 --- a/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForTimeoutTests.cs +++ b/lib/PuppeteerSharp.Tests/WaitTaskTests/FrameWaitForTimeoutTests.cs @@ -19,10 +19,10 @@ public FrameWaitForTimeoutTests(ITestOutputHelper output) : base(output) public async Task WaitsForTheGivenTimeoutBeforeResolving() { await Page.GoToAsync(TestConstants.EmptyPage); - var startTime = DateTime.Now; + var startTime = DateTime.UtcNow; await Page.MainFrame.WaitForTimeoutAsync(1000); - Assert.True((DateTime.Now - startTime).TotalMilliseconds > 700); - Assert.True((DateTime.Now - startTime).TotalMilliseconds < 1300); + Assert.True((DateTime.UtcNow - startTime).TotalMilliseconds > 700); + Assert.True((DateTime.UtcNow - startTime).TotalMilliseconds < 1300); } } } diff --git a/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTests.cs b/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTests.cs index 4f803b4e9..5b3406e64 100644 --- a/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTests.cs +++ b/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTests.cs @@ -56,10 +56,10 @@ public async Task ShouldNotAllowYouToSelectAnElementWithSingleSlashXpath() [PuppeteerFact] public async Task ShouldTimeout() { - var startTime = DateTime.Now; + var startTime = DateTime.UtcNow; var timeout = 42; await Page.WaitForTimeoutAsync(timeout); - Assert.True((DateTime.Now - startTime).TotalMilliseconds > timeout / 2); + Assert.True((DateTime.UtcNow - startTime).TotalMilliseconds > timeout / 2); } [PuppeteerTest("waittask.spec.ts", "Page.waitFor", "should work with multiline body")] diff --git a/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTimeoutTests.cs b/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTimeoutTests.cs index 3764fc9a6..6993b6983 100644 --- a/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTimeoutTests.cs +++ b/lib/PuppeteerSharp.Tests/WaitTaskTests/PageWaitForTimeoutTests.cs @@ -19,10 +19,10 @@ public PageWaitForTimeoutTests(ITestOutputHelper output) : base(output) public async Task WaitsForTheGivenTimeoutBeforeResolving() { await Page.GoToAsync(TestConstants.EmptyPage); - var startTime = DateTime.Now; + var startTime = DateTime.UtcNow; await Page.WaitForTimeoutAsync(1000); - Assert.True((DateTime.Now - startTime).TotalMilliseconds > 700); - Assert.True((DateTime.Now - startTime).TotalMilliseconds < 1300); + Assert.True((DateTime.UtcNow - startTime).TotalMilliseconds > 700); + Assert.True((DateTime.UtcNow - startTime).TotalMilliseconds < 1300); } } }