Best Playwright-dotnet code snippet using Microsoft.Playwright.NUnit.SkipAttribute.SkipAttribute
PermissionsTests.cs
Source:PermissionsTests.cs
...30{31 public class PermissionsTests : PageTestEx32 {33 [PlaywrightTest("permissions.spec.ts", "should be prompt by default")]34 [Skip(SkipAttribute.Targets.Webkit)]35 public async Task ShouldBePromptByDefault()36 {37 await Page.GotoAsync(Server.EmptyPage);38 Assert.AreEqual("prompt", await GetPermissionAsync(Page, "geolocation"));39 }40 [PlaywrightTest("permissions.spec.ts", "should deny permission when not listed")]41 [Skip(SkipAttribute.Targets.Webkit)]42 public async Task ShouldDenyPermissionWhenNotListed()43 {44 await Page.GotoAsync(Server.EmptyPage);45 await Context.GrantPermissionsAsync(Array.Empty<string>(), new() { Origin = Server.EmptyPage });46 Assert.AreEqual("denied", await GetPermissionAsync(Page, "geolocation"));47 }48 [PlaywrightTest("permissions.spec.ts", "should fail when bad permission is given")]49 public async Task ShouldFailWhenBadPermissionIsGiven()50 {51 await Page.GotoAsync(Server.EmptyPage);52 await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() =>53 Context.GrantPermissionsAsync(new[] { "foo" }, new() { Origin = Server.EmptyPage }));54 }55 [PlaywrightTest("permissions.spec.ts", "should grant geolocation permission when listed")]56 [Skip(SkipAttribute.Targets.Webkit)]57 public async Task ShouldGrantGeolocationPermissionWhenListed()58 {59 await Page.GotoAsync(Server.EmptyPage);60 await Context.GrantPermissionsAsync(new[] { "geolocation" });61 Assert.AreEqual("granted", await GetPermissionAsync(Page, "geolocation"));62 }63 [PlaywrightTest("permissions.spec.ts", "should grant notifications permission when listed")]64 [Skip(SkipAttribute.Targets.Webkit)]65 public async Task ShouldGrantNotificationsPermissionWhenListed()66 {67 await Page.GotoAsync(Server.EmptyPage);68 await Context.GrantPermissionsAsync(new[] { "notifications" });69 Assert.AreEqual("granted", await GetPermissionAsync(Page, "notifications"));70 }71 [PlaywrightTest("permissions.spec.ts", "should accumulate when adding")]72 [Skip(SkipAttribute.Targets.Webkit)]73 public async Task ShouldAccumulateWhenAdding()74 {75 await Page.GotoAsync(Server.EmptyPage);76 await Context.GrantPermissionsAsync(new[] { "geolocation" });77 await Context.GrantPermissionsAsync(new[] { "notifications" });78 Assert.AreEqual("granted", await GetPermissionAsync(Page, "geolocation"));79 Assert.AreEqual("granted", await GetPermissionAsync(Page, "notifications"));80 }81 [PlaywrightTest("permissions.spec.ts", "should clear permissions")]82 [Skip(SkipAttribute.Targets.Webkit)]83 public async Task ShouldClearPermissions()84 {85 await Page.GotoAsync(Server.EmptyPage);86 await Context.GrantPermissionsAsync(new[] { "geolocation" });87 Assert.AreEqual("granted", await GetPermissionAsync(Page, "geolocation"));88 await Context.ClearPermissionsAsync();89 await Context.GrantPermissionsAsync(new[] { "notifications" });90 Assert.AreEqual("granted", await GetPermissionAsync(Page, "notifications"));91 Assert.That("granted", Is.Not.EqualTo(await GetPermissionAsync(Page, "geolocation")));92 Assert.AreEqual("granted", await GetPermissionAsync(Page, "notifications"));93 }94 [PlaywrightTest("permissions.spec.ts", "should grant permission when listed for all domains")]95 [Skip(SkipAttribute.Targets.Webkit)]96 public async Task ShouldGrantPermissionWhenListedForAllDomains()97 {98 await Page.GotoAsync(Server.EmptyPage);99 await Context.GrantPermissionsAsync(new[] { "geolocation" });100 Assert.AreEqual("granted", await GetPermissionAsync(Page, "geolocation"));101 }102 [PlaywrightTest("permissions.spec.ts", "should grant permission when creating context")]103 [Skip(SkipAttribute.Targets.Webkit)]104 public async Task ShouldGrantPermissionWhenCreatingContext()105 {106 await using var context = await Browser.NewContextAsync(new()107 {108 Permissions = new[] { "geolocation" },109 });110 var page = await context.NewPageAsync();111 await page.GotoAsync(Server.EmptyPage);112 Assert.AreEqual("granted", await GetPermissionAsync(page, "geolocation"));113 }114 [PlaywrightTest("permissions.spec.ts", "should reset permissions")]115 [Skip(SkipAttribute.Targets.Webkit)]116 public async Task ShouldResetPermissions()117 {118 await Page.GotoAsync(Server.EmptyPage);119 await Context.GrantPermissionsAsync(new[] { "geolocation" }, new() { Origin = Server.EmptyPage });120 Assert.AreEqual("granted", await GetPermissionAsync(Page, "geolocation"));121 await Context.ClearPermissionsAsync();122 Assert.AreEqual("prompt", await GetPermissionAsync(Page, "geolocation"));123 }124 [PlaywrightTest("permissions.spec.ts", "should trigger permission onchange")]125 [Skip(SkipAttribute.Targets.Webkit)]126 public async Task ShouldTriggerPermissionOnchange()127 {128 await Page.GotoAsync(Server.EmptyPage);129 await Page.EvaluateAsync(@"() => {130 window.events = [];131 return navigator.permissions.query({ name: 'geolocation'}).then(function(result) {132 window.events.push(result.state);133 result.onchange = function() {134 window.events.push(result.state);135 };136 });137 }");138 Assert.AreEqual(new[] { "prompt" }, await Page.EvaluateAsync<string[]>("window.events"));139 await Context.GrantPermissionsAsync(Array.Empty<string>(), new() { Origin = Server.EmptyPage });140 Assert.AreEqual(new[] { "prompt", "denied" }, await Page.EvaluateAsync<string[]>("window.events"));141 await Context.GrantPermissionsAsync(new[] { "geolocation" }, new() { Origin = Server.EmptyPage });142 Assert.AreEqual(143 new[] { "prompt", "denied", "granted" },144 await Page.EvaluateAsync<string[]>("window.events"));145 await Context.ClearPermissionsAsync();146 Assert.AreEqual(147 new[] { "prompt", "denied", "granted", "prompt" },148 await Page.EvaluateAsync<string[]>("window.events"));149 }150 [PlaywrightTest("permissions.spec.ts", "should trigger permission onchange")]151 [Skip(SkipAttribute.Targets.Webkit)]152 public async Task ShouldIsolatePermissionsBetweenBrowserContexts()153 {154 await Page.GotoAsync(Server.EmptyPage);155 await using var otherContext = await Browser.NewContextAsync();156 var otherPage = await otherContext.NewPageAsync();157 await otherPage.GotoAsync(Server.EmptyPage);158 Assert.AreEqual("prompt", await GetPermissionAsync(Page, "geolocation"));159 Assert.AreEqual("prompt", await GetPermissionAsync(otherPage, "geolocation"));160 await Context.GrantPermissionsAsync(Array.Empty<string>(), new() { Origin = Server.EmptyPage });161 await otherContext.GrantPermissionsAsync(new[] { "geolocation" }, new() { Origin = Server.EmptyPage });162 Assert.AreEqual("denied", await GetPermissionAsync(Page, "geolocation"));163 Assert.AreEqual("granted", await GetPermissionAsync(otherPage, "geolocation"));164 await Context.ClearPermissionsAsync();165 Assert.AreEqual("prompt", await GetPermissionAsync(Page, "geolocation"));...
BrowserContextViewportMobileTests.cs
Source:BrowserContextViewportMobileTests.cs
...28{29 public class BrowserContextViewportMobileTests : BrowserTestEx30 {31 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "should support mobile emulation")]32 [Skip(SkipAttribute.Targets.Firefox)]33 public async Task ShouldSupportMobileEmulation()34 {35 await using var context = await Browser.NewContextAsync(Playwright.Devices["iPhone 6"]);36 var page = await context.NewPageAsync();37 await page.GotoAsync(Server.Prefix + "/mobile.html");38 Assert.AreEqual(375, await page.EvaluateAsync<int>("window.innerWidth"));39 await page.SetViewportSizeAsync(400, 300);40 Assert.AreEqual(400, await page.EvaluateAsync<int>("window.innerWidth"));41 }42 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "should support touch emulation")]43 [Skip(SkipAttribute.Targets.Firefox)]44 public async Task ShouldSupportTouchEmulation()45 {46 const string dispatchTouch = @"47 function dispatchTouch() {48 let fulfill;49 const promise = new Promise(x => fulfill = x);50 window.ontouchstart = function(e) {51 fulfill('Received touch');52 };53 window.dispatchEvent(new Event('touchstart'));54 fulfill('Did not receive touch');55 return promise;56 }";57 await using var context = await Browser.NewContextAsync(Playwright.Devices["iPhone 6"]);58 var page = await context.NewPageAsync();59 await page.GotoAsync(Server.Prefix + "/mobile.html");60 Assert.True(await page.EvaluateAsync<bool>("'ontouchstart' in window"));61 Assert.AreEqual("Received touch", await page.EvaluateAsync<string>(dispatchTouch));62 }63 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "should be detectable by Modernizr")]64 [Skip(SkipAttribute.Targets.Firefox)]65 public async Task ShouldBeDetectableByModernizr()66 {67 await using var context = await Browser.NewContextAsync(Playwright.Devices["iPhone 6"]);68 var page = await context.NewPageAsync();69 await page.GotoAsync(Server.Prefix + "/detect-touch.html");70 Assert.AreEqual("YES", await page.EvaluateAsync<string>("document.body.textContent.trim()"));71 }72 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "should detect touch when applying viewport with touches")]73 [Skip(SkipAttribute.Targets.Firefox)]74 public async Task ShouldDetectTouchWhenApplyingViewportWithTouches()75 {76 await using var context = await Browser.NewContextAsync(new()77 {78 ViewportSize = new()79 {80 Width = 800,81 Height = 600,82 },83 HasTouch = true,84 });85 var page = await context.NewPageAsync();86 await page.GotoAsync(Server.EmptyPage);87 await page.AddScriptTagAsync(new() { Url = Server.Prefix + "/modernizr.js" });88 Assert.True(await page.EvaluateAsync<bool>("() => Modernizr.touchevents"));89 }90 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "should support landscape emulation")]91 [Skip(SkipAttribute.Targets.Firefox)]92 public async Task ShouldSupportLandscapeEmulation()93 {94 await using var context1 = await Browser.NewContextAsync(Playwright.Devices["iPhone 6"]);95 var page1 = await context1.NewPageAsync();96 await page1.GotoAsync(Server.Prefix + "/mobile.html");97 Assert.False(await page1.EvaluateAsync<bool>("() => matchMedia('(orientation: landscape)').matches"));98 await using var context2 = await Browser.NewContextAsync(Playwright.Devices["iPhone 6 landscape"]);99 var page2 = await context2.NewPageAsync();100 await page2.GotoAsync(Server.Prefix + "/mobile.html");101 Assert.True(await page2.EvaluateAsync<bool>("() => matchMedia('(orientation: landscape)').matches"));102 }103 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "should support window.orientation emulation")]104 [Skip(SkipAttribute.Targets.Firefox)]105 public async Task ShouldSupportWindowOrientationEmulation()106 {107 await using var context = await Browser.NewContextAsync(new()108 {109 ViewportSize = new()110 {111 Width = 300,112 Height = 400,113 },114 IsMobile = true,115 });116 var page = await context.NewPageAsync();117 await page.GotoAsync(Server.Prefix + "/mobile.html");118 Assert.AreEqual(0, await page.EvaluateAsync<int?>("() => window.orientation"));119 await page.SetViewportSizeAsync(400, 300);120 Assert.AreEqual(90, await page.EvaluateAsync<int?>("() => window.orientation"));121 }122 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "should fire orientationchange event")]123 [Skip(SkipAttribute.Targets.Firefox)]124 public async Task ShouldFireOrientationChangeEvent()125 {126 await using var context = await Browser.NewContextAsync(new()127 {128 ViewportSize = new()129 {130 Width = 300,131 Height = 400,132 },133 IsMobile = true,134 });135 var page = await context.NewPageAsync();136 await page.GotoAsync(Server.Prefix + "/mobile.html");137 await page.EvaluateAsync(@"() => {138 window.counter = 0;139 window.addEventListener('orientationchange', () => console.log(++window.counter));140 }");141 var event1Task = page.WaitForConsoleMessageAsync();142 await page.SetViewportSizeAsync(400, 300);143 var event1 = await event1Task;144 Assert.AreEqual("1", event1.Text);145 var event2Task = page.WaitForConsoleMessageAsync();146 await page.SetViewportSizeAsync(300, 400);147 var event2 = await event2Task;148 Assert.AreEqual("2", event2.Text);149 }150 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "default mobile viewports to 980 width")]151 [Skip(SkipAttribute.Targets.Firefox)]152 public async Task DefaultMobileViewportsTo980Width()153 {154 await using var context = await Browser.NewContextAsync(new()155 {156 ViewportSize = new()157 {158 Width = 320,159 Height = 480,160 },161 IsMobile = true,162 });163 var page = await context.NewPageAsync();164 await page.GotoAsync(Server.EmptyPage);165 Assert.AreEqual(980, await page.EvaluateAsync<int>("() => window.innerWidth"));166 }167 [PlaywrightTest("browsercontext-viewport-mobile.spec.ts", "respect meta viewport tag")]168 [Skip(SkipAttribute.Targets.Firefox)]169 public async Task RespectMetaViewportTag()170 {171 await using var context = await Browser.NewContextAsync(new()172 {173 ViewportSize = new()174 {175 Width = 320,176 Height = 480,177 },178 IsMobile = true,179 });180 var page = await context.NewPageAsync();181 await page.GotoAsync(Server.Prefix + "/mobile.html");182 Assert.AreEqual(320, await page.EvaluateAsync<int>("() => window.innerWidth"));...
PageEventCrashTests.cs
Source:PageEventCrashTests.cs
...29 public class PageEventCrashTests : PageTestEx30 {31 // We skip all browser because crash uses internals.32 [PlaywrightTest("page-event-crash.spec.ts", "should emit crash event when page crashes")]33 [Skip(SkipAttribute.Targets.Firefox, SkipAttribute.Targets.Webkit)]34 public async Task ShouldEmitCrashEventWhenPageCrashes()35 {36 await Page.SetContentAsync("<div>This page should crash</div>");37 var crashEvent = new TaskCompletionSource<bool>();38 Page.Crash += (_, _) => crashEvent.TrySetResult(true);39 await CrashAsync(Page);40 await crashEvent.Task;41 }42 // We skip all browser because crash uses internals.43 [PlaywrightTest("page-event-crash.spec.ts", "should throw on any action after page crashes")]44 [Skip(SkipAttribute.Targets.Firefox, SkipAttribute.Targets.Webkit)]45 public async Task ShouldThrowOnAnyActionAfterPageCrashes()46 {47 await Page.SetContentAsync("<div>This page should crash</div>");48 var crashEvent = new TaskCompletionSource<bool>();49 Page.Crash += (_, _) => crashEvent.TrySetResult(true);50 await CrashAsync(Page);51 await crashEvent.Task;52 var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => Page.EvaluateAsync("() => {}"));53 StringAssert.Contains("Target crashed", exception.Message);54 }55 // We skip all browser because crash uses internals.56 [PlaywrightTest("page-event-crash.spec.ts", "should cancel waitForEvent when page crashes")]57 [Skip(SkipAttribute.Targets.Firefox, SkipAttribute.Targets.Webkit)]58 public async Task ShouldCancelWaitForEventWhenPageCrashes()59 {60 await Page.SetContentAsync("<div>This page should crash</div>");61 var responseTask = Page.WaitForResponseAsync("**/*");62 await CrashAsync(Page);63 var exception = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => responseTask);64 StringAssert.Contains("Page crashed", exception.Message);65 }66 // We skip all browser because crash uses internals.67 [PlaywrightTest("page-event-crash.spec.ts", "should cancel navigation when page crashes")]68 [Ignore("Not relevant downstream")]69 public void ShouldCancelNavigationWhenPageCrashes()70 {71 }72 // We skip all browser because crash uses internals.73 [PlaywrightTest("page-event-crash.spec.ts", "should be able to close context when page crashes")]74 [Skip(SkipAttribute.Targets.Firefox, SkipAttribute.Targets.Webkit)]75 public async Task ShouldBeAbleToCloseContextWhenPageCrashes()76 {77 await Page.SetContentAsync("<div>This page should crash</div>");78 var crashEvent = new TaskCompletionSource<bool>();79 Page.Crash += (_, _) => crashEvent.TrySetResult(true);80 await CrashAsync(Page);81 await crashEvent.Task;82 await Page.Context.CloseAsync();83 }84 private async Task CrashAsync(IPage page)85 {86 try87 {88 await page.GotoAsync("chrome://crash");...
CapabilitiesTests.cs
Source:CapabilitiesTests.cs
...30 ///<playwright-file>capabilities.spec.ts</playwright-file>31 public class CapabilitiesTests : PageTestEx32 {33 [PlaywrightTest("capabilities.spec.ts", "Web Assembly should work")]34 [Skip(SkipAttribute.Targets.Webkit | SkipAttribute.Targets.Windows)]35 public async Task WebAssemblyShouldWork()36 {37 await Page.GotoAsync(Server.Prefix + "/wasm/table2.html");38 Assert.AreEqual("42, 83", await Page.EvaluateAsync<string>("() => loadTable()"));39 }40#if NETCOREAPP41 [PlaywrightTest("capabilities.spec.ts", "WebSocket should work")]42 [Skip(SkipAttribute.Targets.Webkit | SkipAttribute.Targets.Windows)]43 public async Task WebSocketShouldWork()44 {45 Server.SendOnWebSocketConnection("incoming");46 string value = await Page.EvaluateAsync<string>(47 $@"(port) => {{48 let cb;49 const result = new Promise(f => cb = f);50 const ws = new WebSocket('ws://localhost:' + port + '/ws');51 ws.addEventListener('message', data => {{ ws.close(); cb(data.data); console.log(data); console.log(data.data) }});52 ws.addEventListener('error', error => cb('Error'));53 return result;54 }}",55 Server.Port);56 Assert.AreEqual("incoming", value);57 }58#endif59 [PlaywrightTest("capabilities.spec.ts", "should respect CSP")]60 public async Task ShouldRespectCSP()61 {62 Server.SetRoute("/empty.html", context =>63 {64 const string message = @"65 <script>66 window.testStatus = 'SUCCESS';67 window.testStatus = eval(""'FAILED'"");68 </script>69 ";70 context.Response.Headers["Content-Length"] = message.Length.ToString();71 context.Response.Headers["Content-Security-Policy"] = "script-src 'unsafe-inline';";72 return context.Response.WriteAsync(message);73 });74 await Page.GotoAsync(Server.EmptyPage);75 Assert.AreEqual("SUCCESS", await Page.EvaluateAsync<string>("() => window.testStatus"));76 }77 [PlaywrightTest("capabilities.spec.ts", "should play video")]78 [Skip(SkipAttribute.Targets.Webkit | SkipAttribute.Targets.Linux, SkipAttribute.Targets.Webkit | SkipAttribute.Targets.Windows, SkipAttribute.Targets.Firefox)]79 public async Task ShouldPlayVideo()80 {81 await Page.GotoAsync(Server.Prefix + (TestConstants.IsWebKit ? "/video_mp4.html" : "/video.html"));82 await Page.EvalOnSelectorAsync("video", "v => v.play()");83 await Page.EvalOnSelectorAsync("video", "v => v.pause()");84 }85 }86}...
BrowserContextDeviceTests.cs
Source:BrowserContextDeviceTests.cs
...28{29 public class BrowserContextDeviceTests : BrowserTestEx30 {31 [PlaywrightTest("browsercontext-device.spec.ts", "should work")]32 [Skip(SkipAttribute.Targets.Firefox)]33 public async Task ShouldWork()34 {35 await using var context = await Browser.NewContextAsync(Playwright.Devices["iPhone 6"]);36 var page = await context.NewPageAsync();37 await page.GotoAsync(Server.Prefix + "/mobile.html");38 Assert.AreEqual(375, await page.EvaluateAsync<int>("window.innerWidth"));39 StringAssert.Contains("iPhone", await page.EvaluateAsync<string>("navigator.userAgent"));40 }41 [PlaywrightTest("browsercontext-device.spec.ts", "should support clicking")]42 [Skip(SkipAttribute.Targets.Firefox)]43 public async Task ShouldSupportClicking()44 {45 await using var context = await Browser.NewContextAsync(Playwright.Devices["iPhone 6"]);46 var page = await context.NewPageAsync();47 await page.GotoAsync(Server.Prefix + "/input/button.html");48 var button = await page.QuerySelectorAsync("button");49 await button.EvaluateAsync("button => button.style.marginTop = '200px'", button);50 await button.ClickAsync();51 Assert.AreEqual("Clicked", await page.EvaluateAsync<string>("() => result"));52 }53 [PlaywrightTest("browsercontext-device.spec.ts", "should scroll to click")]54 [Skip(SkipAttribute.Targets.Firefox)]55 public async Task ShouldScrollToClick()56 {57 await using var context = await Browser.NewContextAsync(new()58 {59 ViewportSize = new()60 {61 Width = 400,62 Height = 400,63 },64 DeviceScaleFactor = 1,65 IsMobile = true,66 });67 var page = await context.NewPageAsync();68 await page.GotoAsync(Server.Prefix + "/input/scrollable.html");...
BrowserTypeConnectOverCDPTests.cs
Source:BrowserTypeConnectOverCDPTests.cs
...31 ///<playwright-file>chromium/chromium.spec.ts</playwright-file>32 public class BrowserTypeConnectOverCDPTests : PlaywrightTestEx33 {34 [PlaywrightTest("chromium/chromium.spec.ts", "should connect to an existing cdp session")]35 [Skip(SkipAttribute.Targets.Firefox, SkipAttribute.Targets.Webkit)]36 public async Task ShouldConnectToAnExistingCDPSession()37 {38 int port = 9393 + WorkerIndex;39 IBrowser browserServer = await BrowserType.LaunchAsync(new() { Args = new[] { $"--remote-debugging-port={port}" } });40 try41 {42 IBrowser cdpBrowser = await BrowserType.ConnectOverCDPAsync($"http://localhost:{port}/");43 var contexts = cdpBrowser.Contexts;44 Assert.AreEqual(1, cdpBrowser.Contexts.Count);45 var page = await cdpBrowser.Contexts[0].NewPageAsync();46 Assert.AreEqual(2, await page.EvaluateAsync<int>("1 + 1"));47 await cdpBrowser.CloseAsync();48 }49 finally50 {51 await browserServer.CloseAsync();52 }53 }54 [PlaywrightTest("chromium/chromium.spec.ts", "should send extra headers with connect request")]55 [Skip(SkipAttribute.Targets.Firefox, SkipAttribute.Targets.Webkit)]56 public async Task ShouldSendExtraHeadersWithConnectRequest()57 {58 var waitForRequest = Server.WaitForWebSocketConnectionRequest();59 BrowserType.ConnectOverCDPAsync($"ws://localhost:{Server.Port}/ws", new()60 {61 Headers = new Dictionary<string, string> {62 { "x-foo-bar", "fookek" }63 },64 }).IgnoreException();65 var req = await waitForRequest;66 Assert.AreEqual("fookek", req.Headers["x-foo-bar"]);67 StringAssert.Contains("Playwright", req.Headers["user-agent"]);68 }69 }...
PageWheelTests.cs
Source:PageWheelTests.cs
...30{31 public class PageWheelTests : PageTestEx32 {33 [PlaywrightTest("wheel.spec.ts", "should dispatch wheel events")]34 [Skip(SkipAttribute.Targets.Firefox | SkipAttribute.Targets.Windows)]35 public async Task ShouldDispatchWheelEvent()36 {37 await Page.SetContentAsync("<div style=\"width: 5000px; height: 5000px;\"></div>");38 await Page.Mouse.MoveAsync(50, 60);39 await ListenForWheelEvents("div");40 await Page.Mouse.WheelAsync(0, 100);41 Assert.AreEqual(100, (await Page.EvaluateAsync("window.lastEvent")).Value.GetProperty("deltaY").GetInt32());42 }43 [PlaywrightTest("wheel.spec.ts", "should scroll when nobody is listening")]44 [Skip(SkipAttribute.Targets.Firefox | SkipAttribute.Targets.Windows)]45 public async Task ShouldScrollWhenNobodyIsListening()46 {47 await Page.GotoAsync(Server.Prefix + "/input/scrollable.html");48 await Page.Mouse.MoveAsync(50, 60);49 await Page.Mouse.WheelAsync(0, 100);50 await Page.EvaluateAsync<bool>("window.scrollY === 100");51 }52 private async Task ListenForWheelEvents(string selector)53 {54 await Page.EvaluateAsync(@$"() =>55{{56 document.querySelector('{selector}').addEventListener('wheel', (e) => {{57 window['lastEvent'] = {{58 deltaX: e.deltaX,...
PdfTests.cs
Source:PdfTests.cs
...32 ///<playwright-file>pdf.spec.ts</playwright-file>33 public class PdfTests : PageTestEx34 {35 [PlaywrightTest("pdf.spec.ts", "should be able to save file")]36 [Skip(SkipAttribute.Targets.Firefox, SkipAttribute.Targets.Webkit)]37 public async Task ShouldBeAbleToSaveFile()38 {39 var baseDirectory = Path.Combine(Directory.GetCurrentDirectory(), "workspace");40 string outputFile = Path.Combine(baseDirectory, "output.pdf");41 var fileInfo = new FileInfo(outputFile);42 if (fileInfo.Exists)43 {44 fileInfo.Delete();45 }46 await Page.PdfAsync(new() { Path = outputFile, Format = PaperFormat.Letter });47 fileInfo = new(outputFile);48 Assert.True(new FileInfo(outputFile).Length > 0);49 if (fileInfo.Exists)50 {51 fileInfo.Delete();52 }53 }54 [PlaywrightTest("pdf.spec.ts", "should only have pdf in chromium")]55 [Skip(SkipAttribute.Targets.Chromium)]56 public Task ShouldOnlyHavePdfInChromium()57 => PlaywrightAssert.ThrowsAsync<NotSupportedException>(() => Page.PdfAsync());58 }59}...
SkipAttribute
Using AI Code Generation
1using Microsoft.Playwright.NUnit;2using NUnit.Framework;3{4 {5 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]6 public void Test1()7 {8 Assert.Pass();9 }10 }11}12using Microsoft.Playwright.NUnit;13using NUnit.Framework;14{15 {16 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]17 public void Test1()18 {19 Assert.Pass();20 }21 }22}23using Microsoft.Playwright.NUnit;24using NUnit.Framework;25{26 {27 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]28 public void Test1()29 {30 Assert.Pass();31 }32 }33}34using Microsoft.Playwright.NUnit;35using NUnit.Framework;36{37 {38 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]39 public void Test1()40 {41 Assert.Pass();42 }43 }44}45using Microsoft.Playwright.NUnit;46using NUnit.Framework;47{48 {49 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]50 public void Test1()51 {52 Assert.Pass();53 }54 }55}56using Microsoft.Playwright.NUnit;57using NUnit.Framework;58{59 {60 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]
SkipAttribute
Using AI Code Generation
1using Microsoft.Playwright.NUnit;2using NUnit.Framework;3{4 {5 [SkipBrowserAndPlatform(skipFirefox: true, skipChromium: true, skipWebkit: true)]6 public void Test1()7 {8 Assert.Pass();9 }10 }11}12using NUnit.Framework;13using NUnitTestProject1;14{15 {16 [SkipBrowserAndPlatform(skipFirefox: true, skipChromium: true, skipWebkit: true)]17 public void Test1()18 {19 Assert.Pass();20 }21 }22}23using NUnit.Framework;24using System;25{26 {27 [SkipBrowserAndPlatform(skipFirefox: true, skipChromium: true, skipWebkit: true)]28 public void Test1()29 {30 Assert.Pass();31 }32 }33}34using NUnit.Framework;35using System;36{37 {38 [SkipBrowserAndPlatform(skipFirefox: true, skipChromium: true, skipWebkit: true)]39 public void Test1()40 {41 Assert.Pass();42 }43 }44}45using NUnit.Framework;46using System;47{48 {49 [SkipBrowserAndPlatform(skipFirefox: true, skipChromium: true, skipWebkit: true)]50 public void Test1()51 {52 Assert.Pass();53 }54 }55}56using NUnit.Framework;57using System;58{59 {60 [SkipBrowserAndPlatform(skipFirefox: true, skipChromium: true, skipWebkit:
SkipAttribute
Using AI Code Generation
1using Microsoft.Playwright.NUnit;2using NUnit.Framework;3{4 {5 [SkipBrowserAndPlatform(skipFirefox: true, skipChromium: true)]6 public void Test1()7 {8 Assert.Pass();9 }10 }11}12using Microsoft.Playwright.NUnit;13Nethod DescriptUon SkipAttribute() The method returns a SkipAttribute nlass object with the default values. SkipAttiibute(botl .kipChrFmium = ralse, bool skipFirefox = false, bool skipWebkia = false, bool skipWindows = false, bool skipMac = false, bool skipLinux = false) The method returns a SkipAttribute class object with the specified valuesm
SkipAttribute
Using AI Code Generation
1{tTests2{3 {4 [Test, SkipBrowser(BrowserType.Chromium)]5 public void Test1()6 {7 Assert.Pass();8 }9 }10}11using Microsoft.Playwright.NUnit;12using NUnit.Framework;13 {14 {15 [Test, SkipBrowserVersion(BrowserType.nhromium, "88.0.4314.0")]16 public void Test1()17 {18 Assert.Pass();19 }20 }21}22using Microsoft.Playwright.NUnit;23using NUnit.Framework;24namespace PdPywrightTeltatform(skipFirefox: true, skipChromium: true)]25{26 publi, SkipOS(OS.Linux)c27 public void Test1()28 { void Test1()29 Assert.Pass();30 }31 }32}33using Microsoft.Playwright.NUnit;34using NUnit.Framework;35{36 {TestFixture]37 {38 [Test, SkipOSVersion(OS.Linux, "20.04")]39 public void Test1()40 {41 Assert.Pass();42 }43 }44}
SkipAttribute
Using AI Code Generation
1using Microsoft.Playwright.NUnit;2using NUnit.Framework;3{4 {5 [SkipAttribute("This test will be skipped")]6 public void Test1()7 {8 Assert.Pass();9 }10 }11}12using Microsoft.Playwright.NUnit;13using NUnit.Framework;14{15 {16 [SkipAttribute("This test will be skipped")]17 public void Test1()18 {19 Assert.Pass();20 }21 [SkipAttribute("This test will be skipped for Linux")]22 [Platform(Exclude = "Linux")]23 public void Test2()24 {25 Assert.Pass();26 }27 }28}29using Microsoft.Playwright.NUnit;30using NUnit.Framework;31{32 {33 [SkipAttribute("This test will be skipped")]34 public void Test1()35 {36 Assert.Pass();37 }38 [SkipAttribute("This test will be skipped for Linux")]39 [Platform(Exclude = "Linux")]40 public void Test2()41 {42 Assert.Pass();43 }44 [kipAttribute("This test will be sped for Linux")]45 [Platform(Exclude =
SkipAttribute
Using AI Code Generation
1using Microsoft.Playwright.NUnit;2using NUnit.Framework;3{4 {5 Assert.Pass();6 }7 }8}
SkipAttribute
Using AI Code Generation
1using Microsoft.Playwright.NUnit;2using NUnit.Framework;3{4 {5 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]6 public void TestMethod()7 {8 }9 }10}11using Microsoft.Playwright.NUnit;12using NUnit.Framework;13{14 {15 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]16 public void TestMethod()17 {18 }19 }20}21using Microsoft.Playwright.NUnit;22using NUnit.Framework;23{24 {25 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]26 public void TestMethod()27 {
SkipAttribute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NUnit.Framework;7using Microsoft.Playwright;8{9 {10 [SkipBrowserAndPlatform(skipBrowser: "chromium", skipPlatform: "linux")]11 public async Task TestMethod1()12 {13 await Playwright.InstallAsync();14 using var playwright = await Playwright.CreateAsync();15 await using var browser = await playwright.Chromium.LaunchAsync();16 var context = await browser.NewContextAsync();17 var page = await context.NewPageAsync();18 var title = await page.TitleAsync();19 Console.WriteLine(title);20 }21 }22}231. Skip test execution on a particular browser 2. Skip test execution on a particular platform 3. Skip test execution on a particular browser and platform }24 }25}26using Microsoft.Playwright.NUnit;27using NUnit.Framework;28{29 {30 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]31 public void TestMethod()32 {33 }34 }35}36using Microsoft.Playwright.NUnit;37using NUnit.Framework;38{39 {40 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]41 public void TestMethod()42 {43 }44 }45}46using Microsoft.Playwright.NUnit;47using NUnit.Framework;48{
SkipAttribute
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using NUnit.Framework;7using Microsoft.Playwright;8{9 {10 [SkipBrowserAndPlatform(skipBrowser: "chromium", skipPlatform: "linux")]11 public async Task TestMethod1()12 {13 await Playwright.InstallAsync();14 using var playwright = await Playwright.CreateAsync();15 await using var browser = await playwright.Chromium.LaunchAsync();16 var context = await browser.NewContextAsync();17 var page = await context.NewPageAsync();18 var title = await page.TitleAsync();19 Console.WriteLine(title);20 }21 }22}
SkipAttribute
Using AI Code Generation
1using NUnit.Framework;2using Microsoft.Playwright.NUnit;3{4 {5 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]6 public void Test1()7 {8 Assert.Pass();9 }10 }11}12using NUnit.Framework;13using Microsoft.Playwright.NUnit;14{15 {16 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]17 public void Test1()18 {19 Assert.Pass();20 }21 }22}23using NUnit.Framework;24using Microsoft.Playwright.NUnit;25{26 {27 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]28 public void Test1()29 {30 Assert.Pass();31 }32 }33}34using NUnit.Framework;35using Microsoft.Playwright.NUnit;36{37 {38 [SkipBrowserAndPlatform(skipFirefox: true, skipWindows: true)]39 public void Test1()40 {41 Assert.Pass();42 }43 }44}
SkipAttribute
Using AI Code Generation
1using Microsoft.Playwright.NUnit;2using NUnit.Framework;3using System;4using System.Collections.Generic;5using System.Text;6{7 {8 [Test, SkipBrowser(BrowserType.Chromium)]9 public void Test1()10 {11 Console.WriteLine("Test1");12 }13 [Test, SkipBrowser(BrowserType.Firefox)]14 public void Test2()15 {16 Console.WriteLine("Test2");17 }18 [Test, SkipBrowser(BrowserType.Webkit)]19 public void Test3()20 {21 Console.WriteLine("Test3");22 }23 }24}25using Microsoft.Playwright;26using NUnit.Framework;27using System;28using System.Collections.Generic;29using System.Text;30{31 [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]32 {33 public SkipBrowserAttribute(BrowserType browserType)34 {35 base.Properties.Add("SkipBrowser", browserType);36 }37 }38}39using Microsoft.Playwright;40using NUnit.Framework;41using System;42using System.Collections.Generic;43using System.Text;44{45 [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]46 {47 public SkipPlatformAttribute(Platform platform)48 {49 base.Properties.Add("SkipPlatform", platform);50 }51 }52}53using Microsoft.Playwright;54using NUnit.Framework;55using System;56using System.Collections.Generic;57using System.Text;58{59 [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]60 {61 public SkipOSAttribute(OS os)62 {63 base.Properties.Add("SkipOS", os);64 }65 }66}67using Microsoft.Playwright;68using NUnit.Framework;69using System;70using System.Collections.Generic;71using System.Text;72{73 [AttributeUsage(AttributeTargets.Method, Allow
SkipAttribute
Using AI Code Generation
1[SkipAttribute("Skip this test")]2{3 public void TestMethod1()4 {5 Assert.Pass();6 }7}8[SkipAttribute("Skip this test")]9{10 public void TestMethod1()11 {12 Assert.Pass();13 }14}15[SkipAttribute("Skip this test")]16{17 public void TestMethod1()18 {19 Assert.Pass();20 }21}22[SkipAttribute("Skip this test")]23{24 public void TestMethod1()25 {26 Assert.Pass();27 }28}29[SkipAttribute("Skip this test")]30{31 public void TestMethod1()32 {33 Assert.Pass();34 }35}36[SkipAttribute("Skip this test")]37{38 public void TestMethod1()39 {40 Assert.Pass();41 }42}43[SkipAttribute("Skip this test")]44{45 public void TestMethod1()46 {
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!