|
6 | 6 | # WebDriverManager.Net |
7 | 7 | This small library aimed to automate the [Selenium WebDriver] binaries management inside a .Net project. |
8 | 8 |
|
| 9 | +*You need run you IDE/program/tests with Administrator privileges* |
| 10 | + |
9 | 11 | 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. |
10 | 12 | 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). |
11 | 13 |
|
@@ -64,9 +66,8 @@ Notice that simple adding ``new DriverManager().SetUpDriver(<config>)`` does mag |
64 | 66 | 1. It checks the latest version of the WebDriver binary file |
65 | 67 | 2. It downloads the binary WebDriver if it is not present in your system |
66 | 68 |
|
67 | | -So far, WebDriverManager supports **Appium**, **Chrome**, **Microsoft Edge**, **Firefox(Marionette)**, **Internet Explorer**, **Opera** or **PhantomJS** configs (Just change <config> to prefered config): |
| 69 | +So far, WebDriverManager supports **Chrome**, **Microsoft Edge**, **Firefox(Marionette)**, **Internet Explorer**, **Opera** or **PhantomJS** configs (Just change <config> to prefered config): |
68 | 70 |
|
69 | | - new AppiumConfig(); |
70 | 71 | new ChromeConfig(); |
71 | 72 | new EdgeConfig(); |
72 | 73 | new FirefoxConfig(); |
@@ -99,38 +100,67 @@ Or version and architecture: |
99 | 100 | "chromedriver.exe" |
100 | 101 | ); |
101 | 102 |
|
102 | | -### If you want use your own implementation you need to create driver config and use it for set up: |
103 | | - public class CustomDriverConfig : IDriverConfig |
| 103 | +### If you want use your own implementation you need to create driver config and use it for set up(ex get, setup and wotk with phantomjs driver from taobao mirror): |
| 104 | + public class TaobaoPhantomConfig : IDriverConfig |
104 | 105 | { |
105 | 106 | public string GetName() |
106 | 107 | { |
107 | | - return "CustomDriverName"; |
| 108 | + return "TaobaoPhantom"; |
108 | 109 | } |
109 | 110 |
|
110 | 111 | public string GetUrl32() |
111 | 112 | { |
112 | | - return "https://someurl/<version>/win32.zip"; |
| 113 | + return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip"; |
113 | 114 | } |
114 | 115 |
|
115 | 116 | public string GetUrl64() |
116 | 117 | { |
117 | | - return "https://someurl/<version>/win64.zip"; |
| 118 | + return GetUrl32(); |
118 | 119 | } |
119 | 120 |
|
120 | 121 | public string GetBinaryName() |
121 | 122 | { |
122 | | - return "binary.name.exe"; |
| 123 | + return "phantomjs.exe"; |
123 | 124 | } |
124 | 125 |
|
125 | 126 | public string GetLatestVersion() |
126 | 127 | { |
127 | | - <some code that get and return latest version> |
| 128 | + using (var client = new WebClient()) |
| 129 | + { |
| 130 | + var doc = new HtmlDocument(); |
| 131 | + var htmlCode = client.DownloadString("https://bitbucket.org/ariya/phantomjs/downloads"); |
| 132 | + doc.LoadHtml(htmlCode); |
| 133 | + var itemList = |
| 134 | + doc.DocumentNode.SelectNodes("//tr[@class='iterable-item']/td[@class='name']/a") |
| 135 | + .Select(p => p.InnerText) |
| 136 | + .ToList(); |
| 137 | + var version = itemList.FirstOrDefault()?.Split('-')[1]; |
| 138 | + return version; |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + ... |
| 144 | + |
| 145 | + new DriverManager().SetUpDriver(new TaobaoPhantomConfig()); |
| 146 | + |
| 147 | +### Or you can modify existed drivers and change only necessary fields(same example): |
| 148 | + public class TaobaoPhantomConfig : PhantomConfig |
| 149 | + { |
| 150 | + public string GetName() |
| 151 | + { |
| 152 | + return "TaobaoPhantom"; |
| 153 | + } |
| 154 | + |
| 155 | + public string GetUrl32() |
| 156 | + { |
| 157 | + return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip"; |
128 | 158 | } |
129 | 159 | } |
130 | 160 |
|
131 | 161 | ... |
132 | 162 |
|
133 | | - new DriverManager().SetUpDriver(new CustomDriverConfig()); |
| 163 | + new DriverManager().SetUpDriver(new TaobaoPhantomConfig()); |
134 | 164 |
|
135 | 165 | ## About |
136 | 166 |
|
|
0 commit comments