How to use ShouldWorkWithContentFrame method of Microsoft.Playwright.Tests.FrameFrameElementTests class

Best Playwright-dotnet code snippet using Microsoft.Playwright.Tests.FrameFrameElementTests.ShouldWorkWithContentFrame

Run Playwright-dotnet automation tests on LambdaTest cloud grid

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

FrameFrameElementTests.cs

Source: FrameFrameElementTests.cs Github

copy
1/*
2 * MIT License
3 *
4 * Copyright (c) Microsoft Corporation.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25using System.Threading.Tasks;
26using Microsoft.Playwright.NUnit;
27using NUnit.Framework;
28
29namespace Microsoft.Playwright.Tests
30{
31    public class FrameFrameElementTests : PageTestEx
32    {
33        [PlaywrightTest("frame-frame-element.spec.ts", "should work")]
34        public async Task ShouldWork()
35        {
36            await Page.GotoAsync(Server.EmptyPage);
37            var frame1 = await FrameUtils.AttachFrameAsync(Page, "frame1", Server.EmptyPage);
38            await FrameUtils.AttachFrameAsync(Page, "frame2", Server.EmptyPage);
39            var frame3 = await FrameUtils.AttachFrameAsync(Page, "frame3", Server.EmptyPage);
40
41            var frame1handle1 = await Page.QuerySelectorAsync("#frame1");
42            var frame1handle2 = await frame1.FrameElementAsync();
43            var frame3handle1 = await Page.QuerySelectorAsync("#frame3");
44            var frame3handle2 = await frame3.FrameElementAsync();
45
46            Assert.True(await frame1handle1.EvaluateAsync<bool>("(a, b) => a === b", frame1handle2));
47            Assert.True(await frame3handle1.EvaluateAsync<bool>("(a, b) => a === b", frame3handle2));
48            Assert.False(await frame1handle1.EvaluateAsync<bool>("(a, b) => a === b", frame3handle2));
49
50            var windowHandle = await Page.MainFrame.EvaluateHandleAsync("() => window");
51            Assert.NotNull(windowHandle);
52        }
53
54        [PlaywrightTest("frame-frame-element.spec.ts", "should work with contentFrame")]
55        public async Task ShouldWorkWithContentFrame()
56        {
57            await Page.GotoAsync(Server.EmptyPage);
58            var frame = await FrameUtils.AttachFrameAsync(Page, "frame1", Server.EmptyPage);
59            var handle = await frame.FrameElementAsync();
60            var contentFrame = await handle.ContentFrameAsync();
61
62            Assert.AreEqual(contentFrame, frame);
63        }
64
65        [PlaywrightTest("frame-frame-element.spec.ts", "should throw when detached")]
66        public async Task ShouldThrowWhenDetached()
67        {
68            await Page.GotoAsync(Server.EmptyPage);
69            var frame1 = await FrameUtils.AttachFrameAsync(Page, "frame1", Server.EmptyPage);
70            await Page.EvalOnSelectorAsync("#frame1", "e => e.remove()");
71
72            var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => frame1.FrameElementAsync());
73
74            Assert.AreEqual("Frame has been detached.", exception.Message);
75        }
76    }
77}
78
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 FrameFrameElementTests

Trigger ShouldWorkWithContentFrame code on LambdaTest Cloud Grid

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