Skip to content

Commit 66f6b7f

Browse files
committed
Test improve
1 parent 17fcf44 commit 66f6b7f

File tree

7 files changed

+88
-15
lines changed

7 files changed

+88
-15
lines changed

IntegrationTests/BrowserTests/BrowserTests.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public class BrowserData : IEnumerable<object[]>
1313
{
1414
private readonly List<object[]> _data = new List<object[]>
1515
{
16-
new object[] {new ChromeConfig(), DriverType.Chrome},
17-
// new object[] {new EdgeConfig(), DriverType.Edge},
18-
new object[] {new FirefoxConfig(), DriverType.Firefox},
19-
new object[] {new InternetExplorerConfig(), DriverType.InternetExplorer},
20-
// new object[] {new OperaConfig(), DriverType.Opera},
21-
new object[] {new PhantomConfig(), DriverType.Phantom}
16+
new object[] {new ChromeConfig(), DriverType.Chrome, "chromedriver"},
17+
// new object[] {new EdgeConfig(), DriverType.Edge, "MicrosoftWebDriver"},
18+
new object[] {new FirefoxConfig(), DriverType.Firefox, "geckodriver"},
19+
new object[] {new InternetExplorerConfig(), DriverType.InternetExplorer, "IEDriverServer"},
20+
// new object[] {new OperaConfig(), DriverType.Opera, "operadriver"},
21+
new object[] {new PhantomConfig(), DriverType.Phantom, "phantomjs"}
2222
};
2323

2424
public IEnumerator<object[]> GetEnumerator()
@@ -35,20 +35,39 @@ IEnumerator IEnumerable.GetEnumerator()
3535
public class BrowserTests : IDisposable
3636
{
3737
private IWebDriver _webDriver;
38+
private string _driverExe;
3839

3940
[Theory, ClassData(typeof(BrowserData)), Trait("Category", "Browser")]
40-
protected void BrowserTest(IDriverConfig driverConfig, DriverType driverType)
41+
protected void BrowserTest(IDriverConfig driverConfig, DriverType driverType, string driverExe)
4142
{
42-
new DriverManager().SetUpDriver(driverConfig);
43+
_driverExe = driverExe;
44+
if (driverType == DriverType.Phantom)
45+
{
46+
new DriverManager().SetUpDriver(driverConfig, "2.1.1");
47+
}
48+
else
49+
{
50+
new DriverManager().SetUpDriver(driverConfig);
51+
}
4352
_webDriver = new DriverCreator().Create(driverType);
4453
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
45-
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
4654
Assert.Equal("Wikipedia", _webDriver.Title);
4755
}
4856

4957
public void Dispose()
5058
{
51-
_webDriver.Quit();
59+
try
60+
{
61+
_webDriver.Quit();
62+
}
63+
catch (Exception ex)
64+
{
65+
Console.WriteLine(ex.Message, ex);
66+
}
67+
finally
68+
{
69+
Helper.KillProcesses(_driverExe);
70+
}
5271
}
5372
}
5473
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Diagnostics;
2+
3+
namespace IntegrationTests.BrowserTests
4+
{
5+
public static class Helper
6+
{
7+
public static void KillProcesses(string driverExe)
8+
{
9+
var driverProcesses = Process.GetProcessesByName(driverExe);
10+
foreach (var driverProcess in driverProcesses)
11+
{
12+
driverProcess.Kill();
13+
}
14+
}
15+
}
16+
}

IntegrationTests/DriverManagerTests/CustomConfigTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ namespace IntegrationTests.DriverManagerTests
99
public class CustomConfigTests: IDisposable
1010
{
1111
private IWebDriver _webDriver;
12+
private string _driverExe;
1213

1314
[Fact, Trait("Category", "Browser")]
1415
protected void CustomConfigTest()
1516
{
17+
_driverExe = "chromedriver";
1618
new DriverManager().SetUpDriver(new TaobaoChromeConfig());
1719
_webDriver = new DriverCreator().Create(DriverType.Chrome);
1820
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
@@ -21,7 +23,18 @@ protected void CustomConfigTest()
2123

2224
public void Dispose()
2325
{
24-
_webDriver.Quit();
26+
try
27+
{
28+
_webDriver.Quit();
29+
}
30+
catch (Exception ex)
31+
{
32+
Console.WriteLine(ex.Message, ex);
33+
}
34+
finally
35+
{
36+
Helper.KillProcesses(_driverExe);
37+
}
2538
}
2639
}
2740
}

IntegrationTests/DriverManagerTests/CustomServiceTests.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class CustomServiceTests: IDisposable
1313
private IWebDriver _webDriver;
1414
private readonly BinaryService _customBinaryService;
1515
private readonly VariableService _customVariableService;
16+
private string _driverExe;
1617

1718
public CustomServiceTests()
1819
{
@@ -23,6 +24,7 @@ public CustomServiceTests()
2324
[Fact, Trait("Category", "Browser")]
2425
protected void CustomServiceTest()
2526
{
27+
_driverExe = "geckodriver";
2628
new DriverManager(_customBinaryService, _customVariableService).SetUpDriver(new FirefoxConfig());
2729
_webDriver = new DriverCreator().Create(DriverType.Firefox);
2830
_webDriver.Navigate().GoToUrl("https://www.wikipedia.org");
@@ -31,7 +33,18 @@ protected void CustomServiceTest()
3133

3234
public void Dispose()
3335
{
34-
_webDriver.Quit();
36+
try
37+
{
38+
_webDriver.Quit();
39+
}
40+
catch (Exception ex)
41+
{
42+
Console.WriteLine(ex.Message, ex);
43+
}
44+
finally
45+
{
46+
Helper.KillProcesses(_driverExe);
47+
}
3548
}
3649
}
3750
}

IntegrationTests/DriverManagerTests/ManualSetupTests.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public ManualSetupTests()
1818
{
1919
_url = "https://chromedriver.storage.googleapis.com/2.25/chromedriver_win32.zip";
2020
_binaryOutput = Path.Combine(Directory.GetCurrentDirectory(), "Chrome", "2.25", "X32", "chromedriver.exe");
21-
_driverName = "chromedriver.exe";
21+
_driverName = "chromedriver";
2222
}
2323

2424
[Fact, Trait("Category", "Browser")]
@@ -32,7 +32,18 @@ protected void ManualSetupTest()
3232

3333
public void Dispose()
3434
{
35-
_webDriver.Quit();
35+
try
36+
{
37+
_webDriver.Quit();
38+
}
39+
catch (Exception ex)
40+
{
41+
Console.WriteLine(ex.Message, ex);
42+
}
43+
finally
44+
{
45+
Helper.KillProcesses(_driverName);
46+
}
3647
}
3748
}
3849
}

IntegrationTests/IntegrationTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<Compile Include="BrowserTests\BrowserTests.cs" />
6060
<Compile Include="BrowserTests\DriverCreator.cs" />
6161
<Compile Include="BrowserTests\DriverType.cs" />
62+
<Compile Include="BrowserTests\Helper.cs" />
6263
<Compile Include="DriverManagerTests\CustomConfigTests.cs" />
6364
<Compile Include="DriverManagerTests\ManualSetupTests.cs" />
6465
<Compile Include="DriverManagerTests\CustomServiceTests.cs" />

WebDriverManager/DriverConfigs/Impl/InternetExplorerConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public class InternetExplorerConfig : IDriverConfig
1010
{
1111
public string GetName()
1212
{
13-
return "IE";
13+
return "InternetExplorer";
1414
}
1515

1616
public string GetUrl32()

0 commit comments

Comments
 (0)