WebDriverManager.Net
This small library aimed to automate the Selenium WebDriver binaries management inside a .Net project.
If you have ever used Selenium WebDriver, you probably know that in order to use some browsers (for example Chrome) you need to download a binary which allows WebDriver to handle the browser. In addition, the absolute path to this binary must be set as part of the PATH environment variable or manually copied to build output folder (working directory).
This is quite annoying since it forces you to link directly this binary in your source code. In addition, you have to check manually when new versions of the binaries are released. This library comes to the rescue, performing in an automated way all this dirty job for you.
WebDriverManager is open source, released under the terms of MIT license.
WebDriverManager.Net can be downloaded from NuGet. Use the GUI or the following command in the Package Manager Console:
PM> Install-Package WebDriverManager
Target is netstandard2.0.
After installation you can let WebDriverManager.Net to do manage WebDriver binaries for your application/test. Take a look to this NUnit example which uses Chrome with Selenium WebDriver:
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Chrome; using WebDriverManager; using WebDriverManager.DriverConfigs.Impl; namespace Test { [TestFixture] public class Tests { private IWebDriver _webDriver; [SetUp] public void SetUp() { new DriverManager().SetUpDriver(new ChromeConfig()); _webDriver = new ChromeDriver(); } [TearDown] public void TearDown() { _webDriver.Quit(); } [Test] public void Test() { _webDriver.Navigate().GoToUrl("https://www.google.com"); Assert.True(_webDriver.Title.Contains("Google")); } } }
Notice that simple adding new DriverManager().SetUpDriver(<config>)
does magic for you:
It checks the latest version of the WebDriver binary file
It downloads the binary WebDriver if it is not present in your system
So far, WebDriverManager supports Chrome, Microsoft Edge, Firefox(Marionette), Internet Explorer, Opera or PhantomJS configs (Just change to prefered config):
new ChromeConfig(); new EdgeConfig(); new FirefoxConfig(); new InternetExplorerConfig(); new OperaConfig(); new PhantomConfig();
You can use WebDriverManager in two ways:
Automatic
Manual
new DriverManager().SetUpDriver(new <Driver>Config());
You can also specify version: new DriverManager().SetUpDriver(new ChromeConfig(), "2.25")
Or architecture: new DriverManager().SetUpDriver(new ChromeConfig(), "Latest", Architecture.X32)
Or version and architecture: new DriverManager().SetUpDriver(new ChromeConfig(), "2.25", Architecture.X64)
new DriverManager().SetUpDriver( "https://chromedriver.storage.googleapis.com/2.25/chromedriver_win32.zip", Path.Combine(Directory.GetCurrentDirectory(), "chromedriver.exe"), "chromedriver.exe" );
public class TaobaoPhantomConfig : IDriverConfig { public string GetName() { return "TaobaoPhantom"; } public string GetUrl32() { return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip"; } public string GetUrl64() { return GetUrl32(); } public string GetBinaryName() { return "phantomjs.exe"; } public string GetLatestVersion() { using (var client = new WebClient()) { 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(); var version = itemList.FirstOrDefault()?.Split('-')[1]; return version; } } } ... new DriverManager().SetUpDriver(new TaobaoPhantomConfig());
public class CustomBinaryService : IBinaryService { public string SetupBinary(string url, string zipDestination, string binDestination, string binaryName) { ... // your implementation ... } } public class CustomVariableService : IVariableService { public void SetupVariable(string path) { ... // your implementation ... } } ... new DriverManager(new CustomBinaryService(), new CustomVariableService()).SetUpDriver(new FirefoxConfig());
public class TaobaoPhantomConfig : PhantomConfig { public override string GetName() { return "TaobaoPhantom"; } public override string GetUrl32() { return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip"; } } ... new DriverManager().SetUpDriver(new TaobaoPhantomConfig());
还没有评论,说两句吧!
热门资源
seetafaceJNI
项目介绍 基于中科院seetaface2进行封装的JAVA...
spark-corenlp
This package wraps Stanford CoreNLP annotators ...
Keras-ResNeXt
Keras ResNeXt Implementation of ResNeXt models...
capsnet-with-caps...
CapsNet with capsule-wise convolution Project ...
inferno-boilerplate
This is a very basic boilerplate example for pe...
智能在线
400-630-6780
聆听.建议反馈
E-mail: support@tusaishared.com