Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a problem with running IE on a retina screen #194

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ class ProcessLifecycleTests
public void Closing_SelenoHost_should_close_child_browser(string driverName)
{
Process.GetProcessesByName(driverName).ForEach(StopProcess);
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);

selenoHost.Dispose();
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();
}
Expand Down
12 changes: 7 additions & 5 deletions src/TestStack.Seleno/Configuration/BrowserFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static ChromeDriver Chrome(ChromeOptions options)
public static FirefoxDriver FireFox()
{
return new WebDriverBuilder<FirefoxDriver>(() => new FirefoxDriver())
.WithProcessName("firefox");
.WithProcessNames("firefox");
}

/// <summary>
Expand All @@ -83,7 +83,7 @@ public static FirefoxDriver FireFox()
public static FirefoxDriver FireFox(FirefoxProfile profile)
{
return new WebDriverBuilder<FirefoxDriver>(() => new FirefoxDriver(profile))
.WithProcessName("firefox");
.WithProcessNames("firefox");
}

/// <summary>
Expand Down Expand Up @@ -128,9 +128,10 @@ public static SafariDriver Safari(SafariOptions options)
/// <returns>Initialised IE driver</returns>
public static InternetExplorerDriver InternetExplorer()
{
var options = new InternetExplorerOptions { IntroduceInstabilityByIgnoringProtectedModeSettings = true };
var options = new InternetExplorerOptions { IntroduceInstabilityByIgnoringProtectedModeSettings = true, IgnoreZoomLevel = true};
return new WebDriverBuilder<InternetExplorerDriver>(() => new InternetExplorerDriver(options))
.WithFileName("IEDriverServer.exe");
.WithFileName("IEDriverServer.exe")
.WithProcessNames("IEDriverServer", "iexplore");
}

/// <summary>
Expand All @@ -142,7 +143,8 @@ public static InternetExplorerDriver InternetExplorer()
public static InternetExplorerDriver InternetExplorer(InternetExplorerOptions options)
{
return new WebDriverBuilder<InternetExplorerDriver>(() => new InternetExplorerDriver(options))
.WithFileName("IEDriverServer.exe");
.WithFileName("IEDriverServer.exe")
.WithProcessNames("IEDriverServer", "iexplore");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably also need to do this for chrome, but for now just adding for IE since it was easy for me to test at the time

}

}
Expand Down
11 changes: 8 additions & 3 deletions src/TestStack.Seleno/Configuration/SelenoHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,17 @@ private void ThrowIfHostNotInitialised()

public void Dispose()
{
Application.Logger.Info("Starting SelenoHost Dispose");
if (Application != null)
Application.Logger.Info("Starting SelenoHost Dispose");

// removing unload handler as it's being handled here
AppDomain.CurrentDomain.DomainUnload -= CurrentDomainDomainUnload;
Application.Dispose();
Application.Logger.Info("SelenoHost Disposed");

if (Application != null)
{
Application.Dispose();
Application.Logger.Info("SelenoHost Disposed");
}
}
}
}
42 changes: 24 additions & 18 deletions src/TestStack.Seleno/Configuration/WebDriverBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection.Emit;
using Holf.AllForOne;
using OpenQA.Selenium;

Expand All @@ -12,7 +12,7 @@ namespace TestStack.Seleno.Configuration
internal class WebDriverBuilder<T> where T : IWebDriver
{
private readonly Func<IWebDriver> _factory;
private string _processName;
private string[] _processNames;
private string _fileName;

public WebDriverBuilder(Func<IWebDriver> factory)
Expand All @@ -26,9 +26,9 @@ public WebDriverBuilder<T> WithFileName(string fileName)
return this;
}

public WebDriverBuilder<T> WithProcessName(string processName)
public WebDriverBuilder<T> WithProcessNames(params string[] processNames)
{
_processName = processName;
_processNames = processNames;
return this;
}

Expand All @@ -55,7 +55,7 @@ private static void EnsureFileExists(string resourceFileName)
// Find any assembly with the desired executable embedded in it
// http://bloggingabout.net/blogs/vagif/archive/2010/07/02/net-4-0-and-notsupportedexception-complaining-about-dynamic-assemblies.aspx
var assembly = AppDomain.CurrentDomain.GetAssemblies()
.Where(a => !(a is System.Reflection.Emit.AssemblyBuilder))
.Where(a => !(a is AssemblyBuilder))
.Where(a => a.GetType().FullName != "System.Reflection.Emit.InternalAssemblyBuilder")
.Where(a => !a.GlobalAssemblyCache)
.FirstOrDefault(a => a
Expand All @@ -79,22 +79,28 @@ private static void EnsureFileExists(string resourceFileName)

private T CreateWebDriver()
{
var processName = _processName ?? _fileName.Replace(@".exe", "");
var processNames = _processNames ?? new [] {_fileName.Replace(@".exe", "")};

IEnumerable<int> pidsBefore = Process
.GetProcessesByName(processName)
.Select(p => p.Id);
var pidsBefore = processNames
.SelectMany(Process.GetProcessesByName)
.Select(p => p.Id)
.ToArray();

var driver = _factory();

IEnumerable<int> pidsAfter = Process
.GetProcessesByName(processName)
.Select(p => p.Id);

IEnumerable<int> newPids = pidsAfter.Except(pidsBefore);
foreach (int pid in newPids)
IWebDriver driver;
try
{
driver = _factory();
}
finally
{
Process.GetProcessById(pid).TieLifecycleToParentProcess();
var pidsAfter = processNames
.SelectMany(Process.GetProcessesByName)
.Select(p => p.Id)
.ToArray();

var newPids = pidsAfter.Except(pidsBefore);
foreach (var pid in newPids)
Process.GetProcessById(pid).TieLifecycleToParentProcess();
}

return (T)driver;
Expand Down