How to use ShouldFailWhenFrameDetaches method of PuppeteerSharp.Tests.NavigationTests.FrameWaitForNavigationTests class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Tests.NavigationTests.FrameWaitForNavigationTests.ShouldFailWhenFrameDetaches

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

FrameWaitForNavigationTests.cs

Source: FrameWaitForNavigationTests.cs Github

copy
1using System.Linq;
2using System.Net;
3using System.Threading.Tasks;
4using PuppeteerSharp.Tests.Attributes;
5using PuppeteerSharp.Xunit;
6using Xunit;
7using Xunit.Abstractions;
8
9namespace PuppeteerSharp.Tests.NavigationTests
10{
11    [Collection(TestConstants.TestFixtureCollectionName)]
12    public class FrameWaitForNavigationTests : PuppeteerPageBaseTest
13    {
14        public FrameWaitForNavigationTests(ITestOutputHelper output) : base(output)
15        {
16        }
17
18        [PuppeteerTest("navigation.spec.ts", "Frame.waitForNavigation", "should work")]
19        [SkipBrowserFact(skipFirefox: true)]
20        public async Task ShouldWork()
21        {
22            await Page.GoToAsync(TestConstants.ServerUrl + "/frames/one-frame.html");
23            var frame = Page.FirstChildFrame();
24            var waitForNavigationResult = frame.WaitForNavigationAsync();
25
26            await Task.WhenAll(
27                waitForNavigationResult,
28                frame.EvaluateFunctionAsync("url => window.location.href = url", TestConstants.ServerUrl + "/grid.html")
29            );
30            var response = await waitForNavigationResult;
31            Assert.Equal(HttpStatusCode.OK, response.Status);
32            Assert.Contains("grid.html", response.Url);
33            Assert.Same(frame, response.Frame);
34            Assert.Contains("/frames/one-frame.html", Page.Url);
35        }
36
37        [PuppeteerTest("navigation.spec.ts", "Frame.waitForNavigation", "should fail when frame detaches")]
38        [PuppeteerFact]
39        public async Task ShouldFailWhenFrameDetaches()
40        {
41            await Page.GoToAsync(TestConstants.ServerUrl + "/frames/one-frame.html");
42            var frame = Page.FirstChildFrame();
43            Server.SetRoute("/empty.html", _ => Task.Delay(10000));
44            var waitForNavigationResult = frame.WaitForNavigationAsync();
45            await Task.WhenAll(
46                Server.WaitForRequest("/empty.html"),
47                frame.EvaluateFunctionAsync($"() => window.location = '{TestConstants.EmptyPage}'"));
48
49            await Page.QuerySelectorAsync("iframe").EvaluateFunctionAsync("frame => frame.remove()");
50            var exception = await Assert.ThrowsAsync<PuppeteerException>(() => waitForNavigationResult);
51            Assert.Equal("Navigating frame was detached", exception.Message);
52        }
53    }
54}
55
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in FrameWaitForNavigationTests

Trigger ShouldFailWhenFrameDetaches code on LambdaTest Cloud Grid

Execute automation tests with ShouldFailWhenFrameDetaches on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)