Skip to content

Commit 1a12920

Browse files
committed
Update chrome config to get latest version. Lock to 74 release.
Download to separate temp file wih guid as name to avoid access fails. Lock file during archive extracting.
1 parent 706389d commit 1a12920

File tree

9 files changed

+40
-24
lines changed

9 files changed

+40
-24
lines changed

WebDriverManager.Tests/BinaryServiceTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public void DownloadZipResultNotEmpty()
1212
{
1313
const string url = "https://chromedriver.storage.googleapis.com/2.27/chromedriver_win32.zip";
1414
var destination = FileHelper.GetZipDestination(url);
15+
FileHelper.CreateDestinationDirectory(destination);
1516
var result = DownloadZip(url, destination);
1617
Assert.NotEmpty(result);
1718
Assert.True(File.Exists(result));

WebDriverManager.Tests/VersionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class VersionData : IEnumerable<object[]>
1111
{
1212
private readonly List<object[]> _data = new List<object[]>
1313
{
14-
new object[] {new ChromeConfig(), @"^\d+\.\d+$"},
14+
new object[] {new ChromeConfig(), @"^\d+\.\d+.\d+.\d+$"},
1515
new object[] {new EdgeConfig(), @"^\d+\.\d+$"},
1616
new object[] {new FirefoxConfig(), @"^\d+\.\d+\.\d+$"},
1717
new object[] {new InternetExplorerConfig(), @"^\d+\.\d+\.\d+$"},

WebDriverManager/DriverConfigs/Impl/ChromeConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public virtual string GetBinaryName()
2828

2929
public virtual string GetLatestVersion()
3030
{
31-
var uri = new Uri("https://chromedriver.storage.googleapis.com/LATEST_RELEASE");
31+
var uri = new Uri("https://chromedriver.storage.googleapis.com/LATEST_RELEASE_74");
3232
var webRequest = WebRequest.Create(uri);
3333
using (var response = webRequest.GetResponse())
3434
{

WebDriverManager/DriverConfigs/Impl/EdgeConfig.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public virtual string GetLatestVersion()
3030
{
3131
using (var client = new WebClient())
3232
{
33-
var htmlCode = client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
33+
var htmlCode =
34+
client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
3435
var parser = new HtmlParser();
3536
var document = parser.ParseDocument(htmlCode);
3637
var version = document.QuerySelectorAll(".driver-download > a + p")
@@ -46,7 +47,8 @@ public virtual string GetUrl()
4647
{
4748
using (var client = new WebClient())
4849
{
49-
var htmlCode = client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
50+
var htmlCode =
51+
client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
5052
var parser = new HtmlParser();
5153
var document = parser.ParseDocument(htmlCode);
5254
var url = document.QuerySelectorAll(".driver-download > a")
@@ -57,4 +59,4 @@ public virtual string GetUrl()
5759
}
5860
}
5961
}
60-
}
62+
}

WebDriverManager/DriverConfigs/Impl/FirefoxConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ public virtual string GetLatestVersion()
4444
}
4545
}
4646
}
47-
}
47+
}

WebDriverManager/DriverConfigs/Impl/OperaConfig.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ public virtual string GetName()
1313

1414
public virtual string GetUrl32()
1515
{
16-
return "https://github.com/operasoftware/operachromiumdriver/releases/download/v.<version>/operadriver_win32.zip";
16+
return
17+
"https://github.com/operasoftware/operachromiumdriver/releases/download/v.<version>/operadriver_win32.zip";
1718
}
1819

1920
public virtual string GetUrl64()
2021
{
21-
return "https://github.com/operasoftware/operachromiumdriver/releases/download/v.<version>/operadriver_win64.zip";
22+
return
23+
"https://github.com/operasoftware/operachromiumdriver/releases/download/v.<version>/operadriver_win64.zip";
2224
}
2325

2426
public virtual string GetBinaryName()
@@ -41,4 +43,4 @@ public virtual string GetLatestVersion()
4143
}
4244
}
4345
}
44-
}
46+
}

WebDriverManager/DriverConfigs/Impl/PhantomConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ public virtual string GetLatestVersion()
4141
}
4242
}
4343
}
44-
}
44+
}

WebDriverManager/Helpers/FileHelper.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ public static class FileHelper
88
public static string GetZipDestination(string url)
99
{
1010
var tempDirectory = Path.GetTempPath();
11+
var guid = Guid.NewGuid().ToString();
1112
var zipName = Path.GetFileName(url);
1213
if (zipName == null) throw new ArgumentNullException($"Can't get zip name from URL: {url}");
13-
return Path.Combine(tempDirectory, zipName);
14+
return Path.Combine(tempDirectory, guid, zipName);
1415
}
1516

16-
public static string GetBinDestination(string driverName, string version, Architecture architecture, string binName)
17+
public static string GetBinDestination(string driverName, string version, Architecture architecture,
18+
string binName)
1719
{
1820
var currentDirectory = Directory.GetCurrentDirectory();
1921
return Path.Combine(currentDirectory, driverName, version, architecture.ToString(), binName);

WebDriverManager/Services/Impl/BinaryService.cs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ namespace WebDriverManager.Services.Impl
88
{
99
public class BinaryService : IBinaryService
1010
{
11+
static readonly object _object = new object();
12+
1113
public string SetupBinary(string url, string zipDestination, string binDestination, string binaryName)
1214
{
1315
if (File.Exists(binDestination)) return binDestination;
16+
FileHelper.CreateDestinationDirectory(zipDestination);
1417
zipDestination = DownloadZip(url, zipDestination);
1518
FileHelper.CreateDestinationDirectory(binDestination);
1619
binDestination = UnZip(zipDestination, binDestination, binaryName);
@@ -25,33 +28,39 @@ protected string DownloadZip(string url, string destination)
2528
{
2629
webClient.DownloadFile(new Uri(url), destination);
2730
}
31+
2832
return destination;
2933
}
3034

3135
protected string UnZip(string path, string destination, string name)
3236
{
33-
var zipName = Path.GetFileName(path);
34-
if (zipName != null && zipName.Equals(name, StringComparison.CurrentCultureIgnoreCase))
35-
{
36-
File.Copy(path, destination);
37-
return destination;
38-
}
39-
using (var zip = ZipFile.Open(path, ZipArchiveMode.Read))
37+
lock (_object)
4038
{
41-
foreach (var entry in zip.Entries)
39+
var zipName = Path.GetFileName(path);
40+
if (zipName != null && zipName.Equals(name, StringComparison.CurrentCultureIgnoreCase))
4241
{
43-
if (entry.Name == name)
42+
File.Copy(path, destination);
43+
return destination;
44+
}
45+
46+
using (var zip = ZipFile.Open(path, ZipArchiveMode.Read))
47+
{
48+
foreach (var entry in zip.Entries)
4449
{
45-
entry.ExtractToFile(destination, true);
50+
if (entry.Name == name)
51+
{
52+
entry.ExtractToFile(destination, true);
53+
}
4654
}
4755
}
56+
57+
return destination;
4858
}
49-
return destination;
5059
}
5160

5261
protected void RemoveZip(string path)
5362
{
5463
File.Delete(path);
5564
}
5665
}
57-
}
66+
}

0 commit comments

Comments
 (0)