Skip to content

Commit

Permalink
Add support for appium driver
Browse files Browse the repository at this point in the history
  • Loading branch information
rosolko committed Jun 6, 2016
1 parent 032c78c commit 9dfac3e
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 3 deletions.
86 changes: 86 additions & 0 deletions WebDriverManager/BrowserManagers/AppiumDriverManager.cs
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);
}
}
}
44 changes: 41 additions & 3 deletions WebDriverManager/Helpers/WebDriverManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using NLog;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Net;
Expand All @@ -18,6 +19,8 @@ public static class WebDriverManager

private static string zip { get; set; } = null;

private static bool isNew { get; set; } = false;

/// <summary>
/// Build browser driver download URL from mock using config parameters
/// </summary>
Expand All @@ -35,7 +38,7 @@ private static string BuildUrl(string baseUrl, string release, string version, s
.Replace("<version>", version)
.Replace("<architecture>", architecture);
}
catch(Exception ex)
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);
Expand All @@ -53,7 +56,7 @@ private static void PrepareCatalogs(string path)
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
}
catch(Exception ex)
catch (Exception ex)
{
hLog.Error(ex, "Error occurred during browser driver catalog preparation");
throw new WebDriverManagerException("Error occurred during browser driver catalog preparation", ex);
Expand All @@ -71,7 +74,7 @@ private static string ZipFileName(string hreflink)
{
return Path.GetFileName(hreflink);
}
catch(Exception ex)
catch (Exception ex)
{
hLog.Error(ex, "Error occurred during getting browser driver archive name");
throw new WebDriverManagerException("Error occurred during getting browser driver archive name", ex);
Expand Down Expand Up @@ -129,7 +132,10 @@ public static void Unzip(WebDriverManagerConfig config)
}
}
}
isNew = true;
}
else
isNew = false;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -193,5 +199,37 @@ public static void UpdatePath(string variable)
throw new WebDriverManagerException("Error occurred during updating PATH environment variable", ex);
}
}

/// <summary>
/// Install application from file
/// </summary>
/// <param name="command">Installation command</param>
public static void Install(string command)
{
try
{
if (File.Exists(desticationFile) && isNew)
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
UseShellExecute = false,
WindowStyle = ProcessWindowStyle.Hidden,
FileName = desticationFile,
Arguments = command
};
Process process = new Process
{
StartInfo = startInfo
};
process.Start();
process.WaitForExit();
}
}
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);
}
}
}
}
1 change: 1 addition & 0 deletions WebDriverManager/WebDriverManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="BrowserManagers\InternetExplorerDriverManager.cs" />
<Compile Include="BrowserManagers\MarionetteDriverManager.cs" />
<Compile Include="BrowserManagers\OperaDriverManager.cs" />
<Compile Include="BrowserManagers\AppiumDriverManager.cs" />
<Compile Include="BrowserManagers\PhantomJsDriverManager.cs" />
<Compile Include="Helpers\Architecture.cs" />
<Compile Include="BrowserManagers\ChromeDriverManager.cs" />
Expand Down

0 comments on commit 9dfac3e

Please sign in to comment.