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?
If you are trying to use WatiN
for web application testing through Internet Explorer, ensure to complete the right configurations first.
NUnit
doesn't run tests in a thread using the STA apartment state
; it uses multithreaded apartment (MTA)
, but this isn't a big problem, you can attach config file to the NUnit
test project and specify the apartment state mode that you want this way:
<?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>
Article Reference:
WatiN, Internet Explorer and Thread.Apartmentstate
This article explains the why and how about setting the ApartmentState of a Thread to single treaded apartment (STA). This is required when running your test with Internet Explorer. It also shows you how to do this when using WatiN with NUnit, MBUnit, MSTest, TestDriven.Net, Fitnesse or SharpDevelop.