Skip to content

Commit 6f6760d

Browse files
committed
Add more tests. Extend readme
1 parent 7699a35 commit 6f6760d

File tree

7 files changed

+152
-29
lines changed

7 files changed

+152
-29
lines changed

IntegrationTests/BrowserTests/BrowserTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ protected void BrowserTest(IDriverConfig driverConfig, DriverType driverType)
4141
{
4242
new DriverManager().SetUpDriver(driverConfig);
4343
_webDriver = new DriverCreator().Create(driverType);
44-
_webDriver.Navigate().GoToUrl("https://www.google.com/ncr");
45-
Assert.True(_webDriver.Title.Contains("Google"));
44+
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
45+
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
46+
Assert.Equal("Wikipedia", _webDriver.Title);
4647
}
4748

4849
public void Dispose()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using IntegrationTests.BrowserTests;
3+
using OpenQA.Selenium;
4+
using WebDriverManager;
5+
using Xunit;
6+
7+
namespace IntegrationTests.DriverManagerTests
8+
{
9+
public class CustomConfigTests: IDisposable
10+
{
11+
private IWebDriver _webDriver;
12+
13+
[Fact]
14+
protected void CustomConfigTest()
15+
{
16+
new DriverManager().SetUpDriver(new TaobaoChromeConfig());
17+
_webDriver = new DriverCreator().Create(DriverType.Chrome);
18+
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
19+
Assert.Equal("Wikipedia", _webDriver.Title);
20+
}
21+
22+
public void Dispose()
23+
{
24+
_webDriver.Quit();
25+
}
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
using IntegrationTests.BrowserTests;
3+
using OpenQA.Selenium;
4+
using WebDriverManager;
5+
using WebDriverManager.DriverConfigs.Impl;
6+
using WebDriverManager.Services.Impl;
7+
using Xunit;
8+
9+
namespace IntegrationTests.DriverManagerTests
10+
{
11+
public class CustomServiceTests: IDisposable
12+
{
13+
private IWebDriver _webDriver;
14+
private readonly BinaryService _customBinaryService;
15+
private readonly VariableService _customVariableService;
16+
17+
public CustomServiceTests()
18+
{
19+
_customBinaryService = new BinaryService();
20+
_customVariableService = new VariableService();
21+
}
22+
23+
[Fact]
24+
protected void CustomServiceTest()
25+
{
26+
new DriverManager(_customBinaryService, _customVariableService).SetUpDriver(new FirefoxConfig());
27+
_webDriver = new DriverCreator().Create(DriverType.Firefox);
28+
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
29+
Assert.Equal("Wikipedia", _webDriver.Title);
30+
}
31+
32+
public void Dispose()
33+
{
34+
_webDriver.Quit();
35+
}
36+
}
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.IO;
3+
using IntegrationTests.BrowserTests;
4+
using OpenQA.Selenium;
5+
using WebDriverManager;
6+
using Xunit;
7+
8+
namespace IntegrationTests.DriverManagerTests
9+
{
10+
public class ManualSetupTests : IDisposable
11+
{
12+
private IWebDriver _webDriver;
13+
private readonly string _url;
14+
private readonly string _binaryOutput;
15+
private readonly string _driverName;
16+
17+
public ManualSetupTests()
18+
{
19+
_url = "https://chromedriver.storage.googleapis.com/2.25/chromedriver_win32.zip";
20+
_binaryOutput = Path.Combine(Directory.GetCurrentDirectory(), "Chrome", "2.25", "X32", "chromedriver.exe");
21+
_driverName = "chromedriver.exe";
22+
}
23+
24+
[Fact]
25+
protected void ManualSetupTest()
26+
{
27+
new DriverManager().SetUpDriver(_url, _binaryOutput, _driverName);
28+
_webDriver = new DriverCreator().Create(DriverType.Chrome);
29+
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
30+
Assert.Equal("Wikipedia", _webDriver.Title);
31+
}
32+
33+
public void Dispose()
34+
{
35+
_webDriver.Quit();
36+
}
37+
}
38+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using WebDriverManager.DriverConfigs.Impl;
2+
3+
namespace IntegrationTests.DriverManagerTests
4+
{
5+
public class TaobaoChromeConfig : ChromeConfig
6+
{
7+
public new string GetName()
8+
{
9+
return "TaobaoChrome";
10+
}
11+
12+
public new string GetUrl32()
13+
{
14+
return "https://npm.taobao.org/mirrors/chromedriver/<version>/chromedriver_win32.zip";
15+
}
16+
}
17+
}

IntegrationTests/IntegrationTests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
<Compile Include="BrowserTests\BrowserTests.cs" />
6060
<Compile Include="BrowserTests\DriverCreator.cs" />
6161
<Compile Include="BrowserTests\DriverType.cs" />
62+
<Compile Include="DriverManagerTests\CustomConfigTests.cs" />
63+
<Compile Include="DriverManagerTests\ManualSetupTests.cs" />
64+
<Compile Include="DriverManagerTests\CustomServiceTests.cs" />
65+
<Compile Include="DriverManagerTests\TaobaoChromeConfig.cs" />
6266
<Compile Include="Properties\AssemblyInfo.cs" />
6367
<Compile Include="VariableServiceTests.cs" />
6468
<Compile Include="VersionTests.cs" />

README.md

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -106,55 +106,54 @@ Or version and architecture:
106106
#### Manual way:
107107
new DriverManager().SetUpDriver(
108108
"https://chromedriver.storage.googleapis.com/2.25/chromedriver_win32.zip",
109-
Directory.GetCurrentDirectory(),
109+
Path.Combine(Directory.GetCurrentDirectory(), "chromedriver.exe"),
110110
"chromedriver.exe"
111111
);
112112

113113
### 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):
114-
public class TaobaoPhantomConfig : IDriverConfig
114+
public class CustomBinaryService : IBinaryService
115115
{
116-
public string GetName()
116+
public string SetupBinary(string url, string zipDestination, string binDestination, string binaryName)
117117
{
118-
return "TaobaoPhantom";
118+
...
119+
// your implementation
120+
...
119121
}
120-
121-
public string GetUrl32()
122+
}
123+
124+
public class CustomVariableService : IVariableService
125+
{
126+
public void SetupVariable(string path)
122127
{
123-
return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip";
128+
...
129+
// your implementation
130+
...
124131
}
132+
}
133+
134+
...
125135

126-
public string GetUrl64()
127-
{
128-
return GetUrl32();
129-
}
136+
new DriverManager(new CustomBinaryService(), new CustomVariableService()).SetUpDriver(new FirefoxConfig());
130137

131-
public string GetBinaryName()
138+
### Or you can modify existed drivers and change only necessary fields(same example):
139+
public class TaobaoPhantomConfig : PhantomConfig
140+
{
141+
public string GetName()
132142
{
133-
return "phantomjs.exe";
143+
return "TaobaoPhantom";
134144
}
135145

136-
public string GetLatestVersion()
146+
public string GetUrl32()
137147
{
138-
using (var client = new WebClient())
139-
{
140-
var doc = new HtmlDocument();
141-
var htmlCode = client.DownloadString("https://bitbucket.org/ariya/phantomjs/downloads");
142-
doc.LoadHtml(htmlCode);
143-
var itemList =
144-
doc.DocumentNode.SelectNodes("//tr[@class='iterable-item']/td[@class='name']/a")
145-
.Select(p => p.InnerText)
146-
.ToList();
147-
var version = itemList.FirstOrDefault()?.Split('-')[1];
148-
return version;
149-
}
148+
return "https://npm.taobao.org/mirrors/phantomjs/phantomjs-<version>-windows.zip";
150149
}
151150
}
152151

153152
...
154153

155154
new DriverManager().SetUpDriver(new TaobaoPhantomConfig());
156155

157-
### Or you can modify existed drivers and change only necessary fields(same example):
156+
### Also you can implement your own services for download binaries and manage variables:
158157
public class TaobaoPhantomConfig : PhantomConfig
159158
{
160159
public string GetName()

0 commit comments

Comments
 (0)