Skip to content

Commit

Permalink
refactor: reintroduce the .NET Framework 4.8 target framework (appium…
Browse files Browse the repository at this point in the history
…#740)

* refactor: reintroduce the .NET Framework 4.8 target framework into the project

* Update if condition so .NET 6+ would be the primary platform

Co-authored-by: MartyIX <[email protected]>

* chore: Use if condition for all .NET versions not just 6.0

* chore: Use latest LangVersion on Appium.Net.cspoj

* chore: update if statements to ignore NET48 and include more .NET versions

* Apply suggestions from code review

Co-authored-by: MartyIX <[email protected]>

* Update method name

Co-authored-by: MartyIX <[email protected]>

* fix: update method name where we call it

* chore: add ConfigureAwait(false) for NET48

---------

Co-authored-by: MartyIX <[email protected]>
  • Loading branch information
Dor-bl and MartyIX authored Feb 16, 2024
1 parent bc23280 commit a19eef0
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Appium.Net/Appium.Net.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<RootNamespace>OpenQA.Selenium</RootNamespace>
<Company>Appium Commiters</Company>
Expand All @@ -27,7 +27,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<PropertyGroup>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<NoWarn>1701;1702;1591</NoWarn>
Expand Down
38 changes: 32 additions & 6 deletions src/Appium.Net/Appium/Service/AppiumLocalService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
using System.IO;
using System.Linq;
using System.Net;
#if NET
using System.Net.Http;
#endif
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

Expand All @@ -37,7 +39,9 @@ public class AppiumLocalService : ICommandServer
private readonly int Port;
private readonly TimeSpan InitializationTimeout;
private readonly IDictionary<string, string> EnvironmentForProcess;
#if !NET48
private readonly HttpClient SharedHttpClient;
#endif
private Process Service;
private List<string> ArgsList;

Expand All @@ -61,9 +65,12 @@ internal AppiumLocalService(
Port = port;
InitializationTimeout = initializationTimeout;
EnvironmentForProcess = environmentForProcess;
#if !NET48
SharedHttpClient = CreateHttpClientInstance;
#endif
}

#if !NET48
private HttpClient CreateHttpClientInstance
{
get
Expand All @@ -75,7 +82,7 @@ private HttpClient CreateHttpClientInstance
return new HttpClient(handler);
}
}

#endif
/// <summary>
/// The base URL for the managed appium server.
/// </summary>
Expand Down Expand Up @@ -168,8 +175,9 @@ private void DestroyProcess()
finally
{
Service?.Close();

#if !NET48
SharedHttpClient.Dispose();
#endif
}
}

Expand Down Expand Up @@ -288,12 +296,20 @@ private async Task<bool> PingAsync(TimeSpan span)
{
try
{
#if NET48
HttpWebResponse response = await GetHttpResponseAsync(status).ConfigureAwait(false);
if (response.StatusCode == HttpStatusCode.OK)
{
return true;
}
#elif NET
HttpResponseMessage response = await GetHttpResponseAsync(status).ConfigureAwait(false);

if (response.IsSuccessStatusCode)
{
return true;
}
#endif
}
catch
{
Expand All @@ -302,11 +318,21 @@ private async Task<bool> PingAsync(TimeSpan span)
}
return pinged;
}

private async Task<HttpResponseMessage> GetHttpResponseAsync(Uri status)
#if NET48
private async Task<HttpWebResponse> GetHttpResponseAsync(Uri status)
{
HttpResponseMessage response = await SharedHttpClient.GetAsync(status).ConfigureAwait(false);
return response;
return await Task.Run(() =>
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(status);
return (HttpWebResponse)request.GetResponse();
}).ConfigureAwait(false);
}
#else
private async Task<HttpResponseMessage> GetHttpResponseAsync(Uri status)
{
HttpResponseMessage response = await SharedHttpClient.GetAsync(status).ConfigureAwait(false);
return response;
}
#endif
}
}
2 changes: 2 additions & 0 deletions test/integration/Android/ClipboardTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ public void WhenSetClipboardContentTypeIsImageSetClipboardShouldReturnNotImpleme
}

[Test]
#if !NET48
[SupportedOSPlatform("windows")]
#endif
public void WhenGetClipboardImageGetClipboardShouldReturnNotImplementedException()
{
Assert.That(() => _driver.GetClipboardImage(),
Expand Down
5 changes: 3 additions & 2 deletions test/integration/Appium.Net.Integration.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks>net48;net6.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<Compile Remove="apps\**" />
Expand Down

0 comments on commit a19eef0

Please sign in to comment.