How to use ShouldFireForIframes method of Microsoft.Playwright.Tests.PageEventRequestTests class

Best Playwright-dotnet code snippet using Microsoft.Playwright.Tests.PageEventRequestTests.ShouldFireForIframes

Run Playwright-dotnet automation tests on LambdaTest cloud grid

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

PageEventRequestTests.cs

Source: PageEventRequestTests.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) 2020 Darío Kondratiuk
5 * Modifications copyright (c) Microsoft Corporation.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 */
25
26using System.Collections.Generic;
27using System.Threading.Tasks;
28using Microsoft.Playwright.NUnit;
29using NUnit.Framework;
30
31namespace Microsoft.Playwright.Tests
32{
33    public class PageEventRequestTests : PageTestEx
34    {
35        [PlaywrightTest("page-event-request.spec.ts", "should fire for navigation requests")]
36        public async Task ShouldFireForNavigationRequests()
37        {
38            var requests = new List<IRequest>();
39            Page.Request += (_, e) => requests.Add(e);
40            await Page.GotoAsync(Server.EmptyPage);
41            Assert.That(requests, Has.Count.EqualTo(1));
42        }
43
44        [PlaywrightTest("page-event-request.spec.ts", "should fire for iframes")]
45        public async Task ShouldFireForIframes()
46        {
47            var requests = new List<IRequest>();
48            Page.Request += (_, e) => requests.Add(e);
49            await Page.GotoAsync(Server.EmptyPage);
50            await FrameUtils.AttachFrameAsync(Page, "frame1", Server.EmptyPage);
51            Assert.AreEqual(2, requests.Count);
52        }
53
54        [PlaywrightTest("page-event-request.spec.ts", "should fire for fetches")]
55        public async Task ShouldFireForFetches()
56        {
57            var requests = new List<IRequest>();
58            Page.Request += (_, e) => requests.Add(e);
59            await Page.GotoAsync(Server.EmptyPage);
60            await Page.EvaluateAsync("fetch('/empty.html')");
61            Assert.AreEqual(2, requests.Count);
62        }
63
64        [PlaywrightTest("page-event-request.spec.ts", "should report requests and responses handled by service worker")]
65        public async Task ShouldReportRequestsAndResponsesHandledByServiceWorker()
66        {
67            await Page.GotoAsync(Server.Prefix + "/serviceworkers/fetchdummy/sw.html");
68            await Page.EvaluateAsync("() => window.activationPromise");
69
70            var (request, swResponse) = await TaskUtils.WhenAll(
71                Page.WaitForRequestAsync("**/*"),
72                Page.EvaluateAsync<string>("() => fetchDummy('foo')"));
73
74            Assert.AreEqual("responseFromServiceWorker:foo", swResponse);
75            Assert.AreEqual(Server.Prefix + "/serviceworkers/fetchdummy/foo", request.Url);
76            var response = await request.ResponseAsync();
77            Assert.AreEqual(Server.Prefix + "/serviceworkers/fetchdummy/foo", response.Url);
78            Assert.AreEqual("responseFromServiceWorker:foo", await response.TextAsync());
79        }
80    }
81}
82
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

Trigger ShouldFireForIframes code on LambdaTest Cloud Grid

Execute automation tests with ShouldFireForIframes 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)