When I am writing this piece of code it works fine
using System;
using WatiN.Core;
using MbUnit.Framework;
using Gallio.Framework;
using System.Text.RegularExpressions;
using System.Collections;
using System.IO;
using System.Drawing;
using Gallio.Model;
namespace DialogHandlerTestWithWatin
{
[TestFixture]
class Program
{
//This is WatiN - create IE instance
public static IE ie = new IE();
[SetUp]
public void DoTestSetup()
{
IE.Settings.WaitForCompleteTimeOut = 60;
}
[TearDown]
public static void TestNavigateToMedappz()
{
if (ie != null)
{
if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
{
Assert.Fail("Unable to navigate to the medappz application");
ie.Close();
ie.Dispose();
ie = null;
}
}
}
//This funcn navigate us to the Medappz Application
[Test]
public static void NavigateToMedappz()
{
using (TestLog.BeginSection("Go to Medappz"))
{
Assert.IsNotNull(ie);
ie.GoTo("http://192.168.10.82/Sage/");
ie.ShowWindow(NativeMethods.WindowShowStyle.Maximize);
}
//This is NUnit - check that ie instance is not null
Assert.IsNotNull(ie, "Error creating IE instance.");
Assert.AreEqual("Login Page", ie.Title);
}
But when I add another test method in this code as
[TearDown]
public static void TestLoginToMedappz()
{
if (ie != null)
{
if (TestContext.CurrentContext.Outcome == TestOutcome.Failed)
{
Assert.Fail("Unable to Login");
}
}
}
[Test]
public static void LoginToMedappz()
{
using (TestLog.BeginSection("Login to Medappz"))
{
TextField UserName = ie.TextField(Find.ByName("txtUserName"));
UserName.TypeText("<username>");
TextField Password = ie.TextField(Find.ByName("txtPassword"));
Assert.IsTrue(UserName.Exists, "UserName Textbox does not exist");
Assert.IsTrue(Password.Exists, "Password Textbox does not exist");
Password.TypeText("<password>");
Button btnLogin = ie.Button(Find.ByName("btnLogin"));
Assert.IsTrue(btnLogin.Exists, "btnLogin button does not exist");
btnLogin.Blur();
btnLogin.Click();
}
}
Then the test started failing, only a blank IE window opens up and after few seconds the first test method is executed but the second method doesn’t gets executed.The Gallio test report says
Root
110
Results: 2 run, 1 passed, 1 failed, 0 inconclusive, 0 skipped
Duration: 44.042s
Assertions: 3
WatiN.Core.Exceptions.ElementNotFoundException: Could not find INPUT (text password textarea hidden) or TEXTAREA element tag matching criteria: Attribute ‘name’ with value ‘txtUserName’
Are the two tests in the same class? I’ve never seen two teardowns in the same class. Also, if TestNavigateToMedappz is called before LoginToMedappz then your ie variable will have already been disposed. How about you have just one teardown, then at the start of LoginToMedappz you call NavigateToMedappz?