-
Notifications
You must be signed in to change notification settings - Fork 476
Expand file tree
/
Copy pathFirefox.cs
More file actions
46 lines (40 loc) · 1.88 KB
/
Firefox.cs
File metadata and controls
46 lines (40 loc) · 1.88 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
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using TestStack.White.UIItems.WindowItems;
using TestStack.White.WebBrowser.Configuration;
namespace TestStack.White.WebBrowser
{
public class Firefox
{
public static FirefoxWindow Launch(string url)
{
const string executableName = "firefox";
const string executable = executableName + ".exe";
int numberBeforeLaunch = Process.GetProcessesByName(executableName).Length;
Application existingApplication = null;
List<Window> existingWindows = null;
if (numberBeforeLaunch != 0)
{
existingApplication = Application.Attach(executableName);
existingWindows = existingApplication.GetWindows();
}
string commandLine = string.Format("-new-window {0}", url);
var processStartInfo = new ProcessStartInfo {FileName = executable, Arguments = commandLine};
Application application = Application.Launch(processStartInfo);
Thread.Sleep(WebBrowserConfigurationLocator.Get().FirefoxSingleWindowCheckWait);
int numberOfFirefoxProcessesAfterLaunch = Process.GetProcessesByName(executableName).Length;
bool processPerWindow = numberOfFirefoxProcessesAfterLaunch > numberBeforeLaunch;
FirefoxFactory.Plugin();
if (processPerWindow)
{
List<Window> windows = application.GetWindows();
if (windows.Count == 0) throw new WhiteAssertionException("Could not find firefox window");
return (FirefoxWindow) windows[0];
}
List<Window> firefoxWindows = existingApplication.GetWindows();
firefoxWindows.RemoveAll(window => existingWindows.Contains(window));
return (FirefoxWindow) firefoxWindows[0];
}
}
}