1

I run a very simple watin console application like below

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;

namespace ConsoleApplication2
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            IE ie = new IE();

            // point it to http://www.google.com

            ie.GoTo("http://www.google.com");

            // fill the search box

            ie.TextField(Find.ByName("q")).TypeText("WatiN");

            // performs click event

            ie.Button(Find.ByValue("Google Search")).Click();
        }
    }
}

Which is not working. A pop up said that there's a missing .exe file. I can not understand because it's just a console application. Why do I need the .exe file?

4

1 回答 1

1

如果您尝试通过Internet ExplorerWatiN进行Web 应用程序测试,请确保首先完成正确的配置。

NUnit不使用STA apartment state;在线程中运行测试 它使用multithreaded apartment (MTA),但这不是一个大问题,您可以将配置文件附加到NUnit测试项目并指定您想要的公寓状态模式:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="NUnit">
            <section name="TestRunner" type="System.Configuration.NameValueSectionHandler"/>
        </sectionGroup>
    </configSections>
    <NUnit>
        <TestRunner>
            <!-- Valid values are STA, MTA. Others ignored. -->
            <add key="ApartmentState" value="STA" />
        </TestRunner>
    </NUnit>
</configuration>

文章参考:

WatiN、Internet Explorer 和 Thread.Apartmentstate

本文解释了将线程的 ApartmentState 设置为单线程单元 (STA) 的原因和方法。在使用 Internet Explorer 运行测试时,这是必需的。它还向您展示了在将 WatiN 与 NUnit、MBUnit、MSTest、TestDriven.Net、Fitnesse 或 SharpDevelop 一起使用时如何执行此操作。

于 2012-11-02T03:53:31.530 回答