Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
fail-fast: false
matrix:
browser: [chromium, firefox, webkit]
os: [windows-latest, ubuntu-latest, macos-latest]
os: [windows-latest, ubuntu-latest, macos-12]
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->103.0.5060.24<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->103.0.5060.53<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->15.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->99.0.1<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->100.0.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |

Playwright for .NET is the official language port of [Playwright](https://playwright.dev), the library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) with a single API. Playwright is built to enable cross-browser web automation that is **ever-green**, **capable**, **reliable** and **fast**.

Expand Down
2 changes: 1 addition & 1 deletion src/Common/Version.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<AssemblyVersion>1.22.0</AssemblyVersion>
<PackageVersion>$(AssemblyVersion)</PackageVersion>
<DriverVersion>1.23.0-alpha-may-27-2022</DriverVersion>
<DriverVersion>1.23.0-beta-1656093125000</DriverVersion>
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NoDefaultExcludes>true</NoDefaultExcludes>
Expand Down
16 changes: 8 additions & 8 deletions src/Playwright.Tests/BrowserContextLocaleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class BrowserContextLocaleTests : BrowserTestEx
[PlaywrightTest("browsercontext-locale.spec.ts", "should affect accept-language header")]
public async Task ShouldAffectAcceptLanguageHeader()
{
await using var context = await Browser.NewContextAsync(new() { Locale = "fr-CH" });
await using var context = await Browser.NewContextAsync(new() { Locale = "fr-FR" });
string acceptLanguage = string.Empty;
var page = await context.NewPageAsync();
var requestTask = Server.WaitForRequest("/empty.html", c => acceptLanguage = c.Headers["accept-language"]);
Expand All @@ -42,18 +42,18 @@ await TaskUtils.WhenAll(
requestTask,
page.GotoAsync(Server.EmptyPage));

Assert.That(acceptLanguage, Does.StartWith("fr-CH"));
Assert.That(acceptLanguage, Does.StartWith("fr-FR"));
Comment thread
mxschmitt marked this conversation as resolved.
}

[PlaywrightTest("browsercontext-locale.spec.ts", "should affect navigator.language")]
public async Task ShouldAffectNavigatorLanguage()
{
await using var context = await Browser.NewContextAsync(new()
{
Locale = "fr-CH"
Locale = "fr-FR"
});
var page = await context.NewPageAsync();
Assert.AreEqual("fr-CH", await page.EvaluateAsync<string>("navigator.language"));
Assert.AreEqual("fr-FR", await page.EvaluateAsync<string>("navigator.language"));
}

[PlaywrightTest("browsercontext-locale.spec.ts", "should format number")]
Expand All @@ -71,7 +71,7 @@ public async Task ShouldFormatNumber()

await using (var context = await Browser.NewContextAsync(new()
{
Locale = "fr-CH"
Locale = "fr-FR"
}))
{
var page = await context.NewPageAsync();
Expand Down Expand Up @@ -116,7 +116,7 @@ public async Task ShouldFormatNumberInPopups()
{
await using var context = await Browser.NewContextAsync(new()
{
Locale = "fr-CH"
Locale = "fr-FR"
});

var page = await context.NewPageAsync();
Expand All @@ -137,7 +137,7 @@ public async Task ShouldAffectNavigatorLanguageInPopups()
{
await using var context = await Browser.NewContextAsync(new()
{
Locale = "fr-CH"
Locale = "fr-FR"
});

var page = await context.NewPageAsync();
Expand All @@ -150,7 +150,7 @@ await TaskUtils.WhenAll(

var popup = popupTask.Result;
await popup.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
Assert.AreEqual("fr-CH", await popup.EvaluateAsync<string>("() => window.initialNavigatorLanguage"));
Assert.AreEqual("fr-FR", await popup.EvaluateAsync<string>("() => window.initialNavigatorLanguage"));
}
}
}
58 changes: 58 additions & 0 deletions src/Playwright.Tests/BrowserContextServiceWorkerPolicyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;

namespace Microsoft.Playwright.Tests
{
public class BrowserContextServiceWorkerPolicyTests : BrowserTestEx
Comment thread
mxschmitt marked this conversation as resolved.
{
[PlaywrightTest("browsercontext-service-worker-policy.spec.ts", "should allow service workers by default")]
public async Task ShouldAllowServiceWorkersByDefault()
{
var context = await Browser.NewContextAsync();
var page = await context.NewPageAsync();
await page.GotoAsync(Server.Prefix + "/serviceworkers/empty/sw.html");
var registrationResult = await page.EvaluateAsync<object>("() => window['registrationPromise']");
Assert.IsNotNull(registrationResult);
await context.CloseAsync();
}

[PlaywrightTest("browsercontext-service-worker-policy.spec.ts", "blocks service worker registration")]
public async Task ShouldBlockServiceWorkerRegistration()
{
var context = await Browser.NewContextAsync(new()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to close the context!

{
ServiceWorkers = ServiceWorkerPolicy.Block
});
var page = await context.NewPageAsync();
var (consoleMessage, _) = await TaskUtils.WhenAll(page.WaitForConsoleMessageAsync(),
page.GotoAsync(Server.Prefix + "/serviceworkers/empty/sw.html"));
Assert.AreEqual("Service Worker registration blocked by Playwright", consoleMessage.Text);
await context.CloseAsync();
}
}
}
10 changes: 10 additions & 0 deletions src/Playwright.Tests/BrowserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public async Task ShouldCreateNewPage()
Assert.That(browser.Contexts, Has.Length.EqualTo(1));

await page2.CloseAsync();
await browser.CloseAsync();
}

[PlaywrightTest("browser.spec.ts", "should return browserType")]
public async Task ShouldReturnBrowserType()
Comment thread
mxschmitt marked this conversation as resolved.
{
var browserType = Playwright[TestConstants.BrowserName];
var browser = await browserType.LaunchAsync();
Assert.AreEqual(browser.BrowserType, browserType);
await browser.CloseAsync();
}

[PlaywrightTest("browser.spec.ts", "should throw upon second create new page")]
Expand Down
1 change: 1 addition & 0 deletions src/Playwright.Tests/BrowserTypeConnectOverCDPTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public async Task ShouldConnectToAnExistingCDPSession()
try
{
IBrowser cdpBrowser = await BrowserType.ConnectOverCDPAsync($"http://localhost:{port}/");
Assert.AreEqual(cdpBrowser.BrowserType, Playwright.Chromium);
var contexts = cdpBrowser.Contexts;
Assert.AreEqual(1, cdpBrowser.Contexts.Count);
var page = await cdpBrowser.Contexts[0].NewPageAsync();
Expand Down
38 changes: 2 additions & 36 deletions src/Playwright.Tests/DefaultBrowsercontext2Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public async Task ShouldSupportLocaleOption()
{
var (tmp, context, page) = await LaunchAsync(new()
{
Locale = "fr-CH",
Locale = "fr-FR",
});

Assert.AreEqual("fr-CH", await page.EvaluateAsync<string>("() => navigator.language"));
Assert.AreEqual("fr-FR", await page.EvaluateAsync<string>("() => navigator.language"));

await context.DisposeAsync();
tmp.Dispose();
Expand Down Expand Up @@ -229,40 +229,6 @@ public async Task ShouldRestoreStateFromUserDataDir()
}
}

[PlaywrightTest("defaultbrowsercontext-2.spec.ts", "should restore cookies from userDataDir")]
Comment thread
mxschmitt marked this conversation as resolved.
[Skip(SkipAttribute.Targets.Chromium | SkipAttribute.Targets.Windows)]
public async Task ShouldRestoreCookiesFromUserDataDir()
{
using var userDataDir = new TempDirectory();

await using (var browserContext = await BrowserType.LaunchPersistentContextAsync(userDataDir.Path))
{
var page = await browserContext.NewPageAsync();
await page.GotoAsync(Server.EmptyPage);
string documentCookie = await page.EvaluateAsync<string>(@"() => {
document.cookie = 'doSomethingOnlyOnce=true; expires=Fri, 31 Dec 9999 23:59:59 GMT';
return document.cookie;
}");

Assert.AreEqual("doSomethingOnlyOnce=true", documentCookie);
}

await using (var browserContext2 = await BrowserType.LaunchPersistentContextAsync(userDataDir.Path))
{
var page = await browserContext2.NewPageAsync();
await page.GotoAsync(Server.EmptyPage);
Assert.AreEqual("doSomethingOnlyOnce=true", await page.EvaluateAsync<string>("() => document.cookie"));
}

using var userDataDir2 = new TempDirectory();
await using (var browserContext2 = await BrowserType.LaunchPersistentContextAsync(userDataDir2.Path))
{
var page = await browserContext2.NewPageAsync();
await page.GotoAsync(Server.EmptyPage);
Assert.That("doSomethingOnlyOnce=true", Is.Not.EqualTo(await page.EvaluateAsync<string>("() => document.cookie")));
}
}

[PlaywrightTest("defaultbrowsercontext-2.spec.ts", "should have default URL when launching browser")]
public async Task ShouldHaveDefaultURLWhenLaunchingBrowser()
{
Expand Down
20 changes: 18 additions & 2 deletions src/Playwright.Tests/PageNetworkResponseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
* SOFTWARE.
*/

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
Expand Down Expand Up @@ -255,5 +254,22 @@ public async Task ShouldBehaveTheSameWayForHeadersAndAllHeaders()
Assert.AreEqual(response.Headers, allHeaders);
#pragma warning restore 0612
}

[PlaywrightTest("page-network-response.spec.ts", "should report if request was fromServiceWorker")]
public async Task ShouldReportIfRequestWasFromServiceWorker()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{
{
var res = await Page.GotoAsync(Server.Prefix + "/serviceworkers/fetch/sw.html");
Assert.False(res.FromServiceWorker);
}
await Page.EvaluateAsync("() => window['activationPromise']");
{
var (res, _) = await TaskUtils.WhenAll(
Page.WaitForResponseAsync(new Regex("example.txt")),
Page.EvaluateAsync("() => fetch('/example.txt')")
);
Assert.True(res.FromServiceWorker);
}
}
}
}
5 changes: 4 additions & 1 deletion src/Playwright.Tests/PageRequestInterceptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace Microsoft.Playwright.Tests
{
public class RequestInterceptTests : PageTestEx
public class PageRequestInterceptTests : PageTestEx
{
[PlaywrightTest("page-request-intercept.spec.ts", "should fulfill intercepted response")]
public async Task ShouldFulfillInterceptedResponse()
Expand Down Expand Up @@ -70,6 +70,9 @@ await route.FulfillAsync(new()
Response = response,
Status = 201,
Body = "",
Headers = new Dictionary<string, string> {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes tests, was also made upstream the same way.

Class got renamed to align it with file name which is common in c# and we do it everywhere else.

{ "Content-Length", "0" },
},
});
});
var response = await Page.GotoAsync(Server.Prefix + "/title.html");
Expand Down
53 changes: 53 additions & 0 deletions src/Playwright/API/Generated/Enums/HarContentPolicy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

#nullable enable

namespace Microsoft.Playwright
{
public enum HarContentPolicy
{
[EnumMember(Value = "omit")]
Omit,
[EnumMember(Value = "embed")]
Embed,
[EnumMember(Value = "attach")]
Attach,
}
}

#nullable disable
51 changes: 51 additions & 0 deletions src/Playwright/API/Generated/Enums/HarMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

#nullable enable

namespace Microsoft.Playwright
{
public enum HarMode
{
[EnumMember(Value = "full")]
Full,
[EnumMember(Value = "minimal")]
Minimal,
}
}

#nullable disable
Loading