This question is locked. New answers and comments are not allowed.
I'm doing a POC for using Test Studio integrated with WatiN. I've got most of the way there I'm running into issues where I'm trying to pass an exception back to the test studio. In order to use WatiN with Test Studio I need to for the browser into STA mode and in order to do that I need to setup a delegate. In side the delegate I'm having trouble taking the assert failure and passing it back to test studio. Do you have any suggestions?
public
class
WebTest1 : BaseWebAiiTest
{
#region [ Dynamic Pages Reference ]
private
Pages _pages;
/// <summary>
/// Gets the Pages object that has references
/// to all the elements, frames or regions
/// in this project.
/// </summary>
public
Pages Pages
{
get
{
if
(_pages ==
null
)
{
_pages =
new
Pages(Manager.Current);
}
return
_pages;
}
}
#endregion
[CodedStep(
"WatiN Test"
)]
public
void
WatiNTest()
{
ForceSTA(() =>
{
using
(var browser = WatiN.Core.Browser.AttachTo<IE>(WatiN.Core.Find.ByUrl(
"about:blank"
)))
{
browser.GoTo(
"http://www.google.com"
);
browser.TextField(WatiN.Core.Find.ByName(
"q"
)).TypeText(
"WatiN"
);
browser.Button(WatiN.Core.Find.ByName(
"btnG"
)).Click();
Assert.IsTrue(browser.ContainsText(
"WatiNg"
));
}
});
}
private
void
ForceSTA(Action action)
{
Thread staThread =
new
Thread(
new
ThreadStart(
delegate
{
try
{
action.Invoke();
}
catch
(Exception)
{
Log.WriteLine(
"Fail"
);
}
}));
staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();
staThread.Join();
}
}