【问题标题】:can not use watin不能用 watin
【发布时间】:2012-11-02 03:28:29
【问题描述】:

我运行一个非常简单的 watin 控制台应用程序,如下所示

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();
        }
    }
}

这不起作用。弹出窗口说缺少.exe 文件。我无法理解,因为它只是一个控制台应用程序。为什么我需要.exe 文件?

【问题讨论】:

  • "visual studio 无法开始调试,因为缺少调试目标 D:\....\consoleapplication1.exe。请构建项目并重试或将输出路径和 AssemblyName 属性设置为适当指向在目标程序集的正确位置"
  • 非常感谢,在我将目标 .net 框架从 4.0 更改为 3.5 后它可以工作。真是奇迹

标签: c# watin missing-features


【解决方案1】:

如果您尝试通过 Internet Explorer 使用 WatiN 进行 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 and Thread.Apartmentstate

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

【讨论】:

猜你喜欢
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-26
相关资源
最近更新 更多