Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rosolko committed Sep 5, 2016
1 parent 9b1ffd9 commit ac4ecbf
Show file tree
Hide file tree
Showing 17 changed files with 288 additions and 299 deletions.
47 changes: 23 additions & 24 deletions WebDriverManager/BrowserManagers/AppiumDriverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Set target appium driver architecture to x32 by default because of only 32 architecture presented
/// </summary>
WebDriverManagerConfig config = new WebDriverManagerConfig
private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
binary = "appium-installer.exe",
url = "https://bitbucket.org/appium/appium.app/downloads/AppiumForWindows_<version>.zip",
pathVariable = "appium.binary.path",
architecture = Architecture.x32.ToString()
Binary = "appium-installer.exe",
Url = "https://bitbucket.org/appium/appium.app/downloads/AppiumForWindows_<version>.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;
}
}
Expand All @@ -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);
}
}
}
}
49 changes: 24 additions & 25 deletions WebDriverManager/BrowserManagers/ChromeDriverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,35 @@ public class ChromeDriverManager : Logging, IBaseBrowserManager
/// <summary>
/// Set target chrome driver architecture to x32 by default because of only 32 architecture presented
/// </summary>
WebDriverManagerConfig config = new WebDriverManagerConfig
private readonly WebDriverManagerConfig _config = new WebDriverManagerConfig
{
binary = "chromedriver.exe",
url = "https://chromedriver.storage.googleapis.com/<version>/chromedriver_win<architecture>.zip",
pathVariable = "webdriver.chrome.driver",
architecture = Architecture.x32.ToString().Replace("x", "")
Binary = "chromedriver.exe",
Url = "https://chromedriver.storage.googleapis.com/<version>/chromedriver_win<architecture>.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());
}
}
}
Expand All @@ -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);
}
}
}
}
59 changes: 27 additions & 32 deletions WebDriverManager/BrowserManagers/EdgeDriverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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);
}
}
}
}
2 changes: 1 addition & 1 deletion WebDriverManager/BrowserManagers/IBaseBrowserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public interface IBaseBrowserManager
/// </summary>
void Base();
}
}
}

0 comments on commit ac4ecbf

Please sign in to comment.