21

My problem is that I cannot get a simple WatiN test to reliably work on my development machine which is running Windows Server 2008 and IE8.

I have seen a couple of good posts on this, but am still having problems. Here are the posts:

The steps in the first article seemed to help (comment out "::1" in my hosts file, put my site(s) in trusted sites, and making sure my app.config has "STA" and is set to "copy if newer", but they did not help reliably. I tried the code from the second example hoping that it would help but it did not. I am using WatiN version 2.0 beta 1.

My NUnit code looks like the following:

protected Browser Browser { get; set; }

[TestFixtureSetUp]
public void SetupPriorToTestsInThisFixture()
{
    Browser = new IE();
    Browser.GoTo(Constants.SiteCollectionUrl);
}

[TestFixtureTearDown]
public void TearDownAfterTestsInThisFixture()
{
    if (Browser != null)
    {
        Browser.Dispose();
    }
}

[Test]
public void WaterThroughThePipes()
{
    Link link = Browser.Link(Find.ByText("Calendar"));
    bool exists = link.Exists;
    Assert.That(exists, Is.True, "Could not find 'Calendar' link.");
}

What I'm seeing is that sometimes (albeit rarely) my test passes. Sometimes the assertion fails (exists = false), sometimes I get a timeout when trying to open the browser, and sometimes I get an error trying to access link.Exists.

The error accessing link.Exists looks like:

MyFixture.WaterThroughThePipes: System.Runtime.InteropServices.COMException : The interface is unknown. (Exception from HRESULT: 0x800706B5)

I can't seem to reproduce the timeout error now so I can't provide that at the moment (although this used to happen all of the time).

I tend to see different results when running this in debug mode vs. not running in debug mode.

For what it's worth, Firefox 3.0.6 has never worked for me. I'd like it to, but need IE to work regardless. Here is the error I get with Firefox.

MyFixture (TestFixtureSetUp): WatiN.Core.Native.Mozilla.FireFoxException : Unable to connect to jssh server, please make sure you have correctly installed the jssh.xpi plugin ----> System.Net.Sockets.SocketException : No connection could be made because the target machine actively refused it 127.0.0.1:9997

Any ideas? I really don't want to go back to Selenium (been there, done that), but I may have to.

Community
  • 1
  • 1
Kirk Liemohn
  • 7,733
  • 9
  • 46
  • 57
  • Oh, I have also found different results if I exit NUnit and re-open it. I have also tried a couple of reboots during this process to see if it helped (it did not). – Kirk Liemohn Jun 18 '09 at 19:51
  • 2
    Can you try it with Internet Explorer 7? "Interface is unknown" suggests that maybe Watin doesn't support IE8 yet - it certainly wasn't written against it. Of cource this is just a (psychic debugging) guess. Firefox issue: have you installed the jssh extension? And you could try selenium too. – devdimi Jun 18 '09 at 19:59
  • Once you have IE8 installed I don't think you can go back to IE7 without installing a new OS. I'm sure there is a workaround, but it might be dicey... I may look into that. I hadn't tried the jssh extension for Firefox since Firefox was not my focus, but I will probably give that a shot - thanks for the suggestion. – Kirk Liemohn Jun 19 '09 at 12:49
  • I did install jssh for Firefox and that does work. It will be useful, but I still need to test with IE as well. Hopefully I can get a machine with IE7 available for testing because I'd prefer not to go back to Selenium if I can help it. – Kirk Liemohn Jun 22 '09 at 03:24

5 Answers5

29

Run Visual Studio as Administrator

Craig Lebowitz
  • 549
  • 4
  • 6
  • 1
    Bingo! I had an System.Runtime.InteropServices.COMException was unhandled by user code Message="The interface is unknown. (Exception from HRESULT: 0x800706B5)" error coming from mshtml.HTMLDocumentClass.IHTMLDocument2_get_url() and running Visual Studio as an Administrator fixed it! – Greg Bray Dec 03 '09 at 23:11
  • I was running into this problem when running Watin in an Xunit test through TestDriven.net and running VS as administrator fixed it. – Robin Clowers Dec 23 '09 at 17:14
  • Running Visual Studio as an Administrator fix the problem while debugging. But if I run my exe as a standard user it fails for the same reason. Is there any solution? – Ikaso Aug 20 '10 at 14:22
  • 6
    We have found out that if we change the Local Intranet zone settings to do not detect local intranet network automatically we can perform our testing without running as administrator. To do so on IE8 go to Tools->Internet Options->Security tab->Local Intranet. Press on the sites button and remove the check box from "Automatically detect intranet network" and that's it. – Ikaso Aug 22 '10 at 07:20
  • Hm. I found that it worked if I set the "Automatically detect intranet network" check box as checked; when it was un-checked I got the error. – dagilleland May 06 '11 at 13:58
21

I was able to get this COM error to go away -- and get my tests running normally -- by adjusting my Internet Security settings to "Enable Protected Mode" even for Local Intranet sites. This single checkbox made all the difference. (And I don't have to run Visual Studio as Administrator.)

See this blog post for fixing this problem without running Visual Studio as Administrator.

Briefly:

In Internet Explorer, open Tools -> Internet Options -> Security -> Local intranet and check the box "Enable Protected Mode."

I'm running IE 8 and Visual Studio 2010 on Windows 7.

David Crosby
  • 266
  • 2
  • 5
  • This worked perfectly and much nicer than having to run as an administrator as I have had to in the past. – Bronumski Jul 27 '11 at 10:42
  • Confirmed. Worked for me on win 2008 – lstanczyk Aug 02 '12 at 15:37
  • I'm testing on localhost, and security restrictions prevented me from changing the Protected Mode setting on the "Local intranet" zone. But I was able to set up DNS for a .com subdomain that resolved to 127.0.0.1 and the .com in the name was enough to make IE treat it as the "Internet" zone, which already had Protected Mode enabled. – CrazyPyro Dec 31 '13 at 22:13
1

IE8 definatley works with WatiN, and has done since the first public release of IE8.

If something is working in debug but not when running it usually points to a timing or Server 2008 security lockdown issue.

You should putting the line that is failing in a try catch, then if there is an exception pause for say half a sec and then re-try again.

Also ensure that you have turned off all the extra server security lockdowns, and are running nUnit as administrator to avoid UAC getting in the way.

Bruce McLeod
  • 1,362
  • 15
  • 21
0

Regarding the error you're seeing on firefox... That can be overcome by installing the FireWatir FF plugin. (Or at least that worked for me on 3.5.3)

But as already mentioned, IE is supported and in a WatiN context, using FireFox is no magic solution.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
0

The other alternative to avoid running Visual Studio or NUnit as an admin would be to disable UAC at a machine level, which shouldn't be a security issue if you are running with least privileges (which you should be).

Mike
  • 21
  • 1