diff --git a/Lombiq.Tests.UI.Samples/Tests/BasicVisualVerificationTests.cs b/Lombiq.Tests.UI.Samples/Tests/BasicVisualVerificationTests.cs index a2372dec0..780c69b62 100644 --- a/Lombiq.Tests.UI.Samples/Tests/BasicVisualVerificationTests.cs +++ b/Lombiq.Tests.UI.Samples/Tests/BasicVisualVerificationTests.cs @@ -55,7 +55,7 @@ public Task VerifyBlogImage() => // is the different rendering of text on each platform, but it can occur between different Linux distributions too. // Here: https://pandasauce.org/post/linux-fonts/ you can find a good summary about this from 2019, but still valid // in 2022. - [Theory, Chrome, Edge] + [Theory, Chrome, Edge(Skip = "Until not resolved: https://github.com/atata-framework/atata-webdriversetup/issues/16")] public Task VerifyNavbar(Browser browser) => ExecuteTestAfterSetupAsync( context => diff --git a/Lombiq.Tests.UI.Samples/Tests/MultiBrowserTests.cs b/Lombiq.Tests.UI.Samples/Tests/MultiBrowserTests.cs index c410f92be..da473c6ec 100644 --- a/Lombiq.Tests.UI.Samples/Tests/MultiBrowserTests.cs +++ b/Lombiq.Tests.UI.Samples/Tests/MultiBrowserTests.cs @@ -23,7 +23,9 @@ public MultiBrowserTests(ITestOutputHelper testOutputHelper) // First, let's see a test using Edge. While the default browser is Chrome if you don't set anything, all // ExecuteTest* methods can also accept a browser, if you want to use a different one. - [Fact] +#pragma warning disable xUnit1004 + [Fact(Skip = "Until not resolved: https://github.com/atata-framework/atata-webdriversetup/issues/16")] +#pragma warning restore xUnit1004 public Task AnonymousHomePageShouldExistWithEdge() => ExecuteTestAfterSetupAsync(NavbarIsCorrect, Browser.Edge); @@ -31,7 +33,7 @@ public Task AnonymousHomePageShouldExistWithEdge() => // tests. [Chrome] and [Edge] are input parameters of the test, and thus in effect, you have now two tests: // AnonymousHomePageShouldExistMultiBrowser once with Chrome, and once with Edge. See here for more info: // https://andrewlock.net/creating-parameterised-tests-in-xunit-with-inlinedata-classdata-and-memberdata/. - [Theory, Chrome, Edge] + [Theory, Chrome, Edge(Skip = "Until not resolved: https://github.com/atata-framework/atata-webdriversetup/issues/16")] public Task AnonymousHomePageShouldExistMultiBrowser(Browser browser) => ExecuteTestAfterSetupAsync(NavbarIsCorrect, browser); diff --git a/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs b/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs index d7f2142ef..b4cc23aba 100644 --- a/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/HttpClientUITestContextExtensions.cs @@ -1,5 +1,4 @@ using Lombiq.Tests.UI.Services; -using Newtonsoft.Json.Linq; using Shouldly; using System; using System.Collections.Generic; @@ -25,6 +24,8 @@ namespace Lombiq.Tests.UI.Extensions; Justification = "Disposed by the HttpClient.")] public static class HttpClientUITestContextExtensions { + private static readonly JsonSerializerOptions JsonSerializerOptions = new(JsonSerializerDefaults.Web); + public static HttpClient CreateClient(this UITestContext context) { var handler = new HttpClientHandler @@ -102,8 +103,7 @@ public static async Task GetAndReadResponseContentAsync( where TObject : class { var content = await GetAndReadResponseContentAsync(context, client, requestUri); - var parsed = JToken.Parse(content); - return parsed.ToObject(); + return Deserialize(content); } /// @@ -117,7 +117,7 @@ public static async Task PostAndReadResponseContentAsync( string requestUri, string json) { - using var response = await PostAndGetResponseAsync(client, requestUri, json); + using var response = await PostAndGetResponseAsync(client, json, requestUri); return await response.Content.ReadAsStringAsync(); } @@ -129,16 +129,29 @@ public static async Task PostAndReadResponseContentAsync( public static async Task PostAndReadResponseContentAsync( this UITestContext context, HttpClient client, - string requestUri, - string json) - where TObject : class - { - using var response = await PostAndGetResponseAsync(client, requestUri, json); - var content = await response.Content.ReadAsStringAsync(); - var parsed = JToken.Parse(content); + string json, + string requestUri) + where TObject : class => + Deserialize(await context.PostAndReadResponseContentAsync( + client, + requestUri, + json)); - return parsed.ToObject(); - } + /// + /// Issues a POST request to the given using the provided + /// , that will be serialized as JSON, then the response content is deserialized + /// to the given and returned. + /// + public static async Task PostAndReadResponseContentAsync( + this UITestContext context, + HttpClient client, + object objectToSerialize, + string requestUri) + where TObject : class => + Deserialize(await context.PostAndReadResponseContentAsync( + client, + requestUri, + Serialize(objectToSerialize))); /// /// Issues a POST request to the given using the provided @@ -149,11 +162,8 @@ public static Task PostAndReadResponseContentAsync( this UITestContext context, HttpClient client, object objectToSerialize, - string requestUri) - { - var json = JsonSerializer.Serialize(objectToSerialize); - return PostAndReadResponseContentAsync(context, client, requestUri, json); - } + string requestUri) => + PostAndReadResponseContentAsync(context, client, requestUri, Serialize(objectToSerialize)); /// /// Issues a POST request to the given using the provided @@ -164,11 +174,8 @@ public static Task PostAndGetResponseAsync( this UITestContext context, HttpClient client, object objectToSerialize, - string requestUri) - { - var json = JsonSerializer.Serialize(objectToSerialize); - return PostAndGetResponseAsync(client, requestUri, json); - } + string requestUri) => + PostAndGetResponseAsync(client, Serialize(objectToSerialize), requestUri); /// /// Issues a POST request to the given using the provided . @@ -176,8 +183,8 @@ public static Task PostAndGetResponseAsync( /// The . public static async Task PostAndGetResponseAsync( HttpClient client, - string requestUri, - string json) + string json, + string requestUri) { var stringContent = new StringContent(json, Encoding.UTF8, MediaTypeNames.Application.Json); var response = await client.PostAsync(requestUri, stringContent); @@ -185,6 +192,11 @@ public static async Task PostAndGetResponseAsync( return response; } + /// + /// Issues a POST request to the given using the provided + /// , that will be serialized as JSON, then the response is checked if it's the + /// status code. + /// public static async Task PostAndResponseStatusCodeShouldBeAsync( this UITestContext context, HttpClient client, @@ -195,4 +207,18 @@ public static async Task PostAndResponseStatusCodeShouldBeAsync( using var response = await context.PostAndGetResponseAsync(client, objectToSerialize, requestUri); response.StatusCode.ShouldBe(expected); } + + /// + /// Returns the serialized object as JSON using the default settings. + /// + public static string Serialize(object objectToSerialize) => + JsonSerializer.Serialize(objectToSerialize, JsonSerializerOptions); + + /// + /// Deserializes the provided to the given using the + /// default settings. + /// + public static TObject Deserialize(string content) + where TObject : class => + JsonSerializer.Deserialize(content, JsonSerializerOptions); }