Skip to content

Commit 53874e6

Browse files
authored
[dotnet] Remove System.Drawing.Common as package dependency (#12781)
* Remove Microsoft.IdentityModel.Tokens as dependency * Make it internal * Remove System.Drawing.Common as dependency * Move smoother, throw exception only for those who really uses image encoding/decoding * Remove obsolete methods to save screenshots with encoding
1 parent b0497bf commit 53874e6

File tree

8 files changed

+2
-109
lines changed

8 files changed

+2
-109
lines changed

dotnet/src/webdriver/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ csharp_library(
5252
deps = [
5353
framework("nuget", "NETStandard.Library"),
5454
framework("nuget", "Newtonsoft.Json"),
55-
framework("nuget", "System.Drawing.Common"),
5655
],
5756
)
5857

@@ -84,7 +83,6 @@ csharp_library(
8483
deps = [
8584
framework("nuget", "NETStandard.Library"),
8685
framework("nuget", "Newtonsoft.Json"),
87-
framework("nuget", "System.Drawing.Common"),
8886
],
8987
)
9088

dotnet/src/webdriver/Screenshot.cs

Lines changed: 1 addition & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,10 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.Drawing;
21-
using System.Drawing.Imaging;
2220
using System.IO;
2321

2422
namespace OpenQA.Selenium
2523
{
26-
/// <summary>
27-
/// File format for saving screenshots.
28-
/// </summary>
29-
[Obsolete("Support for decoding/encoding between different image formats is deprecated")]
30-
public enum ScreenshotImageFormat
31-
{
32-
/// <summary>
33-
/// W3C Portable Network Graphics image format.
34-
/// </summary>
35-
Png,
36-
37-
/// <summary>
38-
/// Joint Photgraphic Experts Group image format.
39-
/// </summary>
40-
Jpeg,
41-
42-
/// <summary>
43-
/// Graphics Interchange Format image format.
44-
/// </summary>
45-
Gif,
46-
47-
/// <summary>
48-
/// Tagged Image File Format image format.
49-
/// </summary>
50-
Tiff,
51-
52-
/// <summary>
53-
/// Bitmap image format.
54-
/// </summary>
55-
Bmp
56-
}
57-
5824
/// <summary>
5925
/// Represents an image of the page currently loaded in the browser.
6026
/// </summary>
@@ -76,69 +42,7 @@ public Screenshot(string base64EncodedScreenshot) : base(base64EncodedScreenshot
7642
/// <param name="fileName">The full path and file name to save the screenshot to.</param>
7743
public override void SaveAsFile(string fileName)
7844
{
79-
this.SaveAsFile(fileName, ScreenshotImageFormat.Png);
80-
}
81-
82-
/// <summary>
83-
/// Saves the screenshot to a file, overwriting the file if it already exists.
84-
/// </summary>
85-
/// <param name="fileName">The full path and file name to save the screenshot to.</param>
86-
/// <param name="format">A <see cref="ScreenshotImageFormat"/> value indicating the format
87-
/// to save the image to.</param>
88-
[Obsolete("Support for decoding/encoding between different image formats is deprecated; use SaveAsFile(string fileName) method instead")]
89-
public void SaveAsFile(string fileName, ScreenshotImageFormat format)
90-
{
91-
using (MemoryStream imageStream = new MemoryStream(this.AsByteArray))
92-
{
93-
using (FileStream fileStream = new FileStream(fileName, FileMode.Create))
94-
{
95-
// Optimization: The byte array is already a PNG, so we can just
96-
// write directly to the file. If the user wants to convert to
97-
// another image format, we'll allow them to do so, but on certain
98-
// framework versions (.NET 6 or above) this is likely to fail at
99-
// runtime. It is unclear how many Selenium users are using this
100-
// feature to convert the returned screenshot into a different image
101-
// format. Future mitigations of this issue would need to take a
102-
// dependency on an image processing library like ImageSharp or
103-
// similar.
104-
if (format == ScreenshotImageFormat.Png)
105-
{
106-
imageStream.WriteTo(fileStream);
107-
}
108-
else
109-
{
110-
using (Image screenshotImage = Image.FromStream(imageStream))
111-
{
112-
screenshotImage.Save(fileStream, ConvertScreenshotImageFormat(format));
113-
}
114-
}
115-
}
116-
}
117-
}
118-
119-
private static ImageFormat ConvertScreenshotImageFormat(ScreenshotImageFormat format)
120-
{
121-
ImageFormat returnedFormat = ImageFormat.Png;
122-
switch (format)
123-
{
124-
case ScreenshotImageFormat.Jpeg:
125-
returnedFormat = ImageFormat.Jpeg;
126-
break;
127-
128-
case ScreenshotImageFormat.Gif:
129-
returnedFormat = ImageFormat.Gif;
130-
break;
131-
132-
case ScreenshotImageFormat.Bmp:
133-
returnedFormat = ImageFormat.Bmp;
134-
break;
135-
136-
case ScreenshotImageFormat.Tiff:
137-
returnedFormat = ImageFormat.Tiff;
138-
break;
139-
}
140-
141-
return returnedFormat;
45+
File.WriteAllBytes(fileName, this.AsByteArray);
14246
}
14347
}
14448
}

dotnet/src/webdriver/WebDriver.StrongNamed.nuspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<dependencies>
2626
<group targetFramework="netstandard2.0">
2727
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
28-
<dependency id="System.Drawing.Common" version="7.0.0" exclude="Build,Analyzers" />
2928
</group>
3029
</dependencies>
3130
<frameworkAssemblies>

dotnet/src/webdriver/WebDriver.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161

6262
<ItemGroup>
6363
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
64-
<PackageReference Include="System.Drawing.Common" Version="7.0.0" />
6564
</ItemGroup>
6665

6766
<ItemGroup>

dotnet/src/webdriver/WebDriver.nuspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<dependencies>
2626
<group targetFramework="netstandard2.0">
2727
<dependency id="Newtonsoft.Json" version="13.0.1" exclude="Build,Analyzers" />
28-
<dependency id="System.Drawing.Common" version="7.0.0" exclude="Build,Analyzers" />
2928
</group>
3029
</dependencies>
3130
<frameworkAssemblies>

dotnet/test/common/TakesScreenshotTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void GetScreenshotAsFile()
2929

3030
string filename = Path.Combine(Path.GetTempPath(), "snapshot" + new Random().Next().ToString() + ".png");
3131
Screenshot screenImage = screenshotCapableDriver.GetScreenshot();
32-
screenImage.SaveAsFile(filename, ScreenshotImageFormat.Png);
32+
screenImage.SaveAsFile(filename);
3333
Assert.That(File.Exists(filename), Is.True);
3434
Assert.That(new FileInfo(filename).Length, Is.GreaterThan(0));
3535
File.Delete(filename);

dotnet/workspace.bzl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ def selenium_register_dotnet():
1717
sha256 = "2b6b52556e27e1b7913f33eedeb95568110c746bd64afff74357f1683878323a",
1818
)
1919

20-
import_nuget_package(
21-
name = "system.drawing.common",
22-
file = "third_party/dotnet/nuget/packages/system.drawing.common.7.0.0.nupkg",
23-
sha256 = "b78141813321b8e039140db77e0d1640e1ae1f49e357b8495d24ff2e7fd99e4b",
24-
)
25-
2620
import_nuget_package(
2721
name = "moq",
2822
file = "third_party/dotnet/nuget/packages/moq.4.12.0.nupkg",
Binary file not shown.

0 commit comments

Comments
 (0)