Skip to content

Commit b4720fc

Browse files
committed
Initial support for .NET Core
This will likely change significantly between now and when this support is actually released. Please do not rely on it yet.
1 parent eed161c commit b4720fc

File tree

11 files changed

+65582
-3
lines changed

11 files changed

+65582
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ third_party/java/jetty/jetty-repacked.jar
6565
*.user
6666
*.cache
6767
obj/
68+
obj_core/
6869
*.opensdf
6970
*.suo
7071
*.sdf

Directory.Build.props

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Project>
2+
<PropertyGroup Condition="$(MSBuildProjectName.Contains('.NetCore'))">
3+
<BaseIntermediateOutputPath>obj_core\</BaseIntermediateOutputPath>
4+
</PropertyGroup>
5+
</Project>

dotnet/WebDriver.NET.sln

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26430.16
4+
VisualStudioVersion = 15.0.26730.3
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDriver", "src\webdriver\WebDriver.csproj", "{EA31F748-5E32-476D-AB6D-FEA245B4AF1E}"
77
EndProject
@@ -31,6 +31,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebDriver.Opera.Tests", "te
3131
EndProject
3232
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Selenium.WebDriverBackedSelenium.Tests", "test\webdriverbackedselenium\Selenium.WebDriverBackedSelenium.Tests.csproj", "{7760D121-0C45-4083-83FD-3171F0CF9BF5}"
3333
EndProject
34+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebDriver.NetCore", "src\webdriver\WebDriver.NetCore.csproj", "{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}"
35+
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3638
Debug|Any CPU = Debug|Any CPU
@@ -93,8 +95,15 @@ Global
9395
{7760D121-0C45-4083-83FD-3171F0CF9BF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
9496
{7760D121-0C45-4083-83FD-3171F0CF9BF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
9597
{7760D121-0C45-4083-83FD-3171F0CF9BF5}.Release|Any CPU.Build.0 = Release|Any CPU
98+
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
99+
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Debug|Any CPU.Build.0 = Debug|Any CPU
100+
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Release|Any CPU.ActiveCfg = Release|Any CPU
101+
{08E3D8AB-CB2B-4DC5-9008-1AB20104E989}.Release|Any CPU.Build.0 = Release|Any CPU
96102
EndGlobalSection
97103
GlobalSection(SolutionProperties) = preSolution
98104
HideSolutionNode = FALSE
99105
EndGlobalSection
106+
GlobalSection(ExtensibilityGlobals) = postSolution
107+
SolutionGuid = {2DF40F4F-5B69-4CE2-BA2F-33AD71182B5C}
108+
EndGlobalSection
100109
EndGlobal

dotnet/src/webdriver/Firefox/Internal/Executable.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="Executable.cs" company="WebDriver Committers">
1+
// <copyright file="Executable.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -135,6 +135,9 @@ private static string LocateFirefoxBinaryFromPlatform()
135135
string binary = string.Empty;
136136
if (Platform.CurrentPlatform.IsPlatformType(PlatformType.Windows))
137137
{
138+
#if !NETCOREAPP2_0
139+
// NOTE: This code is legacy, and will be removed. It will not be
140+
// fixed for the .NET Core case.
138141
// Look first in HKEY_LOCAL_MACHINE, then in HKEY_CURRENT_USER
139142
// if it's not found there. If it's still not found, look in
140143
// the default install location (C:\Program Files\Mozilla Firefox).
@@ -151,6 +154,7 @@ private static string LocateFirefoxBinaryFromPlatform()
151154
}
152155
else
153156
{
157+
#endif
154158
// NOTE: Can't use Environment.SpecialFolder.ProgramFilesX86, because .NET 3.5
155159
// doesn't have that member of the enum.
156160
string[] windowsDefaultInstallLocations = new string[]
@@ -160,7 +164,9 @@ private static string LocateFirefoxBinaryFromPlatform()
160164
};
161165

162166
binary = GetExecutablePathUsingDefaultInstallLocations(windowsDefaultInstallLocations, "Firefox.exe");
167+
#if !NETCOREAPP2_0
163168
}
169+
#endif
164170
}
165171
else
166172
{
@@ -200,8 +206,11 @@ private static string LocateFirefoxBinaryFromPlatform()
200206
return FindBinary(new string[] { "firefox3", "firefox" });
201207
}
202208

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

225234
return path;
226235
}
236+
#endif
227237

228238
private static string GetExecutablePathUsingDefaultInstallLocations(string[] defaultInstallLocations, string exeName)
229239
{

dotnet/src/webdriver/Screenshot.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// <copyright file="Screenshot.cs" company="WebDriver Committers">
1+
// <copyright file="Screenshot.cs" company="WebDriver Committers">
22
// Licensed to the Software Freedom Conservancy (SFC) under one
33
// or more contributor license agreements. See the NOTICE file
44
// distributed with this work for additional information
@@ -17,8 +17,13 @@
1717
// </copyright>
1818

1919
using System;
20+
#if NETCOREAPP2_0
21+
using ImageSharp;
22+
using ImageSharp.Formats;
23+
#else
2024
using System.Drawing;
2125
using System.Drawing.Imaging;
26+
#endif
2227
using System.IO;
2328

2429
namespace OpenQA.Selenium
@@ -99,8 +104,16 @@ public void SaveAsFile(string fileName, ScreenshotImageFormat format)
99104
{
100105
using (MemoryStream imageStream = new MemoryStream(this.byteArray))
101106
{
107+
#if NETCOREAPP2_0
108+
Image<Rgba32> image = Image.Load(imageStream);
109+
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
110+
{
111+
image.Save(fileStream, ConvertScreenshotImageFormat(format));
112+
}
113+
#else
102114
Image screenshotImage = Image.FromStream(imageStream);
103115
screenshotImage.Save(fileName, ConvertScreenshotImageFormat(format));
116+
#endif
104117
}
105118
}
106119

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

129+
#if NETCOREAPP2_0
130+
private static IImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat format)
131+
{
132+
IImageFormat returnedFormat = ImageFormats.Png;
133+
switch (format)
134+
{
135+
case ScreenshotImageFormat.Jpeg:
136+
returnedFormat = ImageFormats.Jpeg;
137+
break;
138+
139+
case ScreenshotImageFormat.Gif:
140+
returnedFormat = ImageFormats.Gif;
141+
break;
142+
143+
case ScreenshotImageFormat.Bmp:
144+
returnedFormat = ImageFormats.Bitmap;
145+
break;
146+
147+
case ScreenshotImageFormat.Tiff:
148+
throw new WebDriverException("TIFF image format not supported by .NET Core library");
149+
}
150+
151+
return returnedFormat;
152+
}
153+
#else
116154
private static ImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat format)
117155
{
118156
ImageFormat returnedFormat = ImageFormat.Png;
@@ -137,5 +175,6 @@ private static ImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat fo
137175

138176
return returnedFormat;
139177
}
178+
#endif
140179
}
141180
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<AssemblyName>WebDriver.Net.Core</AssemblyName>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
9+
<OutputPath>..\..\..\build\cli\Debug\</OutputPath>
10+
</PropertyGroup>
11+
12+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
13+
<OutputPath>..\..\..\build\cli\Release\</OutputPath>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<Compile Remove="Properties\AssemblyInfo.cs" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<None Remove="BUCK" />
22+
<None Remove="build.desc" />
23+
<None Remove="Settings.StyleCop" />
24+
<None Remove="WebDriver.ruleset" />
25+
</ItemGroup>
26+
27+
<ItemGroup>
28+
<Reference Include="Newtonsoft.Json">
29+
<HintPath>..\..\..\third_party\dotnet\json-net-10.0r2\netstandard1.3\Newtonsoft.Json.dll</HintPath>
30+
</Reference>
31+
<Reference Include="ImageSharp">
32+
<HintPath>..\..\..\third_party\dotnet\imagesharp-1.0.0-alpha9-00182\netstandard1.3\ImageSharp.dll</HintPath>
33+
</Reference>
34+
</ItemGroup>
35+
36+
<ItemGroup>
37+
<Folder Include="Properties\" />
38+
</ItemGroup>
39+
40+
</Project>
Binary file not shown.

0 commit comments

Comments
 (0)