-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
namespace WebDriverManager.BrowserManagers | ||
{ | ||
using HtmlAgilityPack; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Net; | ||
using Helpers; | ||
|
||
public class AppiumDriverManager : Logging, IBaseBrowserManager | ||
{ | ||
private readonly 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 | ||
{ | ||
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()) | ||
{ | ||
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 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}'"); | ||
return version; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log?.Error(ex, "Error occurred during getting last appium driver version"); | ||
throw new WebDriverManagerException("Error occurred during getting last appium driver version", ex); | ||
} | ||
} | ||
|
||
public AppiumDriverManager() | ||
: base() | ||
{ | ||
config.version = GetLatestVersion(); | ||
} | ||
|
||
public AppiumDriverManager(string version) | ||
: base() | ||
{ | ||
config.version = version; | ||
Log?.Info($"Set appium driver version to: '{version}'"); | ||
} | ||
|
||
public void Init() | ||
{ | ||
config.destication = Path.Combine(Directory.GetCurrentDirectory(), config.DefaultDestinationFolder); | ||
Base(); | ||
} | ||
|
||
public void Init(string 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.Clean(); | ||
WebDriverManager.Install(installationCommand); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters