Skip to content

Commit

Permalink
Initial support for .NET Core
Browse files Browse the repository at this point in the history
This will likely change significantly between now and when this support is
actually released. Please do not rely on it yet.
  • Loading branch information
jimevans committed Aug 16, 2017
1 parent eed161c commit b4720fc
Show file tree
Hide file tree
Showing 11 changed files with 65,582 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ third_party/java/jetty/jetty-repacked.jar
*.user
*.cache
obj/
obj_core/
*.opensdf
*.suo
*.sdf
Expand Down
5 changes: 5 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup Condition="$(MSBuildProjectName.Contains('.NetCore'))">
<BaseIntermediateOutputPath>obj_core\</BaseIntermediateOutputPath>
</PropertyGroup>
</Project>
11 changes: 10 additions & 1 deletion dotnet/WebDriver.NET.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDriver", "src\webdriver\WebDriver.csproj", "{EA31F748-5E32-476D-AB6D-FEA245B4AF1E}"
EndProject
Expand Down Expand Up @@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDriver.Opera.Tests", "te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Selenium.WebDriverBackedSelenium.Tests", "test\webdriverbackedselenium\Selenium.WebDriverBackedSelenium.Tests.csproj", "{7760D121-0C45-4083-83FD-3171F0CF9BF5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebDriver.NetCore", "src\webdriver\WebDriver.NetCore.csproj", "{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -93,8 +95,15 @@ Global
{7760D121-0C45-4083-83FD-3171F0CF9BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7760D121-0C45-4083-83FD-3171F0CF9BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7760D121-0C45-4083-83FD-3171F0CF9BF5}.Release|Any CPU.Build.0 = Release|Any CPU
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2DF40F4F-5B69-4CE2-BA2F-33AD71182B5C}
EndGlobalSection
EndGlobal
12 changes: 11 additions & 1 deletion dotnet/src/webdriver/Firefox/Internal/Executable.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="Executable.cs" company="WebDriver Committers">
// <copyright file="Executable.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
Expand Down Expand Up @@ -135,6 +135,9 @@ private static string LocateFirefoxBinaryFromPlatform()
string binary = string.Empty;
if (Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows))
{
#if !NETCOREAPP2_0
// NOTE: This code is legacy, and will be removed. It will not be
// fixed for the .NET Core case.
// Look first in HKEY_LOCAL_MACHINE, then in HKEY_CURRENT_USER
// if it's not found there. If it's still not found, look in
// the default install location (C:\Program Files\Mozilla Firefox).
Expand All @@ -151,6 +154,7 @@ private static string LocateFirefoxBinaryFromPlatform()
}
else
{
#endif
// NOTE: Can't use Environment.SpecialFolder.ProgramFilesX86, because .NET 3.5
// doesn't have that member of the enum.
string[] windowsDefaultInstallLocations = new string[]
Expand All @@ -160,7 +164,9 @@ private static string LocateFirefoxBinaryFromPlatform()
};

binary = GetExecutablePathUsingDefaultInstallLocations(windowsDefaultInstallLocations, "Firefox.exe");
#if !NETCOREAPP2_0
}
#endif
}
else
{
Expand Down Expand Up @@ -200,8 +206,11 @@ private static string LocateFirefoxBinaryFromPlatform()
return FindBinary(new string[] { "firefox3", "firefox" });
}

#if !NETCOREAPP2_0
private static string GetExecutablePathUsingRegistry(RegistryKey mozillaKey)
{
// NOTE: This code is legacy, and will be removed. It will not be
// fixed for the .NET Core case.
string currentVersion = (string)mozillaKey.GetValue("CurrentVersion");
if (string.IsNullOrEmpty(currentVersion))
{
Expand All @@ -224,6 +233,7 @@ private static string GetExecutablePathUsingRegistry(RegistryKey mozillaKey)

return path;
}
#endif

private static string GetExecutablePathUsingDefaultInstallLocations(string[] defaultInstallLocations, string exeName)
{
Expand Down
41 changes: 40 additions & 1 deletion dotnet/src/webdriver/Screenshot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="Screenshot.cs" company="WebDriver Committers">
// <copyright file="Screenshot.cs" company="WebDriver Committers">
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
Expand All @@ -17,8 +17,13 @@
// </copyright>

using System;
#if NETCOREAPP2_0
using ImageSharp;
using ImageSharp.Formats;
#else
using System.Drawing;
using System.Drawing.Imaging;
#endif
using System.IO;

namespace OpenQA.Selenium
Expand Down Expand Up @@ -99,8 +104,16 @@ public void SaveAsFile(string fileName, ScreenshotImageFormat format)
{
using (MemoryStream imageStream = new MemoryStream(this.byteArray))
{
#if NETCOREAPP2_0
Image<Rgba32> image = Image.Load(imageStream);
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
{
image.Save(fileStream, ConvertScreenshotImageFormat(format));
}
#else
Image screenshotImage = Image.FromStream(imageStream);
screenshotImage.Save(fileName, ConvertScreenshotImageFormat(format));
#endif
}
}

Expand All @@ -113,6 +126,31 @@ public override string ToString()
return this.base64Encoded;
}

#if NETCOREAPP2_0
private static IImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat format)
{
IImageFormat returnedFormat = ImageFormats.Png;
switch (format)
{
case ScreenshotImageFormat.Jpeg:
returnedFormat = ImageFormats.Jpeg;
break;

case ScreenshotImageFormat.Gif:
returnedFormat = ImageFormats.Gif;
break;

case ScreenshotImageFormat.Bmp:
returnedFormat = ImageFormats.Bitmap;
break;

case ScreenshotImageFormat.Tiff:
throw new WebDriverException("TIFF image format not supported by .NET Core library");
}

return returnedFormat;
}
#else
private static ImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat format)
{
ImageFormat returnedFormat = ImageFormat.Png;
Expand All @@ -137,5 +175,6 @@ private static ImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat fo

return returnedFormat;
}
#endif
}
}
40 changes: 40 additions & 0 deletions dotnet/src/webdriver/WebDriver.NetCore.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>WebDriver.Net.Core</AssemblyName>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputPath>..\..\..\build\cli\Debug\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>..\..\..\build\cli\Release\</OutputPath>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Properties\AssemblyInfo.cs" />
</ItemGroup>

<ItemGroup>
<None Remove="BUCK" />
<None Remove="build.desc" />
<None Remove="Settings.StyleCop" />
<None Remove="WebDriver.ruleset" />
</ItemGroup>

<ItemGroup>
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\..\third_party\dotnet\json-net-10.0r2\netstandard1.3\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="ImageSharp">
<HintPath>..\..\..\third_party\dotnet\imagesharp-1.0.0-alpha9-00182\netstandard1.3\ImageSharp.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>

</Project>
Binary file not shown.
Loading

0 comments on commit b4720fc

Please sign in to comment.