Skip to content

Commit 8d14e1d

Browse files
alexeypatorosolko
authored andcommitted
Fix for use firefox driver on linux and mac (#60)
Closes #58
1 parent bdeedd6 commit 8d14e1d

File tree

7 files changed

+65
-13
lines changed

7 files changed

+65
-13
lines changed
109 Bytes
Binary file not shown.

WebDriverManager.Tests/BinaryServiceTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.IO;
1+
using System.IO;
22
using WebDriverManager.Helpers;
33
using WebDriverManager.Services.Impl;
44
using Xunit;
@@ -29,6 +29,16 @@ public void UnZipResultNotEmpty()
2929
Assert.True(File.Exists(result));
3030
}
3131

32+
[Fact]
33+
public void UnZipTgzResultNotEmpty()
34+
{
35+
var zipPath = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "gzip.tar.gz");
36+
var destination = FileHelper.GetBinDestination("Files", "2.0.0", Architecture.X32, "gzip.txt");
37+
FileHelper.CreateDestinationDirectory(destination);
38+
UnZipTgz(zipPath, destination);
39+
Assert.True(File.Exists(destination));
40+
}
41+
3242
[Fact]
3343
public void RemoveZipTargetMissing()
3444
{

WebDriverManager.Tests/WebDriverManager.Tests.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,10 @@
3333
</Content>
3434
</ItemGroup>
3535

36+
<ItemGroup>
37+
<None Update="Assets\gzip.tar.gz">
38+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
39+
</None>
40+
</ItemGroup>
41+
3642
</Project>

WebDriverManager/DriverConfigs/Impl/FirefoxConfig.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
using System.Linq;
1+
using System.Linq;
22
using System.Net;
3+
using System.Runtime.InteropServices;
34
using AngleSharp.Html.Parser;
5+
using Architecture = WebDriverManager.Helpers.Architecture;
46

57
namespace WebDriverManager.DriverConfigs.Impl
68
{
79
public class FirefoxConfig : IDriverConfig
810
{
11+
private const string DownloadUrl = "https://github.com/mozilla/geckodriver/releases/download/v<version>/geckodriver-v<version>-";
12+
913
public virtual string GetName()
1014
{
1115
return "Firefox";
1216
}
1317

1418
public virtual string GetUrl32()
1519
{
16-
return
17-
"https://github.com/mozilla/geckodriver/releases/download/v<version>/geckodriver-v<version>-win32.zip";
20+
return GetUrl(Architecture.X32);
1821
}
1922

2023
public virtual string GetUrl64()
2124
{
22-
return
23-
"https://github.com/mozilla/geckodriver/releases/download/v<version>/geckodriver-v<version>-win64.zip";
25+
return GetUrl(Architecture.X64);
2426
}
2527

2628
public virtual string GetBinaryName()
2729
{
28-
return "geckodriver.exe";
30+
return "geckodriver" + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty);
2931
}
3032

3133
public virtual string GetLatestVersion()
@@ -43,5 +45,17 @@ public virtual string GetLatestVersion()
4345
return version;
4446
}
4547
}
48+
49+
private static string GetUrl(Architecture architecture)
50+
{
51+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
52+
{
53+
return $"{DownloadUrl}macos.tar.gz";
54+
}
55+
56+
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
57+
? $"{DownloadUrl}linux{((int)architecture).ToString()}.tar.gz"
58+
: $"{DownloadUrl}win{((int)architecture).ToString()}.zip";
59+
}
4660
}
4761
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
using System;
1+
using System;
22

33
namespace WebDriverManager.Helpers
44
{
55
public static class ArchitectureHelper
66
{
77
public static Architecture GetArchitecture()
88
{
9-
return string.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))
10-
? Architecture.X32
11-
: Architecture.X64;
9+
return Environment.Is64BitOperatingSystem
10+
? Architecture.X64
11+
: Architecture.X32;
1212
}
1313
}
1414
}

WebDriverManager/Services/Impl/BinaryService.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
using System;
1+
using ICSharpCode.SharpZipLib.GZip;
2+
using System;
23
using System.Diagnostics;
34
using System.IO;
45
using System.IO.Compression;
56
using System.Net;
67
using System.Runtime.InteropServices;
8+
using ICSharpCode.SharpZipLib.Tar;
79
using WebDriverManager.Helpers;
810

911
namespace WebDriverManager.Services.Impl
@@ -21,10 +23,14 @@ public string SetupBinary(string url, string zipDestination, string binDestinati
2123
{
2224
File.Copy(zipDestination, binDestination);
2325
}
24-
else
26+
else if (zipDestination.EndsWith(".zip", StringComparison.OrdinalIgnoreCase))
2527
{
2628
UnZip(zipDestination, binDestination, binaryName);
2729
}
30+
else if (zipDestination.EndsWith(".tar.gz", StringComparison.OrdinalIgnoreCase))
31+
{
32+
UnZipTgz(zipDestination, binDestination);
33+
}
2834

2935
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
3036
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
@@ -71,6 +77,21 @@ protected string UnZip(string path, string destination, string name)
7177
return destination;
7278
}
7379

80+
protected void UnZipTgz(string gzArchiveName, string destination)
81+
{
82+
using (var inStream = File.OpenRead(gzArchiveName))
83+
{
84+
using (var gzipStream = new GZipInputStream(inStream))
85+
{
86+
var destFolder = Path.GetDirectoryName(destination);
87+
using (var tarArchive = TarArchive.CreateInputTarArchive(gzipStream))
88+
{
89+
tarArchive.ExtractContents(destFolder);
90+
}
91+
}
92+
}
93+
}
94+
7495
protected void RemoveZip(string path)
7596
{
7697
File.Delete(path);

WebDriverManager/WebDriverManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="AngleSharp" Version="0.13.0" />
20+
<PackageReference Include="SharpZipLib" Version="1.2.0" />
2021
</ItemGroup>
2122

2223
</Project>

0 commit comments

Comments
 (0)