diff --git a/WebDriverManager/BrowserManagers/AppiumDriverManager.cs b/WebDriverManager/BrowserManagers/AppiumDriverManager.cs
index 6a71810..4bb1a3b 100644
--- a/WebDriverManager/BrowserManagers/AppiumDriverManager.cs
+++ b/WebDriverManager/BrowserManagers/AppiumDriverManager.cs
@@ -9,36 +9,37 @@
public class AppiumDriverManager : Logging, IBaseBrowserManager
{
- private readonly string installationCommand = "/SP- /silent /noicons /closeapplications /dir=expand:%1";
+ private const string InstallationCommand = "/SP- /silent /noicons /closeapplications /dir=expand:%1";
///
/// Set target appium driver architecture to x32 by default because of only 32 architecture presented
///
- WebDriverManagerConfig config = new WebDriverManagerConfig
+ private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
- binary = "appium-installer.exe",
- url = "https://bitbucket.org/appium/appium.app/downloads/AppiumForWindows_.zip",
- pathVariable = "appium.binary.path",
- architecture = Architecture.x32.ToString()
+ Binary = "appium-installer.exe",
+ Url = "https://bitbucket.org/appium/appium.app/downloads/AppiumForWindows_.zip",
+ PathVariable = "appium.binary.path",
+ Architecture = Architecture.X32.ToString()
};
public string GetLatestVersion()
{
try
{
- using (WebClient client = new WebClient())
+ using (var client = new WebClient())
{
- string version = null;
var doc = new HtmlDocument();
var htmlCode = client.DownloadString("https://bitbucket.org/appium/appium.app/downloads");
doc.LoadHtml(htmlCode);
- var itemList = doc.DocumentNode.SelectNodes("//tr[@class='iterable-item']/td[@class='name']/a[contains(.,'AppiumForWindows_')]").Select(p => p.InnerText).ToList();
+ var itemList =
+ doc.DocumentNode.SelectNodes(
+ "//tr[@class='iterable-item']/td[@class='name']/a[contains(.,'AppiumForWindows_')]")
+ .Select(p => p.InnerText)
+ .ToList();
var item = itemList.FirstOrDefault();
- version = item.Substring(item.IndexOf(item.Split('_')[1])).Split('.')[0];
- if (version != null || version != string.Empty)
- Log?.Info($"Latest appium driver version is '{version}'");
- else
- Log?.Warn($"Problem with getting latest appium driver version. Parsed version is '{version}'");
+ var version = item?.Substring(item.IndexOf(item.Split('_')[1], StringComparison.Ordinal))
+ .Split('.')[0];
+ Log?.Info($"Latest appium driver version is '{version}'");
return version;
}
}
@@ -50,37 +51,35 @@ public string GetLatestVersion()
}
public AppiumDriverManager()
- : base()
{
- config.version = GetLatestVersion();
+ _config.Version = GetLatestVersion();
}
public AppiumDriverManager(string version)
- : base()
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set appium driver version to: '{version}'");
}
public void Init()
{
- config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder);
+ _config.Destication = Path.Combine(Directory.GetCurrentDirectory(), _config.DefaultDestinationFolder);
Base();
}
public void Init(string destination)
{
- config.destication = destination;
+ _config.Destication = destination;
Log?.Info($"Set custom appium driver destination path to: '{destination}'");
Base();
}
public void Base()
{
- WebDriverManager.Download(config);
- WebDriverManager.Unzip(config);
+ WebDriverManager.Download(_config);
+ WebDriverManager.Unzip(_config);
WebDriverManager.Clean();
- WebDriverManager.Install(installationCommand);
+ WebDriverManager.Install(InstallationCommand);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/BrowserManagers/ChromeDriverManager.cs b/WebDriverManager/BrowserManagers/ChromeDriverManager.cs
index 829bbad..c0fbaef 100644
--- a/WebDriverManager/BrowserManagers/ChromeDriverManager.cs
+++ b/WebDriverManager/BrowserManagers/ChromeDriverManager.cs
@@ -10,34 +10,35 @@ public class ChromeDriverManager : Logging, IBaseBrowserManager
///
/// Set target chrome driver architecture to x32 by default because of only 32 architecture presented
///
- WebDriverManagerConfig config = new WebDriverManagerConfig
+ private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
- binary = "chromedriver.exe",
- url = "https://chromedriver.storage.googleapis.com//chromedriver_win.zip",
- pathVariable = "webdriver.chrome.driver",
- architecture = Architecture.x32.ToString().Replace("x", "")
+ Binary = "chromedriver.exe",
+ Url = "https://chromedriver.storage.googleapis.com//chromedriver_win.zip",
+ PathVariable = "webdriver.chrome.driver",
+ Architecture = Architecture.X32.ToString().Replace("x", "")
};
public string GetLatestVersion()
{
try
{
- string version = null;
var webRequest = WebRequest.Create(@"https://chromedriver.storage.googleapis.com/LATEST_RELEASE");
-
using (var response = webRequest.GetResponse())
{
using (var content = response.GetResponseStream())
{
- using (var reader = new StreamReader(content))
+ if (content != null)
{
- version = reader.ReadToEnd().Trim();
- if (version != null || version != string.Empty)
+ using (var reader = new StreamReader(content))
+ {
+ var version = reader.ReadToEnd().Trim();
Log?.Info($"Latest chrome driver version is '{version}'");
- else
- Log?.Warn($"Problem with getting latest chrome driver version. Parsed version is '{version}'");
- return version;
+ return version;
+ }
}
+ Log?.Error("Can't get content from URL");
+ throw new WebDriverManagerException(
+ "Can't get content from URL", new Exception());
}
}
}
@@ -49,39 +50,37 @@ public string GetLatestVersion()
}
public ChromeDriverManager()
- : base()
{
- config.version = GetLatestVersion();
+ _config.Version = GetLatestVersion();
}
public ChromeDriverManager(string version)
- : base()
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set chrome driver version to: '{version}'");
}
public void Init()
{
- config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder);
- Log?.Debug($"Use default chrome driver destination path: '{config.destication}'");
+ _config.Destication = Path.Combine(Directory.GetCurrentDirectory(), _config.DefaultDestinationFolder);
+ Log?.Debug($"Use default chrome driver destination path: '{_config.Destication}'");
Base();
}
public void Init(string destination)
{
- config.destication = destination;
+ _config.Destication = destination;
Log?.Info($"Set custom chrome driver destination path to: '{destination}'");
Base();
}
public void Base()
{
- WebDriverManager.Download(config);
- WebDriverManager.Unzip(config);
+ WebDriverManager.Download(_config);
+ WebDriverManager.Unzip(_config);
WebDriverManager.Clean();
- WebDriverManager.AddEnvironmentVariable(config.pathVariable);
- WebDriverManager.UpdatePath(config.pathVariable);
+ WebDriverManager.AddEnvironmentVariable(_config.PathVariable);
+ WebDriverManager.UpdatePath(_config.PathVariable);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/BrowserManagers/EdgeDriverManager.cs b/WebDriverManager/BrowserManagers/EdgeDriverManager.cs
index e973733..a70c1bb 100644
--- a/WebDriverManager/BrowserManagers/EdgeDriverManager.cs
+++ b/WebDriverManager/BrowserManagers/EdgeDriverManager.cs
@@ -9,30 +9,28 @@
public class EdgeDriverManager : Logging, IBaseBrowserManager
{
- WebDriverManagerConfig config = new WebDriverManagerConfig
+ private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
- binary = "MicrosoftWebDriver.exe",
- url = string.Empty,
- pathVariable = "webdriver.edge.driver",
- architecture = Architecture.x32.ToString()
+ Binary = "MicrosoftWebDriver.exe",
+ Url = string.Empty,
+ PathVariable = "webdriver.edge.driver",
+ Architecture = Architecture.X32.ToString()
};
public string GetLatestVersion()
{
try
{
- using (WebClient client = new WebClient())
+ using (var client = new WebClient())
{
- string version = null;
var doc = new HtmlDocument();
- var htmlCode = client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
+ var htmlCode =
+ client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
doc.LoadHtml(htmlCode);
- var itemList = doc.DocumentNode.SelectNodes("//ul[contains(@class, 'subsection__body')]//p[2]").Select(p => p.InnerText).ToList();
- version = itemList.FirstOrDefault().Split(' ')[1].Split(' ')[0];
- if (version != null || version != string.Empty)
- Log?.Info($"Latest edge driver version is '{version}'");
- else
- Log?.Warn($"Problem with getting latest edge driver version. Parsed version is '{version}'");
+ var itemList = doc.DocumentNode.SelectNodes("//ul[contains(@class, 'subsection__body')]//p[2]")
+ .Select(p => p.InnerText).ToList();
+ var version = itemList.FirstOrDefault()?.Split(' ')[1].Split(' ')[0];
+ Log?.Info($"Latest edge driver version is '{version}'");
return version;
}
}
@@ -47,18 +45,16 @@ public string GetDownloadUrl()
{
try
{
- using (WebClient client = new WebClient())
+ using (var client = new WebClient())
{
- string url = null;
var doc = new HtmlDocument();
- var htmlCode = client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
+ var htmlCode =
+ client.DownloadString("https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver");
doc.LoadHtml(htmlCode);
- var itemList = doc.DocumentNode.SelectNodes("//ul[contains(@class, 'subsection__body')]//p[1]/a").Select(p => p.GetAttributeValue("href", null)).ToList();
- url = itemList.FirstOrDefault();
- if (url != null || url != string.Empty)
- Log?.Info($"Edge driver download url is '{url}'");
- else
- Log?.Warn($"Problem with getting edge driver download url. Parsed url is '{url}'");
+ var itemList = doc.DocumentNode.SelectNodes("//ul[contains(@class, 'subsection__body')]//p[1]/a")
+ .Select(p => p.GetAttributeValue("href", null)).ToList();
+ var url = itemList.FirstOrDefault();
+ Log?.Info($"Edge driver download url is '{url}'");
return url;
}
}
@@ -70,30 +66,29 @@ public string GetDownloadUrl()
}
public EdgeDriverManager()
- : base()
{
- config.version = GetLatestVersion();
- config.url = GetDownloadUrl();
+ _config.Version = GetLatestVersion();
+ _config.Url = GetDownloadUrl();
}
public void Init()
{
- config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder);
+ _config.Destication = Path.Combine(Directory.GetCurrentDirectory(), _config.DefaultDestinationFolder);
Base();
}
public void Init(string destination)
{
- config.destication = destination;
+ _config.Destication = destination;
Log?.Debug($"Set custom edge driver destination path to: '{destination}'");
Base();
}
public void Base()
{
- WebDriverManager.Download(config);
- WebDriverManager.AddEnvironmentVariable(config.pathVariable);
- WebDriverManager.UpdatePath(config.pathVariable);
+ WebDriverManager.Download(_config);
+ WebDriverManager.AddEnvironmentVariable(_config.PathVariable);
+ WebDriverManager.UpdatePath(_config.PathVariable);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/BrowserManagers/IBaseBrowserManager.cs b/WebDriverManager/BrowserManagers/IBaseBrowserManager.cs
index f30a32b..3ee6f73 100644
--- a/WebDriverManager/BrowserManagers/IBaseBrowserManager.cs
+++ b/WebDriverManager/BrowserManagers/IBaseBrowserManager.cs
@@ -24,4 +24,4 @@ public interface IBaseBrowserManager
///
void Base();
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/BrowserManagers/InternetExplorerDriverManager.cs b/WebDriverManager/BrowserManagers/InternetExplorerDriverManager.cs
index d0afb0b..accdd7e 100644
--- a/WebDriverManager/BrowserManagers/InternetExplorerDriverManager.cs
+++ b/WebDriverManager/BrowserManagers/InternetExplorerDriverManager.cs
@@ -9,37 +9,35 @@
public class InternetExplorerDriverManager : Logging, IBaseBrowserManager
{
- WebDriverManagerConfig config = new WebDriverManagerConfig
+ private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
- binary = "IEDriverServer.exe",
- url = "http://selenium-release.storage.googleapis.com//IEDriverServer__.zip",
- pathVariable = "webdriver.ie.driver",
- architecture = Architecture.x32.ToString().Replace("x", "Win")
+ Binary = "IEDriverServer.exe",
+ Url = "http://selenium-release.storage.googleapis.com//IEDriverServer__.zip",
+ PathVariable = "webdriver.ie.driver",
+ Architecture = Architecture.X32.ToString().Replace("x", "Win")
};
public string GetLatestVersion()
{
try
{
- using (WebClient client = new WebClient())
+ using (var client = new WebClient())
{
- string version = null;
var doc = new HtmlDocument();
var htmlCode = client.DownloadString("http://www.seleniumhq.org/download");
doc.LoadHtml(htmlCode);
- var itemList = doc.DocumentNode.SelectNodes("(//div[@id='mainContent']/p)[6]").Select(p => p.InnerText).ToList();
- version = itemList.FirstOrDefault().Split(' ')[2];
- if (version != null || version != string.Empty)
- Log?.Info($"Latest internet explorer driver version is '{version}'");
- else
- Log?.Warn($"Problem with getting latest internet explorer driver version. Parsed version is '{version}'");
+ var itemList = doc.DocumentNode.SelectNodes("(//div[@id='mainContent']/p)[6]")
+ .Select(p => p.InnerText).ToList();
+ var version = itemList.FirstOrDefault()?.Split(' ')[2];
+ Log?.Info($"Latest internet explorer driver version is '{version}'");
return version;
}
}
catch (Exception ex)
{
Log?.Error(ex, "Error occurred during getting last internet explorer driver version");
- throw new WebDriverManagerException("Error occurred during getting last internet explorer driver version", ex);
+ throw new WebDriverManagerException(
+ "Error occurred during getting last internet explorer driver version", ex);
}
}
@@ -52,48 +50,43 @@ private string GetRelease(string version)
{
try
{
- string release = null;
- release = version.Substring(0, version.LastIndexOf("."));
- if (release != null || release != string.Empty)
- Log?.Debug($"Internet explorer driver release number is '{release}'");
- else
- Log?.Warn($"Problem with getting internet explorer driver release number. Parsed release number is '{release}'");
+ var release = version.Substring(0, version.LastIndexOf(".", StringComparison.Ordinal));
+ Log?.Debug($"Internet explorer driver release number is '{release}'");
return release;
}
catch (Exception ex)
{
Log?.Error(ex, "Error occurred during getting last internet explorer driver release number");
- throw new WebDriverManagerException("Error occurred during getting last internet explorer driver release number", ex);
+ throw new WebDriverManagerException(
+ "Error occurred during getting last internet explorer driver release number", ex);
}
}
public InternetExplorerDriverManager()
- : base()
{
- config.version = GetLatestVersion();
- config.release = GetRelease(config.version);
+ _config.Version = GetLatestVersion();
+ _config.Release = GetRelease(_config.Version);
}
public InternetExplorerDriverManager(string version)
- : base()
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set internet explorer driver version to: '{version}'");
- config.release = GetRelease(config.version);
+ _config.Release = GetRelease(_config.Version);
}
public InternetExplorerDriverManager(Architecture architecture)
{
- config.version = GetLatestVersion();
- config.release = GetRelease(config.version);
+ _config.Version = GetLatestVersion();
+ _config.Release = GetRelease(_config.Version);
SetArchitecture(architecture);
}
public InternetExplorerDriverManager(string version, Architecture architecture)
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set internet explorer driver version to: '{version}'");
- config.release = GetRelease(config.version);
+ _config.Release = GetRelease(_config.Version);
SetArchitecture(architecture);
}
@@ -101,42 +94,43 @@ private void SetArchitecture(Architecture architecture)
{
switch (architecture)
{
- case Architecture.x32:
- {
- config.architecture = Architecture.x32.ToString().Replace("x", "Win");
- break;
- }
- case Architecture.x64:
- {
- config.architecture = Architecture.x64.ToString();
- break;
- }
- default:
+ case Architecture.X32:
+ {
+ _config.Architecture = Architecture.X32.ToString().Replace("x", "Win");
break;
+ }
+ case Architecture.X64:
+ {
+ _config.Architecture = Architecture.X64.ToString();
+ break;
+ }
+ default:
+ throw new ArgumentOutOfRangeException(nameof(architecture), architecture,
+ "Can't recognize architecture");
}
- Log?.Info($"Set internet explorer driver architecture to: '{config.architecture}'");
+ Log?.Info($"Set internet explorer driver architecture to: '{_config.Architecture}'");
}
public void Init()
{
- config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder);
+ _config.Destication = Path.Combine(Directory.GetCurrentDirectory(), _config.DefaultDestinationFolder);
Base();
}
public void Init(string destination)
{
- config.destication = destination;
+ _config.Destication = destination;
Log?.Info($"Set custom internet explorer driver destination path to: '{destination}'");
Base();
}
public void Base()
{
- WebDriverManager.Download(config);
- WebDriverManager.Unzip(config);
+ WebDriverManager.Download(_config);
+ WebDriverManager.Unzip(_config);
WebDriverManager.Clean();
- WebDriverManager.AddEnvironmentVariable(config.pathVariable);
- WebDriverManager.UpdatePath(config.pathVariable);
+ WebDriverManager.AddEnvironmentVariable(_config.PathVariable);
+ WebDriverManager.UpdatePath(_config.PathVariable);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/BrowserManagers/MarionetteDriverManager.cs b/WebDriverManager/BrowserManagers/MarionetteDriverManager.cs
index 465bcf3..424ff1c 100644
--- a/WebDriverManager/BrowserManagers/MarionetteDriverManager.cs
+++ b/WebDriverManager/BrowserManagers/MarionetteDriverManager.cs
@@ -13,32 +13,27 @@ public class MarionetteDriverManager : Logging, IBaseBrowserManager
/// Set target marionette driver architecture to x64 by default because of only 64 architecture presented
/// Set binary name as pattern because of it's changing in accordance with marionette driver version
///
- WebDriverManagerConfig config = new WebDriverManagerConfig
+ private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
- binary = "geckodriver.exe",
- url = "https://github.com/mozilla/geckodriver/releases/download/v/geckodriver-v-win64.zip",
- pathVariable = "webdriver.gecko.driver",
- architecture = Architecture.x64.ToString()
+ Binary = "geckodriver.exe",
+ Url = "https://github.com/mozilla/geckodriver/releases/download/v/geckodriver-v-win64.zip",
+ PathVariable = "webdriver.gecko.driver",
+ Architecture = Architecture.X64.ToString()
};
public string GetLatestVersion()
{
try
{
- using (WebClient client = new WebClient())
+ using (var client = new WebClient())
{
- string version = null;
var doc = new HtmlDocument();
var htmlCode = client.DownloadString("https://github.com/mozilla/geckodriver/releases");
doc.LoadHtml(htmlCode);
- var itemList = doc.DocumentNode.SelectNodes("//*[@class='release-title']/a").Select(p => p.InnerText).ToList();
- version = itemList.FirstOrDefault().Remove(0, 1);
- if (version != null || version != string.Empty)
- {
- Log?.Info($"Latest marionette driver version is '{version}'");
- }
- else
- Log?.Warn($"Problem with getting latest marionette driver version. Parsed version is '{version}'");
+ var itemList =
+ doc.DocumentNode.SelectNodes("//*[@class='release-title']/a").Select(p => p.InnerText).ToList();
+ var version = itemList.FirstOrDefault()?.Remove(0, 1);
+ Log?.Info($"Latest marionette driver version is '{version}'");
return version;
}
}
@@ -50,38 +45,36 @@ public string GetLatestVersion()
}
public MarionetteDriverManager()
- : base()
{
- config.version = GetLatestVersion();
+ _config.Version = GetLatestVersion();
}
public MarionetteDriverManager(string version)
- : base()
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set marionette driver version to: '{version}'");
}
public void Init()
{
- config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder);
+ _config.Destication = Path.Combine(Directory.GetCurrentDirectory(), _config.DefaultDestinationFolder);
Base();
}
public void Init(string destination)
{
- config.destication = destination;
+ _config.Destication = destination;
Log?.Info($"Set custom marionette driver destination path to: '{destination}'");
Base();
}
public void Base()
{
- WebDriverManager.Download(config);
- WebDriverManager.Unzip(config);
+ WebDriverManager.Download(_config);
+ WebDriverManager.Unzip(_config);
WebDriverManager.Clean();
- WebDriverManager.AddEnvironmentVariable(config.pathVariable);
- WebDriverManager.UpdatePath(config.pathVariable);
+ WebDriverManager.AddEnvironmentVariable(_config.PathVariable);
+ WebDriverManager.UpdatePath(_config.PathVariable);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/BrowserManagers/OperaDriverManager.cs b/WebDriverManager/BrowserManagers/OperaDriverManager.cs
index de503b5..33a827f 100644
--- a/WebDriverManager/BrowserManagers/OperaDriverManager.cs
+++ b/WebDriverManager/BrowserManagers/OperaDriverManager.cs
@@ -9,12 +9,13 @@
public class OperaDriverManager : Logging, IBaseBrowserManager
{
- WebDriverManagerConfig config = new WebDriverManagerConfig
+ private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
- binary = "operadriver.exe",
- url = "https://github.com/operasoftware/operachromiumdriver/releases/download/v/operadriver_.zip",
- pathVariable = "webdriver.opera.driver",
- architecture = Architecture.x32.ToString().Replace("x", "win")
+ Binary = "operadriver.exe",
+ Url =
+ "https://github.com/operasoftware/operachromiumdriver/releases/download/v/operadriver_.zip",
+ PathVariable = "webdriver.opera.driver",
+ Architecture = Architecture.X32.ToString().Replace("x", "win")
};
public string GetLatestVersion()
@@ -23,16 +24,13 @@ public string GetLatestVersion()
{
using (WebClient client = new WebClient())
{
- string version = null;
var doc = new HtmlDocument();
var htmlCode = client.DownloadString("https://github.com/operasoftware/operachromiumdriver/releases");
doc.LoadHtml(htmlCode);
- var itemList = doc.DocumentNode.SelectNodes("//*[@class='release-title']/a").Select(p => p.InnerText).ToList();
- version = itemList.FirstOrDefault();
- if (version != null || version != string.Empty)
- Log?.Info($"Latest opera driver version is '{version}'");
- else
- Log?.Warn($"Problem with getting latest opera driver version. Parsed version is '{version}'");
+ var itemList = doc.DocumentNode.SelectNodes("//*[@class='release-title']/a")
+ .Select(p => p.InnerText).ToList();
+ var version = itemList.FirstOrDefault();
+ Log?.Info($"Latest opera driver version is '{version}'");
return version;
}
}
@@ -44,27 +42,25 @@ public string GetLatestVersion()
}
public OperaDriverManager()
- : base()
{
- config.version = GetLatestVersion();
+ _config.Version = GetLatestVersion();
}
public OperaDriverManager(string version)
- : base()
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set opera driver version to: '{version}'");
}
public OperaDriverManager(Architecture architecture)
{
- config.version = GetLatestVersion();
+ _config.Version = GetLatestVersion();
SetArchitecture(architecture);
}
public OperaDriverManager(string version, Architecture architecture)
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set opera driver version to: '{version}'");
SetArchitecture(architecture);
}
@@ -73,42 +69,43 @@ private void SetArchitecture(Architecture architecture)
{
switch (architecture)
{
- case Architecture.x32:
- {
- config.architecture = Architecture.x32.ToString().Replace("x", "win");
- break;
- }
- case Architecture.x64:
- {
- config.architecture = Architecture.x64.ToString().Replace("x", "win");
- break;
- }
- default:
+ case Architecture.X32:
+ {
+ _config.Architecture = Architecture.X32.ToString().Replace("x", "win");
break;
+ }
+ case Architecture.X64:
+ {
+ _config.Architecture = Architecture.X64.ToString().Replace("x", "win");
+ break;
+ }
+ default:
+ throw new ArgumentOutOfRangeException(nameof(architecture), architecture,
+ "Can't recognize architecture");
}
- Log?.Info($"Set opera driver architecture to: '{config.architecture}'");
+ Log?.Info($"Set opera driver architecture to: '{_config.Architecture}'");
}
public void Init()
{
- config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder);
+ _config.Destication = Path.Combine(Directory.GetCurrentDirectory(), _config.DefaultDestinationFolder);
Base();
}
public void Init(string destination)
{
- config.destication = destination;
+ _config.Destication = destination;
Log?.Info($"Set custom opera driver destination path to: '{destination}'");
Base();
}
public void Base()
{
- WebDriverManager.Download(config);
- WebDriverManager.Unzip(config);
+ WebDriverManager.Download(_config);
+ WebDriverManager.Unzip(_config);
WebDriverManager.Clean();
- WebDriverManager.AddEnvironmentVariable(config.pathVariable);
- WebDriverManager.UpdatePath(config.pathVariable);
+ WebDriverManager.AddEnvironmentVariable(_config.PathVariable);
+ WebDriverManager.UpdatePath(_config.PathVariable);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/BrowserManagers/PhantomJsDriverManager.cs b/WebDriverManager/BrowserManagers/PhantomJsDriverManager.cs
index c91c088..3af2f7d 100644
--- a/WebDriverManager/BrowserManagers/PhantomJsDriverManager.cs
+++ b/WebDriverManager/BrowserManagers/PhantomJsDriverManager.cs
@@ -12,30 +12,29 @@ public class PhantomJsDriverManager : Logging, IBaseBrowserManager
///
/// Set target phantomjs driver architecture to x32 by default because of only 32 architecture presented
///
- WebDriverManagerConfig config = new WebDriverManagerConfig
+ private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
- binary = "phantomjs.exe",
- url = "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs--windows.zip",
- pathVariable = "phantomjs.binary.path",
- architecture = Architecture.x32.ToString().Replace("x", "")
+ Binary = "phantomjs.exe",
+ Url = "https://bitbucket.org/ariya/phantomjs/downloads/phantomjs--windows.zip",
+ PathVariable = "phantomjs.binary.path",
+ Architecture = Architecture.X32.ToString().Replace("x", "")
};
public string GetLatestVersion()
{
try
{
- using (WebClient client = new WebClient())
+ using (var client = new WebClient())
{
- string version = null;
var doc = new HtmlDocument();
var htmlCode = client.DownloadString("https://bitbucket.org/ariya/phantomjs/downloads");
doc.LoadHtml(htmlCode);
- var itemList = doc.DocumentNode.SelectNodes("//tr[@class='iterable-item']/td[@class='name']/a").Select(p => p.InnerText).ToList();
- version = itemList.FirstOrDefault().Split('-')[1];
- if (version != null || version != string.Empty)
- Log?.Info($"Latest phantomjs driver version is '{version}'");
- else
- Log?.Warn($"Problem with getting latest phantomjs driver version. Parsed version is '{version}'");
+ var itemList =
+ doc.DocumentNode.SelectNodes("//tr[@class='iterable-item']/td[@class='name']/a")
+ .Select(p => p.InnerText)
+ .ToList();
+ var version = itemList.FirstOrDefault()?.Split('-')[1];
+ Log?.Info($"Latest phantomjs driver version is '{version}'");
return version;
}
}
@@ -47,38 +46,36 @@ public string GetLatestVersion()
}
public PhantomJsDriverManager()
- : base()
{
- config.version = GetLatestVersion();
+ _config.Version = GetLatestVersion();
}
public PhantomJsDriverManager(string version)
- : base()
{
- config.version = version;
+ _config.Version = version;
Log?.Info($"Set phantomjs driver version to: '{version}'");
}
public void Init()
{
- config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder);
+ _config.Destication = Path.Combine(Directory.GetCurrentDirectory(), _config.DefaultDestinationFolder);
Base();
}
public void Init(string destination)
{
- config.destication = destination;
+ _config.Destication = destination;
Log?.Info($"Set custom phantomjs driver destination path to: '{destination}'");
Base();
}
public void Base()
{
- WebDriverManager.Download(config);
- WebDriverManager.Unzip(config);
+ WebDriverManager.Download(_config);
+ WebDriverManager.Unzip(_config);
WebDriverManager.Clean();
- WebDriverManager.AddEnvironmentVariable(config.pathVariable);
- WebDriverManager.UpdatePath(config.pathVariable);
+ WebDriverManager.AddEnvironmentVariable(_config.PathVariable);
+ WebDriverManager.UpdatePath(_config.PathVariable);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/Helpers/Architecture.cs b/WebDriverManager/Helpers/Architecture.cs
index ac6cfd8..1dd4201 100644
--- a/WebDriverManager/Helpers/Architecture.cs
+++ b/WebDriverManager/Helpers/Architecture.cs
@@ -2,6 +2,7 @@
{
public enum Architecture
{
- x32 = 32, x64 = 64
+ X32 = 32,
+ X64 = 64
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/Helpers/Logging.cs b/WebDriverManager/Helpers/Logging.cs
index a9e7b4a..f00699b 100644
--- a/WebDriverManager/Helpers/Logging.cs
+++ b/WebDriverManager/Helpers/Logging.cs
@@ -11,4 +11,4 @@ protected Logging()
Log = LogManager.GetLogger(GetType().FullName);
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/Helpers/WebDriverManager.cs b/WebDriverManager/Helpers/WebDriverManager.cs
index c04b357..b537298 100644
--- a/WebDriverManager/Helpers/WebDriverManager.cs
+++ b/WebDriverManager/Helpers/WebDriverManager.cs
@@ -9,17 +9,17 @@
public static class WebDriverManager
{
- private static Logger hLog = LogManager.GetCurrentClassLogger();
+ private static readonly Logger HLog = LogManager.GetCurrentClassLogger();
- private static string desticationFolder { get; set; } = null;
+ private static string DesticationFolder { get; set; }
- private static string desticationZip { get; set; } = null;
+ private static string DesticationZip { get; set; }
- private static string desticationFile { get; set; } = null;
+ private static string DesticationFile { get; set; }
- private static string zip { get; set; } = null;
+ private static string Zip { get; set; }
- private static bool isNew { get; set; } = false;
+ private static bool IsNew { get; set; }
///
/// Build browser driver download URL from mock using config parameters
@@ -40,8 +40,9 @@ private static string BuildUrl(string baseUrl, string release, string version, s
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during building browser driver archive download URL");
- throw new WebDriverManagerException("Error occurred during building browser driver archive download URL", ex);
+ HLog.Error(ex, "Error occurred during building browser driver archive download URL");
+ throw new WebDriverManagerException(
+ "Error occurred during building browser driver archive download URL", ex);
}
}
@@ -58,7 +59,7 @@ private static void PrepareCatalogs(string path)
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during browser driver catalog preparation");
+ HLog.Error(ex, "Error occurred during browser driver catalog preparation");
throw new WebDriverManagerException("Error occurred during browser driver catalog preparation", ex);
}
}
@@ -76,7 +77,7 @@ private static string ZipFileName(string hreflink)
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during getting browser driver archive name");
+ HLog.Error(ex, "Error occurred during getting browser driver archive name");
throw new WebDriverManagerException("Error occurred during getting browser driver archive name", ex);
}
}
@@ -87,24 +88,24 @@ private static string ZipFileName(string hreflink)
/// Specific browser driver config
public static void Download(WebDriverManagerConfig config)
{
- using (WebClient webClient = new WebClient())
- {
- string url = BuildUrl(config.url, config.release, config.version, config.architecture);
- zip = ZipFileName(url);
- desticationFolder = Path.Combine(config.destication, Path.GetFileNameWithoutExtension(config.binary), config.version, config.architecture);
- desticationZip = Path.Combine(desticationFolder, zip);
- desticationFile = Path.Combine(desticationFolder, config.binary);
+ using (var webClient = new WebClient())
+ {
+ var url = BuildUrl(config.Url, config.Release, config.Version, config.Architecture);
+ Zip = ZipFileName(url);
+ var bin = Path.GetFileNameWithoutExtension(config.Binary);
+ if (bin != null)
+ DesticationFolder = Path.Combine(config.Destication, bin, config.Version, config.Architecture);
+ DesticationZip = Path.Combine(DesticationFolder, Zip);
+ DesticationFile = Path.Combine(DesticationFolder, config.Binary);
try
{
- if (!File.Exists(desticationFile))
- {
- PrepareCatalogs(desticationFolder);
- webClient.DownloadFile(url, desticationZip);
- }
+ if (File.Exists(DesticationFile)) return;
+ PrepareCatalogs(DesticationFolder);
+ webClient.DownloadFile(url, DesticationZip);
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during browser driver archive downloading");
+ HLog.Error(ex, "Error occurred during browser driver archive downloading");
throw new WebDriverManagerException("Error occurred during browser driver archive downloading", ex);
}
}
@@ -118,28 +119,28 @@ public static void Unzip(WebDriverManagerConfig config)
{
try
{
- desticationFile = Path.Combine(desticationFolder, config.binary);
+ DesticationFile = Path.Combine(DesticationFolder, config.Binary);
- if (!File.Exists(desticationFile))
+ if (!File.Exists(DesticationFile))
{
- using (ZipArchive zip = ZipFile.Open(desticationZip, ZipArchiveMode.Read))
+ using (var zip = ZipFile.Open(DesticationZip, ZipArchiveMode.Read))
{
- foreach (ZipArchiveEntry entry in zip.Entries)
+ foreach (var entry in zip.Entries)
{
- if (entry.Name == config.binary)
+ if (entry.Name == config.Binary)
{
- entry.ExtractToFile(desticationFile);
+ entry.ExtractToFile(DesticationFile);
}
}
}
- isNew = true;
+ IsNew = true;
}
else
- isNew = false;
+ IsNew = false;
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during browser driver archive extracting");
+ HLog.Error(ex, "Error occurred during browser driver archive extracting");
throw new WebDriverManagerException("Error occurred during browser driver archive extracting", ex);
}
}
@@ -151,13 +152,14 @@ public static void Clean()
{
try
{
- if (File.Exists(desticationZip))
- File.Delete(desticationZip);
+ if (File.Exists(DesticationZip))
+ File.Delete(DesticationZip);
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during deleting extracted browser driver archive");
- throw new WebDriverManagerException("Error occurred during deleting extracted browser driver archive", ex);
+ HLog.Error(ex, "Error occurred during deleting extracted browser driver archive");
+ throw new WebDriverManagerException("Error occurred during deleting extracted browser driver archive",
+ ex);
}
}
@@ -170,13 +172,14 @@ public static void AddEnvironmentVariable(string variable)
try
{
var variableValue = Environment.GetEnvironmentVariable(variable);
- if (variableValue == null || !variableValue.Equals(desticationFolder))
- Environment.SetEnvironmentVariable(variable, desticationFolder, EnvironmentVariableTarget.Machine);
+ if (variableValue == null || !variableValue.Equals(DesticationFolder))
+ Environment.SetEnvironmentVariable(variable, DesticationFolder, EnvironmentVariableTarget.Machine);
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during adding(updating) browser driver environment variable");
- throw new WebDriverManagerException("Error occurred during adding(updating) browser driver environment variable", ex);
+ HLog.Error(ex, "Error occurred during adding(updating) browser driver environment variable");
+ throw new WebDriverManagerException(
+ "Error occurred during adding(updating) browser driver environment variable", ex);
}
}
@@ -184,21 +187,20 @@ public static void AddEnvironmentVariable(string variable)
/// Update browser driver environment variable if it's already exist and different from current
///
/// Environment variable
- /// NOTE: Temporary disable this functionality because of wrong path override
+ // TODO : Temporary disable this functionality because of wrong path override
public static void UpdatePath(string variable)
{
try
{
- var name = "PATH";
- var pathVariable = Environment.GetEnvironmentVariable(name);
- var newPathVariable = pathVariable + (pathVariable.EndsWith(";") ? string.Empty : ";") + $@"%{variable}%";
-
- //if (!pathvar.Contains(desticationFolder) && !pathvar.Contains(variable))
- //Environment.SetEnvironmentVariable(newPathVariable, name, EnvironmentVariableTarget.Machine);
+// const string name = "PATH";
+// var pathVariable = Environment.GetEnvironmentVariable(name);
+// var newPathVariable = pathVariable + (pathVariable != null && pathVariable.EndsWith(";") ? string.Empty : ";") + $@"%{variable}%";
+// if (pathVariable != null && !pathVariable.Contains(DesticationFolder) && !pathVariable.Contains(variable))
+// Environment.SetEnvironmentVariable(newPathVariable, name, EnvironmentVariableTarget.Machine);
}
catch (Exception ex)
{
- hLog.Error(ex, "Error occurred during updating PATH environment variable");
+ HLog.Error(ex, "Error occurred during updating PATH environment variable");
throw new WebDriverManagerException("Error occurred during updating PATH environment variable", ex);
}
}
@@ -211,13 +213,13 @@ public static void Install(string command)
{
try
{
- if (File.Exists(desticationFile) && isNew)
+ if (File.Exists(DesticationFile) && IsNew)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
- FileName = desticationFile,
+ FileName = DesticationFile,
Arguments = command
};
Process process = new Process
@@ -230,9 +232,12 @@ public static void Install(string command)
}
catch (Exception ex)
{
- hLog.Error(ex, $"Error occurred during application installation from file '{desticationFile}' using command '{command}'");
- throw new WebDriverManagerException($"Error occurred during application installation from file '{desticationFile}' using command '{command}'", ex);
+ HLog.Error(ex,
+ $"Error occurred during application installation from file '{DesticationFile}' using command '{command}'");
+ throw new WebDriverManagerException(
+ $"Error occurred during application installation from file '{DesticationFile}' using command '{command}'",
+ ex);
}
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/Helpers/WebDriverManagerConfig.cs b/WebDriverManager/Helpers/WebDriverManagerConfig.cs
index d3dda09..7173ef2 100644
--- a/WebDriverManager/Helpers/WebDriverManagerConfig.cs
+++ b/WebDriverManager/Helpers/WebDriverManagerConfig.cs
@@ -4,18 +4,18 @@ public class WebDriverManagerConfig
{
public readonly string DefaultDestinationFolder = "Drivers";
- public string architecture { get; set; } = null;
+ public string Architecture { get; set; } = null;
- public string binary { get; set; } = null;
+ public string Binary { get; set; } = null;
- public string release { get; set; } = null;
+ public string Release { get; set; } = null;
- public string version { get; set; } = null;
+ public string Version { get; set; } = null;
- public string url { get; set; } = null;
+ public string Url { get; set; } = null;
- public string destication { get; set; } = null;
+ public string Destication { get; set; } = null;
- public string pathVariable { get; set; } = null;
+ public string PathVariable { get; set; } = null;
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/Helpers/WebDriverManagerException.cs b/WebDriverManager/Helpers/WebDriverManagerException.cs
index b04c31a..ee7c997 100644
--- a/WebDriverManager/Helpers/WebDriverManagerException.cs
+++ b/WebDriverManager/Helpers/WebDriverManagerException.cs
@@ -3,17 +3,17 @@
using System;
using System.Text;
- public class WebDriverManagerException : Exception
+ public sealed class WebDriverManagerException : Exception
{
- protected StringBuilder _sb = new StringBuilder();
+ private readonly StringBuilder _sb = new StringBuilder();
public WebDriverManagerException(string message, Exception innerException)
: base(message, innerException)
{
_sb.AppendLine($"Message: {message}");
- _sb.AppendLine($"Exception message: {base.Message}");
- _sb.AppendLine($"Exception stack trace: {base.StackTrace}");
- _sb.AppendLine($"InnerException: {innerException.ToString()}");
+ _sb.AppendLine($"Exception message: {Message}");
+ _sb.AppendLine($"Exception stack trace: {StackTrace}");
+ _sb.AppendLine($"InnerException: {innerException}");
}
public override string ToString()
@@ -21,4 +21,4 @@ public override string ToString()
return _sb.ToString();
}
}
-}
+}
\ No newline at end of file
diff --git a/WebDriverManager/Properties/AssemblyInfo.cs b/WebDriverManager/Properties/AssemblyInfo.cs
index c9e6f09..4dbcee1 100644
--- a/WebDriverManager/Properties/AssemblyInfo.cs
+++ b/WebDriverManager/Properties/AssemblyInfo.cs
@@ -1,17 +1,19 @@
-using System;
-using System.Reflection;
+using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
+
[assembly: AssemblyTitle("WebDriverManager.Net")]
[assembly: AssemblyDescription("Automatic Selenium WebDriver binaries management for .Net")]
#if DEBUG
+
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif
+
[assembly: AssemblyCompany("Alexander Rosolko")]
[assembly: AssemblyProduct("WebDriverManager.Net")]
[assembly: AssemblyCopyright("Copyright © Alexander Rosolko 2016")]
@@ -19,9 +21,11 @@
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
+
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
+
[assembly: Guid("0066742e-391b-407c-9dc1-ff71a60bec53")]
// Version information for an assembly consists of the following four values:
@@ -34,5 +38,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
//[assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.2.0")]
-[assembly: AssemblyFileVersion("1.2.0")]
+
+[assembly: AssemblyVersion("1.2.1")]
+[assembly: AssemblyFileVersion("1.2.1")]
\ No newline at end of file
diff --git a/WebDriverManager/WebDriverManager.csproj b/WebDriverManager/WebDriverManager.csproj
index e21e3c2..9c132b0 100644
--- a/WebDriverManager/WebDriverManager.csproj
+++ b/WebDriverManager/WebDriverManager.csproj
@@ -46,6 +46,9 @@
+
+ ..\..\..\..\..\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Xml.dll
+
@@ -77,7 +80,7 @@
-