-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathProcessLifecycleTests.cs
More file actions
81 lines (71 loc) · 2.67 KB
/
ProcessLifecycleTests.cs
File metadata and controls
81 lines (71 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Diagnostics;
using Castle.Core.Internal;
using FluentAssertions;
using NUnit.Framework;
using OpenQA.Selenium.Remote;
using TestStack.Seleno.Configuration;
namespace TestStack.Seleno.AcceptanceTests.Configuration
{
[TestFixture]
class ProcessLifecycleTests
{
private const string Chrome = "chromedriver";
private const string IE = "IEDriverServer";
private const string Phantom = "phantomjs";
private const string Firefox = "firefox";
private const string IisExpress = "iisexpress";
[TestCase(Chrome)]
[TestCase(IE)]
[TestCase(Phantom)]
[TestCase(Firefox)]
public void Closing_SelenoHost_should_close_child_browser(string driverName)
{
Process.GetProcessesByName(driverName).ForEach(StopProcess);
using (var selenoHost = new SelenoHost())
{
Func<RemoteWebDriver> driver = GetBrowserFactory(driverName);
selenoHost.Run("TestStack.Seleno.AcceptanceTests.Web", 12346,
c => c.WithRemoteWebDriver(driver));
Process.GetProcessesByName(driverName).Length.Should().Be(1);
}
Process.GetProcessesByName(driverName).Should().BeEmpty();
}
[Test]
public void Closing_SelenoHost_should_close_Iis_Express()
{
Process.GetProcessesByName(IisExpress).ForEach(StopProcess);
Process.GetProcessesByName("chromedriver").ForEach(StopProcess);
var selenoHost = new SelenoHost();
selenoHost.Run("TestStack.Seleno.AcceptanceTests.Web", 12346,
c => c.WithRemoteWebDriver(BrowserFactory.Chrome));
Process.GetProcessesByName(IisExpress).Length.Should().Be(1);
selenoHost.Dispose();
Process.GetProcessesByName("chromedriver").Should().BeEmpty();
Process.GetProcessesByName(IisExpress).Should().BeEmpty();
}
private void StopProcess(Process process)
{
if (process == null)
return;
if (!process.HasExited)
process.Kill();
process.Dispose();
}
private Func<RemoteWebDriver> GetBrowserFactory(string browser)
{
switch (browser)
{
case Chrome:
return BrowserFactory.Chrome;
case IE:
return BrowserFactory.InternetExplorer;
case Phantom:
return BrowserFactory.PhantomJS;
case Firefox:
return BrowserFactory.FireFox;
}
return null;
}
}
}