-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
release: roll drivers to 1.9.2 (#1279)
* 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
Showing
10 changed files
with
139 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters