Skip to content

Commit a447609

Browse files
committed
Lock full SetUpDriver method not only unzip. Fix dge driver name on mac os.
1 parent bab6601 commit a447609

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using WebDriverManager.DriverConfigs.Impl;
2+
using Xunit;
3+
4+
[assembly: CollectionBehavior(CollectionBehavior.CollectionPerClass, MaxParallelThreads = 2)]
5+
namespace WebDriverManager.Tests
6+
{
7+
public class DriverManagerTests
8+
{
9+
[Fact]
10+
public void ChromeTest()
11+
{
12+
new DriverManager().SetUpDriver(new ChromeConfig());
13+
}
14+
}
15+
16+
public class ParallelDriverManagerTests
17+
{
18+
[Fact]
19+
public void ParallelChromeTest()
20+
{
21+
new DriverManager().SetUpDriver(new ChromeConfig());
22+
}
23+
}
24+
}

WebDriverManager/DriverConfigs/Impl/EdgeConfig.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ public virtual string GetUrl64()
2828

2929
public virtual string GetBinaryName()
3030
{
31-
return "msedgedriver.exe";
31+
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX)
32+
? "msedgedriver.exe"
33+
: "msedgedriver";
3234
}
3335

3436
public virtual string GetLatestVersion()

WebDriverManager/DriverManager.cs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace WebDriverManager
77
{
88
public class DriverManager
99
{
10+
static readonly object _object = new object();
11+
1012
private readonly IBinaryService _binaryService;
1113
private readonly IVariableService _variableService;
1214

@@ -32,13 +34,18 @@ public void SetUpDriver(string url, string binaryPath, string binaryName)
3234
public void SetUpDriver(IDriverConfig config, string version = "Latest",
3335
Architecture architecture = Architecture.Auto)
3436
{
35-
architecture = architecture.Equals(Architecture.Auto) ? ArchitectureHelper.GetArchitecture() : architecture;
36-
version = version.Equals("Latest") ? config.GetLatestVersion() : version;
37-
var url = architecture.Equals(Architecture.X32) ? config.GetUrl32() : config.GetUrl64();
38-
url = UrlHelper.BuildUrl(url, version);
39-
var binaryPath = FileHelper.GetBinDestination(config.GetName(), version, architecture,
40-
config.GetBinaryName());
41-
SetUpDriver(url, binaryPath, config.GetBinaryName());
37+
lock (_object)
38+
{
39+
architecture = architecture.Equals(Architecture.Auto)
40+
? ArchitectureHelper.GetArchitecture()
41+
: architecture;
42+
version = version.Equals("Latest") ? config.GetLatestVersion() : version;
43+
var url = architecture.Equals(Architecture.X32) ? config.GetUrl32() : config.GetUrl64();
44+
url = UrlHelper.BuildUrl(url, version);
45+
var binaryPath = FileHelper.GetBinDestination(config.GetName(), version, architecture,
46+
config.GetBinaryName());
47+
SetUpDriver(url, binaryPath, config.GetBinaryName());
48+
}
4249
}
4350
}
4451
}

WebDriverManager/Services/Impl/BinaryService.cs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ namespace WebDriverManager.Services.Impl
1010
{
1111
public class BinaryService : IBinaryService
1212
{
13-
static readonly object _object = new object();
14-
1513
public string SetupBinary(string url, string zipDestination, string binDestination, string binaryName)
1614
{
1715
if (File.Exists(binDestination)) return binDestination;
@@ -52,28 +50,25 @@ protected string DownloadZip(string url, string destination)
5250

5351
protected string UnZip(string path, string destination, string name)
5452
{
55-
lock (_object)
53+
var zipName = Path.GetFileName(path);
54+
if (zipName != null && zipName.Equals(name, StringComparison.CurrentCultureIgnoreCase))
5655
{
57-
var zipName = Path.GetFileName(path);
58-
if (zipName != null && zipName.Equals(name, StringComparison.CurrentCultureIgnoreCase))
59-
{
60-
File.Copy(path, destination);
61-
return destination;
62-
}
56+
File.Copy(path, destination);
57+
return destination;
58+
}
6359

64-
using (var zip = ZipFile.Open(path, ZipArchiveMode.Read))
60+
using (var zip = ZipFile.Open(path, ZipArchiveMode.Read))
61+
{
62+
foreach (var entry in zip.Entries)
6563
{
66-
foreach (var entry in zip.Entries)
64+
if (entry.Name == name)
6765
{
68-
if (entry.Name == name)
69-
{
70-
entry.ExtractToFile(destination, true);
71-
}
66+
entry.ExtractToFile(destination, true);
7267
}
7368
}
74-
75-
return destination;
7669
}
70+
71+
return destination;
7772
}
7873

7974
protected void RemoveZip(string path)

0 commit comments

Comments
 (0)