Skip to content

Commit

Permalink
chore(roll): roll to Playwright v1.45 (#2949)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Jun 24, 2024
1 parent 062fbe9 commit 86ad6c7
Show file tree
Hide file tree
Showing 48 changed files with 1,611 additions and 120 deletions.
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-12]
os: [windows-latest, ubuntu-latest, macos-13]
steps:
- uses: actions/checkout@v3
- 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 -->125.0.6422.26<!-- GEN:stop --> ||||
| Chromium <!-- GEN:chromium-version -->127.0.6533.5<!-- GEN:stop --> ||||
| WebKit <!-- GEN:webkit-version -->17.4<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->125.0.1<!-- GEN:stop --> ||||
| Firefox <!-- GEN:firefox-version -->127.0<!-- 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
6 changes: 3 additions & 3 deletions src/Common/Dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
</AdditionalFiles>
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.435">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Roslynator.Analyzers" Version="4.1.1">
<PackageReference Include="Roslynator.Analyzers" Version="4.12.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.2.32">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
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.44.0</AssemblyVersion>
<PackageVersion>$(AssemblyVersion)</PackageVersion>
<DriverVersion>1.44.0-beta-1715802478000</DriverVersion>
<DriverVersion>1.45.0-beta-1718782041000</DriverVersion>
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NoDefaultExcludes>true</NoDefaultExcludes>
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright.MSTest/PlaywrightTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class PlaywrightTest

public IBrowserType BrowserType { get; private set; } = null!;

public int WorkerIndex { get => _currentWorker!.WorkerIndex; }
public int WorkerIndex => _currentWorker!.WorkerIndex;

[TestInitialize]
public async Task Setup()
Expand Down
9 changes: 5 additions & 4 deletions src/Playwright.Tests.TestServer/SimpleServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ public SimpleServer(int port, string contentRoot, bool isHttps)
return;
}
if (_requestWaits.TryGetValue(context.Request.Path, out var requestWait))
{
requestWait(context);
}
if (_auths.TryGetValue(context.Request.Path, out var auth) && !Authenticate(auth.username, auth.password, context))
{
context.Response.Headers.Append("WWW-Authenticate", "Basic realm=\"Secure Area\"");
Expand All @@ -128,10 +133,6 @@ public SimpleServer(int port, string contentRoot, bool isHttps)
await context.Response.WriteAsync("HTTP Error 401 Unauthorized: Access is denied").ConfigureAwait(false);
return;
}
if (_requestWaits.TryGetValue(context.Request.Path, out var requestWait))
{
requestWait(context);
}
if (_routes.TryGetValue(context.Request.Path + context.Request.QueryString, out var handler))
{
await handler(context).ConfigureAwait(false);
Expand Down
12 changes: 12 additions & 0 deletions src/Playwright.Tests.TestServer/assets/input/folderupload.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Folder upload test</title>
</head>
<body>
<form action="/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file1" webkitdirectory>
<input type="submit">
</form>
</body>
</html>
15 changes: 15 additions & 0 deletions src/Playwright.Tests/BaseTests/PageTestEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ public class PageTestEx : PageTest
public SimpleServer Server { get; internal set; }
public SimpleServer HttpsServer { get; internal set; }
public int BrowserMajorVersion { get; internal set; }
public SameSiteAttribute DefaultSameSiteCookieValue
{
get
{
if (TestConstants.IsChromium)
{
return SameSiteAttribute.Lax;
}
if (TestConstants.IsWebKit && TestConstants.IsLinux)
{
return SameSiteAttribute.Lax;
}
return SameSiteAttribute.None;
}
}

[SetUp]
public async Task HttpSetup()
Expand Down
15 changes: 15 additions & 0 deletions src/Playwright.Tests/BaseTests/PlaywrightTestEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ public class PlaywrightTestEx : PlaywrightTest
{
public SimpleServer Server { get; internal set; }
public SimpleServer HttpsServer { get; internal set; }
public SameSiteAttribute DefaultSameSiteCookieValue
{
get
{
if (TestConstants.IsChromium)
{
return SameSiteAttribute.Lax;
}
if (TestConstants.IsWebKit && TestConstants.IsLinux)
{
return SameSiteAttribute.Lax;
}
return SameSiteAttribute.None;
}
}

[SetUp]
public async Task HttpSetup()
Expand Down
2 changes: 1 addition & 1 deletion src/Playwright.Tests/BrowserContextAddCookiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ await Context.AddCookiesAsync(new[]
Assert.AreEqual(-1, cookie.Expires);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsFalse(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);
}

[PlaywrightTest("browsercontext-add-cookies.spec.ts", "should set a cookie with a path")]
Expand Down
12 changes: 6 additions & 6 deletions src/Playwright.Tests/BrowserContextCookiesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task ShouldGetACookie()
Assert.AreEqual(-1, cookie.Expires);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsFalse(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);
}

[PlaywrightTest("browsercontext-cookies.spec.ts", "should get a non-session cookie")]
Expand All @@ -70,7 +70,7 @@ public async Task ShouldGetANonSessionCookie()
Assert.NotNull(cookie.Expires);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsFalse(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);
}

[PlaywrightTest("browsercontext-cookies.spec.ts", "should properly report httpOnly cookie")]
Expand Down Expand Up @@ -138,7 +138,7 @@ public async Task ShouldGetMultipleCookies()
Assert.AreEqual(cookie.Expires, -1);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsFalse(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);

cookie = cookies[1];
Assert.AreEqual("username", cookie.Name);
Expand All @@ -148,7 +148,7 @@ public async Task ShouldGetMultipleCookies()
Assert.AreEqual(cookie.Expires, -1);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsFalse(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);
}

[PlaywrightTest("browsercontext-cookies.spec.ts", "should get cookies from multiple urls")]
Expand Down Expand Up @@ -187,7 +187,7 @@ await Context.AddCookiesAsync(new[]
Assert.AreEqual(cookie.Expires, -1);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsTrue(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);

cookie = cookies[1];
Assert.AreEqual("doggo", cookie.Name);
Expand All @@ -197,6 +197,6 @@ await Context.AddCookiesAsync(new[]
Assert.AreEqual(cookie.Expires, -1);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsTrue(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);
}
}
32 changes: 32 additions & 0 deletions src/Playwright.Tests/BrowserContextFetchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,38 @@ public async Task ShouldWorkWithHttpCredentials()
Assert.AreEqual("/empty.html", requestURL);
}

[PlaywrightTest("browsercontext-fetch.spec.ts", "should support HTTPCredentials.send")]
public async Task ShouldSupportHttpCredentialsSend()
{
var context = await Browser.NewContextAsync(new()
{
HttpCredentials = new()
{
Username = "user",
Password = "pass",
Origin = Server.Prefix.ToUpperInvariant(),
Send = HttpCredentialsSend.Always
}
});
{
var (requestHeaders, response) = await TaskUtils.WhenAll(
Server.WaitForRequest("/empty.html", request => request.Headers.ToDictionary(header => header.Key, header => header.Value)),
context.APIRequest.GetAsync(Server.EmptyPage)
);
Assert.AreEqual(requestHeaders["Authorization"], "Basic " + Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("user:pass")));
Assert.AreEqual(200, response.Status);
}
{
var (requestHeaders, response) = await TaskUtils.WhenAll(
Server.WaitForRequest("/empty.html", request => request.Headers.ToDictionary(header => header.Key, header => header.Value)),
context.APIRequest.GetAsync(Server.CrossProcessPrefix + "/empty.html")
);
Assert.AreEqual(200, response.Status);
// Not sent to another origin.
Assert.AreEqual(false, requestHeaders.ContainsKey("Authorization"));
}
}

[PlaywrightTest("browsercontext-fetch.spec.ts", "delete should support post data")]
public async Task DeleteShouldSupportPostData()
{
Expand Down
8 changes: 0 additions & 8 deletions src/Playwright.Tests/BrowserContextStorageStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,6 @@ public async Task ShouldCaptureCookies()
var storageState = await Context.StorageStateAsync();
StringAssert.Contains(@"""name"":""a"",""value"":""b""", storageState);
StringAssert.Contains(@"""name"":""empty"",""value"":""""", storageState);
if (TestConstants.IsWebKit || TestConstants.IsFirefox)
{
StringAssert.Contains(@"""sameSite"":""None""", storageState);
}
else
{
StringAssert.Contains(@"""sameSite"":""Lax""", storageState);
}
StringAssert.DoesNotContain(@"""url"":null", storageState);

await using var context2 = await Browser.NewContextAsync(new() { StorageState = storageState });
Expand Down
92 changes: 92 additions & 0 deletions src/Playwright.Tests/BrowserTypeConnectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,98 @@ public async Task SetInputFilesShouldPreserveLastModifiedTimestamp()
Assert.LessOrEqual(Math.Abs(timestamps[i] - expectedTimestamps[i]), 1000);
}

[PlaywrightTest("page-set-input-files.spec.ts", "should upload a folder")]
public async Task ShouldUploadAFolder()
{
var browser = await BrowserType.ConnectAsync(_remoteServer.WSEndpoint);
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();

await page.GotoAsync(Server.Prefix + "/input/folderupload.html");
var input = await page.QuerySelectorAsync("input");
using var tmpDir = new TempDirectory();
var dir = Path.Combine(tmpDir.Path, "file-upload-test");
{
Directory.CreateDirectory(dir);
File.WriteAllText(Path.Combine(dir, "file1.txt"), "file1 content");
File.WriteAllText(Path.Combine(dir, "file2"), "file2 content");
Directory.CreateDirectory(Path.Combine(dir, "sub-dir"));
File.WriteAllText(Path.Combine(dir, "sub-dir", "really.txt"), "sub-dir file content");
}
await input.SetInputFilesAsync(dir);
var webkitRelativePaths = await input.EvaluateAsync<string[]>("e => [...e.files].map(f => f.webkitRelativePath)");
Assert.True(new HashSet<string> { "file-upload-test/sub-dir/really.txt", "file-upload-test/file1.txt", "file-upload-test/file2" }.SetEquals(new HashSet<string>(webkitRelativePaths)));
for (var i = 0; i < webkitRelativePaths.Length; i++)
{
var content = await input.EvaluateAsync<string>(@"(e, i) => {
const reader = new FileReader();
const promise = new Promise(fulfill => reader.onload = fulfill);
reader.readAsText(e.files[i]);
return promise.then(() => reader.result);
}", i);
Assert.AreEqual(File.ReadAllText(Path.Combine(dir, "..", webkitRelativePaths[i])), content);
}
}

[PlaywrightTest("page-set-input-files.spec.ts", "should upload a folder and throw for multiple directories")]
public async Task ShouldUploadAFolderAndThrowForMultipleDirectories()
{
var browser = await BrowserType.ConnectAsync(_remoteServer.WSEndpoint);
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();

await page.GotoAsync(Server.Prefix + "/input/folderupload.html");
var input = await page.QuerySelectorAsync("input");
using var tmpDir = new TempDirectory();
var dir = Path.Combine(tmpDir.Path, "file-upload-test");
{
Directory.CreateDirectory(Path.Combine(dir, "folder1"));
File.WriteAllText(Path.Combine(dir, "folder1", "file1.txt"), "file1 content");
Directory.CreateDirectory(Path.Combine(dir, "folder2"));
File.WriteAllText(Path.Combine(dir, "folder2", "file2.txt"), "file2 content");
}
var ex = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => input.SetInputFilesAsync(new string[] { Path.Combine(dir, "folder1"), Path.Combine(dir, "folder2") }));
Assert.AreEqual("Multiple directories are not supported", ex.Message);
}

[PlaywrightTest("page-set-input-files.spec.ts", "should throw if a directory and files are passed")]
public async Task ShouldThrowIfADirectoryAndFilesArePassed()
{
var browser = await BrowserType.ConnectAsync(_remoteServer.WSEndpoint);
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();

await page.GotoAsync(Server.Prefix + "/input/folderupload.html");
var input = await page.QuerySelectorAsync("input");
using var tmpDir = new TempDirectory();
var dir = Path.Combine(tmpDir.Path, "file-upload-test");
{
Directory.CreateDirectory(Path.Combine(dir, "folder1"));
File.WriteAllText(Path.Combine(dir, "folder1", "file1.txt"), "file1 content");
}
var ex = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => input.SetInputFilesAsync(new string[] { Path.Combine(dir, "folder1"), Path.Combine(dir, "folder1", "file1.txt") }));
Assert.AreEqual("File paths must be all files or a single directory", ex.Message);
}

[PlaywrightTest("page-set-input-files.spec.ts", "should throw when uploading a folder in a normal file upload input")]
public async Task ShouldThrowWhenUploadingAFolderInANormalFileUploadInput()
{
var browser = await BrowserType.ConnectAsync(_remoteServer.WSEndpoint);
var context = await browser.NewContextAsync();
var page = await context.NewPageAsync();

await page.GotoAsync(Server.Prefix + "/input/fileupload.html");
var input = await page.QuerySelectorAsync("input");
using var tmpDir = new TempDirectory();
var dir = Path.Combine(tmpDir.Path, "file-upload-test");
{
Directory.CreateDirectory(dir);
File.WriteAllText(Path.Combine(dir, "file1.txt"), "file1 content");
}
var ex = await PlaywrightAssert.ThrowsAsync<PlaywrightException>(() => input.SetInputFilesAsync(dir));
Assert.AreEqual("Error: File input does not support directories, pass individual files instead", ex.Message);
}

[PlaywrightTest("browsertype-connect.spec.ts", "should print custom ws close error")]
public async Task ShouldPrintCustomWsCloseError()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Playwright.Tests/DefaultBrowserContext1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task ContextCookiesShouldWork()
Assert.AreEqual(-1, cookie.Expires);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsFalse(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);

await context.DisposeAsync();
tmp.Dispose();
Expand Down Expand Up @@ -82,7 +82,7 @@ await context.AddCookiesAsync(new[]
Assert.AreEqual(-1, cookie.Expires);
Assert.IsFalse(cookie.HttpOnly);
Assert.IsFalse(cookie.Secure);
Assert.AreEqual(TestConstants.IsChromium ? SameSiteAttribute.Lax : SameSiteAttribute.None, cookie.SameSite);
Assert.AreEqual(DefaultSameSiteCookieValue, cookie.SameSite);

await context.DisposeAsync();
tmp.Dispose();
Expand Down
Loading

0 comments on commit 86ad6c7

Please sign in to comment.