-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFirefoxWebDriverUpdater.cs
80 lines (55 loc) · 2.58 KB
/
FirefoxWebDriverUpdater.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using Gsemac.IO.Logging;
using Gsemac.Net.GitHub;
using Gsemac.Net.GitHub.Extensions;
using Gsemac.Net.Http;
using Gsemac.Net.WebBrowsers;
using System;
using System.Linq;
namespace Gsemac.Net.WebDrivers {
public class FirefoxWebDriverUpdater :
WebDriverUpdaterBase {
// Public members
public FirefoxWebDriverUpdater() :
this(Logger.Null) {
}
public FirefoxWebDriverUpdater(ILogger logger) :
this(WebDriverUpdaterOptions.Default, logger) {
}
public FirefoxWebDriverUpdater(IWebDriverUpdaterOptions webDriverUpdaterOptions) :
this(webDriverUpdaterOptions, Logger.Null) {
}
public FirefoxWebDriverUpdater(IWebDriverUpdaterOptions webDriverUpdaterOptions, ILogger logger) :
this(HttpWebRequestFactory.Default, webDriverUpdaterOptions, logger) {
}
public FirefoxWebDriverUpdater(IHttpWebRequestFactory webRequestFactory, IWebDriverUpdaterOptions webDriverUpdaterOptions) :
this(webRequestFactory, webDriverUpdaterOptions, Logger.Null) {
}
public FirefoxWebDriverUpdater(IHttpWebRequestFactory webRequestFactory, IWebDriverUpdaterOptions webDriverUpdaterOptions, ILogger logger) :
base(webRequestFactory, new WebDriverUpdaterOptions(webDriverUpdaterOptions) { WebBrowserId = WebBrowserId.Firefox }, logger) {
this.webRequestFactory = webRequestFactory;
}
// Protected members
protected override Uri GetWebDriverUri(IWebBrowserInfo webBrowserInfo) {
string releasesUrl = "https://github.com/mozilla/geckodriver/releases/latest";
IGitHubClient gitHubClient = new GitHubWebClient(webRequestFactory);
IRelease release = gitHubClient.GetLatestRelease(releasesUrl);
IReleaseAsset asset = release.Assets.Where(a => a.Name.Contains(GetPlatformOS()))
.FirstOrDefault();
if (!string.IsNullOrWhiteSpace(asset?.DownloadUrl))
return new Uri(asset.DownloadUrl);
// We weren't able to get information on the latest web driver.
return null;
}
protected override string GetWebDriverExecutablePath() {
return WebDriverUtilities.GeckoDriverExecutablePath;
}
// Private members
private readonly IHttpWebRequestFactory webRequestFactory;
private string GetPlatformOS() {
// For now, we'll focus on Windows.
return Environment.Is64BitOperatingSystem ?
"win64" :
"win32";
}
}
}