Saturday, October 20, 2012

I wrote a WatiN test for the first time in a forever today.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WatiN.Core;
using WebApplication.Infrastructure;
namespace WebApplication.Tests
{
   [TestClass]
   public class FullSystemTest
   {
      [TestMethod]
      public void may_convert_a_single_digit_to_German_or_to_French()
      {
         using (var browser = new IE("http://localhost:65535/"))
         {
            TimeKeeping timeKeeping = new TimeKeeping();
            DateTime startOfTest = timeKeeping.GiveTime();
            while (startOfTest.AddSeconds(3) > timeKeeping.GiveTime()) { }
//wait 3 sec
            
            browser.TextField(Find.ByName("TextBox1")).TypeText("7");
            while (startOfTest.AddSeconds(6) > timeKeeping.GiveTime()) { }
//wait 3 sec
            
            browser.Button(Find.ByName("Button1")).Click();
            while (startOfTest.AddSeconds(9) > timeKeeping.GiveTime()) { }
//wait 3 sec
            
            var german = browser.Div(Find.ById("germanout")).Text.Trim();
            Assert.AreEqual(german, "sieben");
            while (startOfTest.AddSeconds(12) > timeKeeping.GiveTime()) { }
//wait 3 sec
            
            browser.TextField(Find.ById("forfrench")).TypeText("7");
            while (startOfTest.AddSeconds(15) > timeKeeping.GiveTime()) { }
//wait 3 sec
            
            browser.Div(Find.ById("frenchbutton")).Elements[0].Click();
            while (startOfTest.AddSeconds(18) > timeKeeping.GiveTime()) { }
//wait 3 sec
            
            var french = browser.Div(Find.ById("frenchout")).Text.Trim();
            Assert.AreEqual(french, "sept");
            while (startOfTest.AddSeconds(21) > timeKeeping.GiveTime()) { }
//wait 3 sec
         }
      }
   }
}

 
 

DateTime.Now is being abstracted away like so:

using System;
namespace WebApplication.Infrastructure
{
   public class TimeKeeping
   {
      public TimeKeeping()
      {
      }
      
      public DateTime GiveTime()
      {
         return DateTime.UtcNow;
      }
   }
}

No comments:

Post a Comment