@@ -37,40 +37,42 @@ Target is **netstandard2.0**.
3737
3838After 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:
3939
40- using NUnit.Framework;
41- using OpenQA.Selenium;
42- using OpenQA.Selenium.Chrome;
43- using WebDriverManager;
44- using WebDriverManager.DriverConfigs.Impl;
45-
46- namespace Test
47- {
48- [TestFixture]
49- public class Tests
50- {
51- private IWebDriver _webDriver;
52-
53- [SetUp]
54- public void SetUp()
55- {
56- new DriverManager().SetUpDriver(new ChromeConfig());
57- _webDriver = new ChromeDriver();
58- }
59-
60- [TearDown]
61- public void TearDown()
62- {
63- _webDriver.Quit();
64- }
65-
66- [Test]
67- public void Test()
68- {
69- _webDriver.Navigate().GoToUrl("https://www.google.com");
70- Assert.True(_webDriver.Title.Contains("Google"));
71- }
72- }
73- }
40+ ``` csharp
41+ using NUnit .Framework ;
42+ using OpenQA .Selenium ;
43+ using OpenQA .Selenium .Chrome ;
44+ using WebDriverManager ;
45+ using WebDriverManager .DriverConfigs .Impl ;
46+
47+ namespace Test
48+ {
49+ [TestFixture ]
50+ public class Tests
51+ {
52+ private IWebDriver _webDriver ;
53+
54+ [SetUp ]
55+ public void SetUp ()
56+ {
57+ new DriverManager ().SetUpDriver (new ChromeConfig ());
58+ _webDriver = new ChromeDriver ();
59+ }
60+
61+ [TearDown ]
62+ public void TearDown ()
63+ {
64+ _webDriver .Quit ();
65+ }
66+
67+ [Test ]
68+ public void Test ()
69+ {
70+ _webDriver .Navigate ().GoToUrl (" https://www.google.com" );
71+ Assert .True (_webDriver .Title .Contains (" Google" ));
72+ }
73+ }
74+ }
75+ ```
7476
7577Notice that simply adding `` new DriverManager().SetUpDriver(<config>) `` does magic for you:
7678
@@ -79,12 +81,14 @@ Notice that simply adding ``new DriverManager().SetUpDriver(<config>)`` does mag
7981
8082So far, WebDriverManager supports ** Chrome** , ** Microsoft Edge** , ** Firefox(Marionette)** , ** Internet Explorer** , ** Opera** or ** PhantomJS** configs (Just change <config > to prefered config):
8183
82- new ChromeConfig();
83- new EdgeConfig();
84- new FirefoxConfig();
85- new InternetExplorerConfig();
86- new OperaConfig();
87- new PhantomConfig();
84+ ``` csharp
85+ new ChromeConfig ();
86+ new EdgeConfig ();
87+ new FirefoxConfig ();
88+ new InternetExplorerConfig ();
89+ new OperaConfig ();
90+ new PhantomConfig ();
91+ ```
8892
8993## Advanced
9094
@@ -93,117 +97,128 @@ You can use WebDriverManager in two ways:
93972 . Manual
9498
9599#### Automatic way:
96- new DriverManager().SetUpDriver(new <Driver>Config());
100+ ``` csharp
101+ new DriverManager ().SetUpDriver (new < Driver > Config ());
102+ ```
97103
98- You can also specify version:
104+ You can also specify version:
99105 `` new DriverManager().SetUpDriver(new ChromeConfig(), "2.25") ``
100106
101- Or architecture:
107+ Or architecture:
102108 `` new DriverManager().SetUpDriver(new ChromeConfig(), "Latest", Architecture.X32) ``
103109
104- Or version and architecture:
110+ Or version and architecture:
105111 `` new DriverManager().SetUpDriver(new ChromeConfig(), "2.25", Architecture.X64) ``
106112
107- Only for Google Chrome so far, you can specify to automatically download a ``` chromedriver.exe ``` matching the version of the browser that is installed in your machine:
113+ Only for Google Chrome so far, you can specify to automatically download a ``` chromedriver.exe ``` matching the version of the browser that is installed in your machine:
108114 `` new DriverManager().SetUpDriver(new ChromeConfig(), VersionResolveStrategy.MatchingBrowser); ``
109115
110116#### Manual way:
111- new DriverManager().SetUpDriver(
112- "https://chromedriver.storage.googleapis.com/2.25/chromedriver_win32.zip",
113- Path.Combine(Directory.GetCurrentDirectory(), "chromedriver.exe"),
114- "chromedriver.exe"
115- );
117+ ``` csharp
118+ new DriverManager ().SetUpDriver (
119+ " https://chromedriver.storage.googleapis.com/2.25/chromedriver_win32.zip" ,
120+ Path .Combine (Directory .GetCurrentDirectory (), " chromedriver.exe" ),
121+ " chromedriver.exe"
122+ );
123+ ```
116124
117125### If you want use your own implementation you need to create driver config and use it for set up(ex get, setup and work with phantomjs driver from taobao mirror):
118- public class TaobaoPhantomConfig : IDriverConfig
126+ ``` csharp
127+ public class TaobaoPhantomConfig : IDriverConfig
128+ {
129+ public string GetName ()
119130 {
120- public string GetName()
121- {
122- return "TaobaoPhantom";
123- }
131+ return " TaobaoPhantom" ;
132+ }
124133
125- public string GetUrl32()
126- {
127- return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip";
128- }
134+ public string GetUrl32 ()
135+ {
136+ return " https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip" ;
137+ }
129138
130- public string GetUrl64()
131- {
132- return GetUrl32();
133- }
139+ public string GetUrl64 ()
140+ {
141+ return GetUrl32 ();
142+ }
134143
135- public string GetBinaryName()
136- {
137- return "phantomjs.exe";
138- }
144+ public string GetBinaryName ()
145+ {
146+ return " phantomjs.exe" ;
147+ }
139148
140- public string GetLatestVersion()
149+ public string GetLatestVersion ()
150+ {
151+ using (var client = new WebClient ())
141152 {
142- using (var client = new WebClient())
143- {
144- var doc = new HtmlDocument();
145- var htmlCode = client.DownloadString("https://bitbucket.org/ariya/phantomjs/downloads");
146- doc.LoadHtml(htmlCode);
147- var itemList =
148- doc.DocumentNode.SelectNodes("//tr[@class='iterable-item']/td[@class='name']/a")
149- .Select(p => p.InnerText)
150- .ToList();
151- var version = itemList.FirstOrDefault()?.Split('-')[1];
152- return version;
153- }
153+ var doc = new HtmlDocument ();
154+ var htmlCode = client .DownloadString (" https://bitbucket.org/ariya/phantomjs/downloads" );
155+ doc .LoadHtml (htmlCode );
156+ var itemList =
157+ doc .DocumentNode .SelectNodes (" //tr[@class='iterable-item']/td[@class='name']/a" )
158+ .Select (p => p .InnerText )
159+ .ToList ();
160+ var version = itemList .FirstOrDefault ()? .Split ('-' )[1 ];
161+ return version ;
154162 }
155163 }
164+ }
156165
157- ...
166+ .. .
158167
159- new DriverManager().SetUpDriver(new TaobaoPhantomConfig());
168+ new DriverManager ().SetUpDriver (new TaobaoPhantomConfig ());
169+ ```
160170
161171### Also you can implement your own services for download binaries and manage variables:
162- public class CustomBinaryService : IBinaryService
172+ ``` csharp
173+ public class CustomBinaryService : IBinaryService
174+ {
175+ public string SetupBinary (string url , string zipDestination , string binDestination , string binaryName )
163176 {
164- public string SetupBinary(string url, string zipDestination, string binDestination, string binaryName)
165- {
166- ...
167- // your implementation
168- ...
169- }
177+ .. .
178+ // your implementation
179+ .. .
170180 }
171-
172- public class CustomVariableService : IVariableService
181+ }
182+
183+ public class CustomVariableService : IVariableService
184+ {
185+ public void SetupVariable (string path )
173186 {
174- public void SetupVariable(string path)
175- {
176- ...
177- // your implementation
178- ...
179- }
187+ .. .
188+ // your implementation
189+ .. .
180190 }
181-
182- ...
191+ }
192+
193+ .. .
183194
184- new DriverManager(new CustomBinaryService(), new CustomVariableService()).SetUpDriver(new FirefoxConfig());
195+ new DriverManager (new CustomBinaryService (), new CustomVariableService ()).SetUpDriver (new FirefoxConfig ());
196+ ```
185197
186198### Or you can modify existed drivers and change only necessary fields(same example):
187- public class TaobaoPhantomConfig : PhantomConfig
199+ ``` csharp
200+ public class TaobaoPhantomConfig : PhantomConfig
201+ {
202+ public override string GetName ()
188203 {
189- public override string GetName()
190- {
191- return "TaobaoPhantom";
192- }
193-
194- public override string GetUrl32()
195- {
196- return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip";
197- }
204+ return " TaobaoPhantom" ;
198205 }
199206
200- ...
207+ public override string GetUrl32 ()
208+ {
209+ return " https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip" ;
210+ }
211+ }
201212
202- new DriverManager().SetUpDriver(new TaobaoPhantomConfig());
213+ .. .
203214
215+ new DriverManager ().SetUpDriver (new TaobaoPhantomConfig ());
216+ ```
204217
205218### Using with proxy:
206- new DriverManager().WithProxy(previouslyInitializedProxy).SetUpDriver(new ChromeConfig());
219+ ``` csharp
220+ new DriverManager ().WithProxy (previouslyInitializedProxy ).SetUpDriver (new ChromeConfig ());
221+ ```
207222
208223## Thanks
209224Thanks to the following companies for generously providing their services/products to help improve this project:
0 commit comments