How to use ShouldExposeVideoPath method of Microsoft.Playwright.Tests.ScreencastTests class

Best Playwright-dotnet code snippet using Microsoft.Playwright.Tests.ScreencastTests.ShouldExposeVideoPath

Run Playwright-dotnet automation tests on LambdaTest cloud grid

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

ScreencastTests.cs

Source: ScreencastTests.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.IO;
26using System.Threading.Tasks;
27using Microsoft.Playwright.NUnit;
28using NUnit.Framework;
29
30namespace Microsoft.Playwright.Tests
31{
32    ///<playwright-file>screencast.spec.ts</playwright-file>
33    public class ScreencastTests : BrowserTestEx
34    {
35        [PlaywrightTest("screencast.spec.ts", "videoSize should require videosPath")]
36        public async Task VideoSizeShouldRequireVideosPath()
37        {
38            var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => Browser.NewContextAsync(new()
39            {
40                RecordVideoSize = new() { Height = 100, Width = 100 }
41            }));
42
43            StringAssert.Contains("\"RecordVideoSize\" option requires \"RecordVideoDir\" to be specified", exception.Message);
44        }
45
46        public async Task ShouldWorkWithoutASize()
47        {
48            using var tempDirectory = new TempDirectory();
49            var context = await Browser.NewContextAsync(new()
50            {
51                RecordVideoDir = tempDirectory.Path
52            });
53
54            var page = await context.NewPageAsync();
55            await page.EvaluateAsync("() => document.body.style.backgroundColor = 'red'");
56            await Task.Delay(1000);
57            await context.CloseAsync();
58
59            Assert.IsNotEmpty(new DirectoryInfo(tempDirectory.Path).GetFiles("*.webm"));
60        }
61
62        [PlaywrightTest("screencast.spec.ts", "should capture static page")]
63        [Skip(SkipAttribute.Targets.Webkit | SkipAttribute.Targets.Windows)]
64        public async Task ShouldCaptureStaticPage()
65        {
66            using var tempDirectory = new TempDirectory();
67            var context = await Browser.NewContextAsync(new()
68            {
69                RecordVideoDir = tempDirectory.Path,
70                RecordVideoSize = new() { Height = 100, Width = 100 }
71            });
72
73            var page = await context.NewPageAsync();
74            await page.EvaluateAsync("() => document.body.style.backgroundColor = 'red'");
75            await Task.Delay(1000);
76            await context.CloseAsync();
77
78            Assert.IsNotEmpty(new DirectoryInfo(tempDirectory.Path).GetFiles("*.webm"));
79        }
80
81        [PlaywrightTest("screencast.spec.ts", "should expose video path")]
82        public async Task ShouldExposeVideoPath()
83        {
84            using var tempDirectory = new TempDirectory();
85            var context = await Browser.NewContextAsync(new()
86            {
87                RecordVideoDir = tempDirectory.Path,
88                RecordVideoSize = new() { Height = 100, Width = 100 }
89            });
90
91            var page = await context.NewPageAsync();
92            await page.EvaluateAsync("() => document.body.style.backgroundColor = 'red'");
93            string path = await page.Video.PathAsync();
94            StringAssert.Contains(tempDirectory.Path, path);
95            await context.CloseAsync();
96
97            Assert.True(new FileInfo(path).Exists);
98        }
99
100        [PlaywrightTest("screencast.spec.ts", "should expose video path blank page")]
101        public async Task ShouldExposeVideoPathBlankPage()
102        {
103            using var tempDirectory = new TempDirectory();
104            var context = await Browser.NewContextAsync(new()
105            {
106                RecordVideoDir = tempDirectory.Path,
107                RecordVideoSize = new() { Height = 100, Width = 100 }
108            });
109
110            var page = await context.NewPageAsync();
111            string path = await page.Video.PathAsync();
112            StringAssert.Contains(tempDirectory.Path, path);
113            await context.CloseAsync();
114
115            Assert.True(new FileInfo(path).Exists);
116        }
117
118        [PlaywrightTest("screencast.spec.ts", "should expose video path blank popup")]
119        [Ignore("We don't need to test video details")]
120        public void ShouldExposeVideoPathBlankPopup()
121        {
122        }
123
124        [PlaywrightTest("screencast.spec.ts", "should capture navigation")]
125        [Ignore("We don't need to test video details")]
126        public void ShouldCaptureNavigation()
127        {
128        }
129
130        [PlaywrightTest("screencast.spec.ts", "should capture css transformation")]
131        [Ignore("We don't need to test video details")]
132        public void ShouldCaptureCssTransformation()
133        {
134        }
135
136        [PlaywrightTest("screencast.spec.ts", "should work for popups")]
137        [Ignore("We don't need to test video details")]
138        public void ShouldWorkForPopups()
139        {
140        }
141
142        [PlaywrightTest("screencast.spec.ts", "should scale frames down to the requested size")]
143        [Ignore("We don't need to test video details")]
144        public void ShouldScaleFramesDownToTheRequestedSize()
145        {
146        }
147
148        [PlaywrightTest("screencast.spec.ts", "should use viewport as default size")]
149        [Ignore("We don't need to test video details")]
150        public void ShouldUseViewportAsDefaultSize()
151        {
152        }
153
154        [PlaywrightTest("screencast.spec.ts", "should be 1280x720 by default")]
155        [Ignore("We don't need to test video details")]
156        public void ShouldBe1280x720ByDefault()
157        {
158        }
159
160        [PlaywrightTest("screencast.spec.ts", "should capture static page in persistent context")]
161        [Skip(SkipAttribute.Targets.Webkit, SkipAttribute.Targets.Firefox)]
162        public async Task ShouldCaptureStaticPageInPersistentContext()
163        {
164            using var userDirectory = new TempDirectory();
165            using var tempDirectory = new TempDirectory();
166            var context = await BrowserType.LaunchPersistentContextAsync(userDirectory.Path, new()
167            {
168                RecordVideoDir = tempDirectory.Path,
169                RecordVideoSize = new() { Height = 100, Width = 100 },
170            });
171
172            var page = await context.NewPageAsync();
173            await page.EvaluateAsync("() => document.body.style.backgroundColor = 'red'");
174            await Task.Delay(1000);
175            await context.CloseAsync();
176
177            Assert.IsNotEmpty(new DirectoryInfo(tempDirectory.Path).GetFiles("*.webm"));
178        }
179    }
180}
181
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 ShouldExposeVideoPath code on LambdaTest Cloud Grid

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