Skip to content

Commit a1713e6

Browse files
timoteirosolko
authored andcommitted
Support Chrome Web Driver for mac/linux (#38)
* Support Chrome Web Drivers for mac/linux * Update ChromeConfig.cs * Make the binary executable on linux/osx
1 parent a7aa31f commit a1713e6

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

WebDriverManager/DriverConfigs/Impl/ChromeConfig.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,50 @@
11
using System;
22
using System.IO;
33
using System.Net;
4+
using System.Runtime.InteropServices;
5+
using WebDriverManager.DriverConfigs;
46

57
namespace WebDriverManager.DriverConfigs.Impl
68
{
79
public class ChromeConfig : IDriverConfig
810
{
11+
private const string BaseVersionPatternUrl = "https://chromedriver.storage.googleapis.com/<version>/";
12+
913
public virtual string GetName()
1014
{
1115
return "Chrome";
1216
}
1317

1418
public virtual string GetUrl32()
1519
{
16-
return "https://chromedriver.storage.googleapis.com/<version>/chromedriver_win32.zip";
20+
return GetUrl();
1721
}
1822

1923
public virtual string GetUrl64()
2024
{
21-
return GetUrl32();
25+
return GetUrl();
26+
}
27+
28+
private string GetUrl()
29+
{
30+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
31+
{
32+
return $"{BaseVersionPatternUrl}chromedriver_mac64.zip";
33+
}
34+
35+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
36+
{
37+
return $"{BaseVersionPatternUrl}chromedriver_linux64.zip";
38+
}
39+
40+
return $"{BaseVersionPatternUrl}chromedriver_win32.zip";
2241
}
2342

2443
public virtual string GetBinaryName()
2544
{
26-
return "chromedriver.exe";
45+
var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
46+
var suffix = isWindows ? ".exe" : string.Empty;
47+
return $"chromedriver{suffix}";
2748
}
2849

2950
public virtual string GetLatestVersion()

WebDriverManager/Services/Impl/BinaryService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using System;
2+
using System.Diagnostics;
23
using System.IO;
34
using System.IO.Compression;
45
using System.Net;
6+
using System.Runtime.InteropServices;
57
using WebDriverManager.Helpers;
68

79
namespace WebDriverManager.Services.Impl
@@ -20,6 +22,13 @@ public string SetupBinary(string url, string zipDestination, string binDestinati
2022
{
2123
binDestination = UnZip(zipDestination, binDestination, binaryName);
2224
}
25+
26+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
27+
RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
28+
{
29+
var chmod = Process.Start("chmod", $"+x {binDestination}");
30+
chmod.WaitForExit();
31+
}
2332

2433
RemoveZip(zipDestination);
2534
return binDestination;

0 commit comments

Comments
 (0)