- Add Selenium NuGet packages
- Exchange project references
- Generic test classes
- Fixed compatibility caveats
While for IIE, the COM references to Interop.MSHTML
and
Interop.SHDocVw
were only required in the library itself, some NuGet
packages must be added to the web/test projects, too (similar to NUnit itself).
The ISelenium library only references the generic Selenium.WebDriver
to
communicate with the browser. Therefore, the concrete WebDriver NuGet package
is required for the web project, either
Selenium.InternetExplorer.WebDriver
(32 bit),
Selenium.Firefox.WebDriver
or Selenium.Chrome.WebDriver
.
The case for Edge is different, as the WebDriver is integrated into the win10 operating system as an official Windows Feature on Demand. Go to Apps in the win10 Settings, click on Optional Features and Add Feature, then look for the "Microsoft WebDriver" and install it.
Additionally, Developer Mode must be enabled. Go to Settings > Update and Security > For Developer and then select "Developer mode".
Even more, in Edge itself, access to localhost must be enabled. Type
about:flags
in the URL bar and enable the "Localhost-Loopback".
However, this will not enable the now blocked http://127.0.0.1 (to ptotect local
webservices from malicious CORS requests from a remote web site, see e.g.
Hacker News - I can see your local web
servers) or Hacker News - Why
Is This Website Port Scanning
Me?. No http://127.0.0.1 no
more is the main reason why IIE with direct COM communication is now abandoned,
although it was by far the fastest test driver. No more tweak the
solution because "localhost" seems to
never reach OnDocumentComplete
(in iie.IEExtension
). Its inability
to communicate with SPA pages like the minimal.websharper.spa was another big
reason.
Unlike for .NET Core, the NUnit test project for ASP.NET Framework also
requires the generic Selenium.WebDriver
to be installed in the project
itself, the indirect reference via iselenium.webforms
is not enough.
Delete the iie.webforms
resp. iie.core
and the parent iie
project references and replace them with iselenium.webforms
resp.
iselenium.core
in both the web project and its corresponding NUnit test
project. For .NET core, the parent iselenium
reference is only needed in
the web project itself.
After the iie
references have been removed, Visual Studio will
automatically complain - it should suffice to replace
using iie;
with
using iselenium;
in all test sources and, in case of .NET Core, in the Controller class for the page containing the NUnit button to start the test.
For ASP.NET Framework, the Register Assembly
directive in the .ascx file
containing the NUnit button must be adjusted as well. Replace
<%@ Register Assembly="iie.webforms" Namespace="iie" TagPrefix="iie" %>
with
<%@ Register Assembly="iselenium.webforms" Namespace="iselenium" TagPrefix="iie" %>
The TagPrefix="iie"
can remain as is.
If you don’t want to use the obsolete non-generic IETest
base classes for
Internet Explorer, the concrete browser to perform tests with needs to be
declared in the TestFixture. Multiple declarations are allowed, which will
execute all tests with each of the given browsers:
[TestFixture(typeof(EdgeDriver))]
[TestFixture(typeof(ChromeDriver))]
[TestFixture(typeof(FirefoxDriver))]
[TestFixture(typeof(InternetExplorerDriver))]
Make sure to add the corresponding NuGet packages for the browser-specific WebDriver.
getElementsByName
The getElementsByName()
method in an IHTMLDocument3
instance from
Interop.MSHTML
implicitly returns an HTMLElement with that id instead of
the given name if the latter is not founc. This behavior has been replicated in
SeleniumExtensionBase.GetHTMLElementByName() (which by itself ignores the id) to
retain compatibility.
Line Breaks
Line breaks in a MSHTML.IHTMLDocument2.body.outerHTML
are only LF (\n),
while line breaks returned by Seleniums GetAttribute("outerHTML")
are
Windows-style CR LF (\r\n). To retain compatiblity with hackish test assertions
like Assert.That(this.Html(), Does.Contain(" 5\n")
, this has been
mitigated by returning only LF (\n), too.