Skip to content

Commit

Permalink
release: roll drivers to 1.9.2 (#1279)
Browse files Browse the repository at this point in the history
* fix(postData): add more network tests and port postData fix

* fix(tests): fixing broken tests after roll

* release: rolling driver version to v1.9.2

* chore(build): support release branches
  • Loading branch information
avodovnik authored Mar 12, 2021
1 parent b2b0746 commit 1069712
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ on:
push:
branches:
- main
- release-*
pull_request:
branches:
- main
- release-*

jobs:
test_net5:
Expand Down Expand Up @@ -121,4 +123,4 @@ jobs:
env:
PRODUCT: CHROMIUM
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && dotnet test ./src/PlaywrightSharp.Tests/PlaywrightSharp.Tests.csproj -c Debug -f netcoreapp3.1 --logger \"trx\""
xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- bash -c "ulimit -c unlimited && dotnet test ./src/PlaywrightSharp.Tests/PlaywrightSharp.Tests.csproj -c Debug -f netcoreapp3.1 --logger \"trx\""
6 changes: 3 additions & 3 deletions src/Common/PackageInfo.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project>
<PropertyGroup>
<AssemblyVersion>0.191.2</AssemblyVersion>
<AssemblyVersion>0.192.0</AssemblyVersion>
<PackageVersion>$(AssemblyVersion)</PackageVersion>
<DriverVersion>1.9.1-1614225150000</DriverVersion>
<DriverVersion>1.9.2</DriverVersion>
<ReleaseVersion>$(AssemblyVersion)</ReleaseVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<NoDefaultExcludes>true</NoDefaultExcludes>
Expand All @@ -15,4 +15,4 @@
<PackageReleaseNotes><![CDATA[
]]></PackageReleaseNotes>
</PropertyGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion src/PlaywrightSharp.Tests/BeforeUnloadTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public async Task ShouldRunBeforeunloadIfAskedFor()
// We have to interact with a page so that 'beforeunload' handlers
// fire.
await newPage.ClickAsync("body");

var dialogTask = newPage.WaitForEventAsync(PageEvent.Dialog);
var pageClosingTask = newPage.CloseAsync(true);
var dialog = await newPage.WaitForEventAsync(PageEvent.Dialog).ContinueWith(task => task.Result.Dialog);
var dialog = await dialogTask.ContinueWith(task => task.Result.Dialog);
Assert.Equal(DialogType.BeforeUnload, dialog.Type);
Assert.Empty(dialog.DefaultValue);
if (TestConstants.IsChromium)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public async Task ShouldBeCallableFromInsideAddInitScript()

args.Clear();
await page.ReloadAsync();
Assert.Equal(new List<object> { "context", "page" }, args);
Assert.Contains("context", args);
Assert.Contains("page", args);
}

[PlaywrightTest("browsercontext-expose-function.spec.ts", "exposeBindingHandle should work")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
namespace PlaywrightSharp.Tests
{
[Collection(TestConstants.TestFixtureBrowserCollectionName)]
public class BrowserContectPageEventTests : PlaywrightSharpBrowserBaseTest
public class BrowserContextPageEventTests : PlaywrightSharpBrowserBaseTest
{
/// <inheritdoc/>
public BrowserContectPageEventTests(ITestOutputHelper output) : base(output)
public BrowserContextPageEventTests(ITestOutputHelper output) : base(output)
{
}

Expand Down
2 changes: 1 addition & 1 deletion src/PlaywrightSharp.Tests/HarTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public async Task ShouldHavePages()
var pageEntry = log.Pages.First();
Assert.Equal("page_0", pageEntry.Id);
Assert.Equal("Hello", pageEntry.Title);
Assert.True(pageEntry.StartedDateTime > DateTime.Now.AddMinutes(-1));
Assert.True(pageEntry.StartedDateTime > DateTime.UtcNow.AddMinutes(-1));
Assert.True(pageEntry.PageTimings.OnContentLoad > 0);
Assert.True(pageEntry.PageTimings.OnLoad > 0);
}
Expand Down
120 changes: 120 additions & 0 deletions src/PlaywrightSharp.Tests/NetworkPostDataTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Threading.Tasks;
using PlaywrightSharp.Tests.BaseTests;
using Xunit;
using Xunit.Abstractions;


namespace PlaywrightSharp.Tests
{
/// <playwright-file>network-post-data.spec.ts</playwright-file>
[Collection(TestConstants.TestFixtureBrowserCollectionName)]
public sealed class NetworkPostDataTests : PlaywrightSharpPageBaseTest
{

/// <inheritdoc/>
public NetworkPostDataTests(ITestOutputHelper output) :
base(output)
{
}

/// <playwright-file>network-post-data.spec.ts</playwright-file>
/// <playwright-it>should return correct postData buffer for utf-8 body</playwright-it>
[Fact(Timeout = PlaywrightSharp.Playwright.DefaultTimeout)]
public async Task ShouldReturnCorrectPostdataBufferForUtf8Body()
{
await Page.GoToAsync(TestConstants.EmptyPage);
string value = "baẞ";

var task = Page.WaitForEventAsync(PageEvent.Request, (r) => true);
var actualTask = Page.EvaluateAsync(@$"() => {{
const request = new Request('{TestConstants.ServerUrl + "/title.html"}', {{
method: 'POST',
body: JSON.stringify('{value}'),
}});
request.headers.set('content-type', 'application/json;charset=UTF-8');
return fetch(request);
}}");

Task.WaitAll(task, actualTask);

string expectedJsonValue = JsonSerializer.Serialize(value, new JsonSerializerOptions
{
Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
WriteIndented = true
});

var request = task.Result.Request;
Assert.Equal(expectedJsonValue, request.PostData);
Assert.Equal(value, request.GetPostDataJson().RootElement.GetString());
}

/// <playwright-file>network-post-data.spec.ts</playwright-file>
/// <playwright-it>should return post data w/o content-type</playwright-it>
[Fact(Timeout = PlaywrightSharp.Playwright.DefaultTimeout)]
public async Task ShouldReturnPostDataWOContentType()
{
await Page.GoToAsync(TestConstants.EmptyPage);

var task = Page.WaitForEventAsync(PageEvent.Request, (r) => true);
var actualTask = Page.EvaluateAsync(@"(url) => {
const request = new Request(url, {
method: 'POST',
body: JSON.stringify({ value: 42 }),
});
request.headers.set('content-type', '');
return fetch(request);
}", TestConstants.ServerUrl + "/title.html");

Task.WaitAll(task, actualTask);

var request = task.Result.Request;
Assert.Equal(42, request.GetPostDataJson().RootElement.GetProperty("value").GetInt32());
}

/// <playwright-file>network-post-data.spec.ts</playwright-file>
/// <playwright-it>should throw on invalid JSON in post data</playwright-it>
[Fact(Timeout = PlaywrightSharp.Playwright.DefaultTimeout)]
public async Task ShouldThrowOnInvalidJSONInPostData()
{
await Page.GoToAsync(TestConstants.EmptyPage);

var task = Page.WaitForEventAsync(PageEvent.Request, (r) => true);
var actualTask = Page.EvaluateAsync(@"(url) => {
const request = new Request(url, {
method: 'POST',
body: '<not a json>',
});
return fetch(request);
}", TestConstants.ServerUrl + "/title.html");

Task.WaitAll(task, actualTask);

var request = task.Result.Request;
Assert.ThrowsAny<JsonException>(() => request.GetPostDataJson());
}

/// <playwright-file>network-post-data.spec.ts</playwright-file>
/// <playwright-it>should return post data for PUT requests</playwright-it>
[Fact(Timeout = PlaywrightSharp.Playwright.DefaultTimeout)]
public async Task ShouldReturnPostDataForPUTRequests()
{
await Page.GoToAsync(TestConstants.EmptyPage);

var task = Page.WaitForEventAsync(PageEvent.Request, (r) => true);
var actualTask = Page.EvaluateAsync(@"(url) => {
const request = new Request(url, {
method: 'PUT',
body: JSON.stringify({ value: 42 }),
});
return fetch(request);
}", TestConstants.ServerUrl + "/title.html");

Task.WaitAll(task, actualTask);

var request = task.Result.Request;
Assert.Equal(42, request.GetPostDataJson().RootElement.GetProperty("value").GetInt32());
}
}
}
6 changes: 3 additions & 3 deletions src/PlaywrightSharp.Tests/SelectorsTextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ public async Task ShouldBeCaseSensitiveIfQuotesAreSpecified()
Assert.Null(await Page.QuerySelectorAsync("text=\"yA\""));
}

[PlaywrightTest("selectors-text.spec.ts", "should search for a substring")]
[PlaywrightTest("selectors-text.spec.ts", "should search for a substring without quotes")]
[Fact(Timeout = TestConstants.DefaultTestTimeout)]
public async Task ShouldSearchForASubstring()
public async Task ShouldSearchForASubstringWithoutQuotes()
{
await Page.SetContentAsync("<div>textwithsubstring</div>");
Assert.Equal("<div>textwithsubstring</div>", await Page.EvalOnSelectorAsync<string>("text=with", "e => e.outerHTML"));
Assert.Equal("<div>textwithsubstring</div>", await Page.EvalOnSelectorAsync<string>("text=\"with\"", "e => e.outerHTML"));
Assert.Null(await Page.QuerySelectorAsync("text=\"with\""));
}

[PlaywrightTest("selectors-text.spec.ts", "should skip head, script and style")]
Expand Down
7 changes: 1 addition & 6 deletions src/PlaywrightSharp/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ private string GetRequestForJson()
return null;
}

if (Headers.TryGetValue("content-type", out string contentType) && string.IsNullOrEmpty(contentType))
{
return null;
}

if (contentType == "application/x-www-form-urlencoded")
if (Headers.TryGetValue("content-type", out string contentType) && contentType == "application/x-www-form-urlencoded")
{
var parsed = HttpUtility.ParseQueryString(PostData);
var dictionary = new Dictionary<string, string>();
Expand Down
2 changes: 1 addition & 1 deletion src/tools/PlaywrightSharp.Tooling/DriverDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static Task<string> GetUpstreamReadmeAsync(string playwrightVersion)
private async Task DownloadDriverAsync(DirectoryInfo destinationDirectory, string driverVersion, string platform, string runtime)
{
Console.WriteLine("Downloading driver for " + platform);
string cdn = "https://playwright.azureedge.net/builds/driver/next";
string cdn = "https://playwright.azureedge.net/builds/driver";

using var client = new HttpClient();
string url = $"{cdn}/playwright-{driverVersion}-{platform}.zip";
Expand Down

0 comments on commit 1069712

Please sign in to comment.