How to use ShouldWorkForFileUrls method of Microsoft.Playwright.Tests.PageHistoryTests class

Best Playwright-dotnet code snippet using Microsoft.Playwright.Tests.PageHistoryTests.ShouldWorkForFileUrls

Run Playwright-dotnet automation tests on LambdaTest cloud grid

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

PageHistoryTests.cs

Source: PageHistoryTests.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.Threading.Tasks;
27using Microsoft.Playwright.NUnit;
28using NUnit.Framework;
29
30namespace Microsoft.Playwright.Tests
31{
32    public class PageHistoryTests : PageTestEx
33    {
34        [PlaywrightTest("page-history.spec.ts", "page.goBack should work")]
35        public async Task PageGobackShouldWork()
36        {
37            await Page.GotoAsync(Server.EmptyPage);
38            await Page.GotoAsync(Server.Prefix + "/grid.html");
39
40            var response = await Page.GoBackAsync();
41            Assert.True(response.Ok);
42            StringAssert.Contains(Server.EmptyPage, response.Url);
43
44            response = await Page.GoForwardAsync();
45            Assert.True(response.Ok);
46            StringAssert.Contains("/grid.html", response.Url);
47
48            response = await Page.GoForwardAsync();
49            Assert.Null(response);
50        }
51
52        [PlaywrightTest("page-history.spec.ts", "page.goBack should work with HistoryAPI")]
53        public async Task PageGoBackShouldWorkWithHistoryAPI()
54        {
55            await Page.GotoAsync(Server.EmptyPage);
56            await Page.EvaluateAsync(@"
57              history.pushState({ }, '', '/first.html');
58              history.pushState({ }, '', '/second.html');
59            ");
60            Assert.AreEqual(Server.Prefix + "/second.html", Page.Url);
61
62            await Page.GoBackAsync();
63            Assert.AreEqual(Server.Prefix + "/first.html", Page.Url);
64            await Page.GoBackAsync();
65            Assert.AreEqual(Server.EmptyPage, Page.Url);
66            await Page.GoForwardAsync();
67            Assert.AreEqual(Server.Prefix + "/first.html", Page.Url);
68        }
69
70        [PlaywrightTest("page-history.spec.ts", "should work for file urls")]
71        [Ignore("We need screenshots for this")]
72        public void ShouldWorkForFileUrls()
73        {
74        }
75
76
77        [PlaywrightTest("page-history.spec.ts", "page.reload should work")]
78        public async Task PageReloadShouldWork()
79        {
80            await Page.GotoAsync(Server.EmptyPage);
81            await Page.EvaluateAsync("() => window._foo = 10");
82            await Page.ReloadAsync();
83            Assert.Null(await Page.EvaluateAsync("() => window._foo"));
84        }
85    }
86}
87
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 ShouldWorkForFileUrls code on LambdaTest Cloud Grid

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