The section of navigation code (see below) between the asterisks works
perfectly when I run it outside of NUnit.  I am able to navigate to
the proper screen without difficulty.

When I run the same code under NUnit, I eventually get to the proper
screen.  But by that time the following errors have occured:

Tests run: 2, Failures: 2, Skipped: 0, Ignored: 0
Failures:
1)
DecaturTestFixtures.Class1.Navigate.C_2_3_2_1_TEXT_My_Post_Office_128177_Test.Cleaup
 :
Timeout while 'Internet Explorer busy'
   at WatiN.Core.DomContainer.ThrowExceptionWhenTimeout(String
timeoutMessage)
   at WatiN.Core.DomContainer.waitWhileIEBusy(IWebBrowser2 ie)
   at WatiN.Core.IE.WaitForComplete()
   at WatiN.Core.Element.WaitForComplete()
   at WatiN.Core.Element.Click()
   at DecaturTestFixtures.Class1.Navigate() in E:\NUnit Testing
\TestNavigationSolution\DecaturTestFixtures\Class1.cs:line 61
2)
DecaturTestFixtures.Class1.Navigate.C_2_3_2_2_1_LINK_Change_Facility_127129_Test.Cleaup
 :
Could not find a 'A' tag containing attribute innertext with value
'Log On'
   at WatiN.Core.Element.getElement(Boolean
throwExceptionIfElementNotFound)
   at WatiN.Core.Element.get_HTMLElement()
   at WatiN.Core.Element.get_htmlElement3()
   at WatiN.Core.Element.get_Enabled()
   at WatiN.Core.Element.Click()
   at DecaturTestFixtures.Class1.Navigate() in E:\NUnit Testing
\TestNavigationSolution\DecaturTestFixtures\Class1.cs:line 53


Any help would be appreciated.

Thanks,

Ben

using System;

using System.Collections.Generic;

using System.Text;



using WatiN.Core.DialogHandlers;

using WatiN.Core.Exceptions;

using WatiN.Core.Interfaces;

using WatiN.Core.Logging;

using WatiN.Core;



using System.Runtime.InteropServices;

using System.Threading;

using System.Diagnostics;

using System.Configuration;

using System.IO;

using System.Timers;



//using NUnit.Framework;

using MbUnit.Framework;



using DecaturTests;



namespace DecaturTestFixtures

{

    //[TestFixture]

    [TestFixture (ApartmentState = ApartmentState.STA)]



    public class Class1

    {

        List<string> testList;



        string testName;



        public string stringOut;

        public StringBuilder builderOut;



        IE ie;



        [SetUp]

        public void Navigate()

        {

            testList = new List<string>();





//
*************************************************************************************************



            //IE("C:/Documents and Settings/All Users/Documents/My PO/
United States Postal Service                      //Intranet - My
Work.htm");



            ie = new IE("http://eagnmntwe200.usps.gov/wps/portal";);



            ie.Link(Find.ByText("Log On")).Click();



            //Decatur

            ie.TextField(Find.ByName("userid")).TypeText("x0w3b0");

            ie.TextField(Find.ByName("password")).TypeText("Postal2");



            ie.DialogWatcher.CloseUnhandledDialogs = false;



            ie.Button(Find.ByValue("Log On")).Click();



            StartAutomator();



            ie.Link(Find.ByText(" My Work  ")).Click();





//
*************************************************************************************************





        }



        [Test]

        public void C_2_3_2_1_TEXT_My_Post_Office_128177_Test()

        {

            //System.Timers.Timer aTimer = new System.Timers.Timer();

            //aTimer.Elapsed += new
ElapsedEventHandler(OnTimedEvent);

            // Set the Interval to 5 seconds.

            //aTimer.Interval=5000;

            //aTimer.Interval=60000;

            //aTimer.Enabled=true;



            testName = "\nC_2_3_2_1_TEXT_My_Post_Office_128177";

            AddTestName(testList, testName);



            DecaturTest test = new DecaturTest();



 
Assert.IsTrue(test.C_2_3_2_1_TEXT_My_Post_Office_128177(ie));

            //
Assert.IsFalse(test.C_2_3_2_1_TEXT_My_Post_Office_128177(ie));



            ie.Close();

        }



        [Test]

        public void C_2_3_2_2_1_LINK_Change_Facility_127129_Test()

        {

            testName = "\nC_2_3_2_2_1_LINK_Change_Facility_127129";

            AddTestName(testList, testName);



            DecaturTest test = new DecaturTest();



 
Assert.IsNotNull(test.C_2_3_2_2_1_LINK_Change_Facility_127129(ie),

                 "NOT FOUND ->
C_2_3_2_2_1_LINK_Change_Facility_127129");



            //
Assert.IsNull(test.C_2_3_2_2_1_LINK_Change_Facility_127129(ie),

            //    "\n\nNOT FOUND ->
C_2_3_2_2_1_LINK_Change_Facility_127129\n");



            ie.Close();

        }



        [TearDown]

        public void Cleaup()

        {

            long dateString = DateTime.Today.ToFileTime();

            StreamWriter writer = new StreamWriter(@"E:\a Results
\tb_resultsTestSolution_"
+
dateString.ToString() + ".bak", true);



            foreach (string testName in testList)

            {

                writer.WriteLine(testName.ToString());

            }



            writer.Flush();



            writer.Close();



            ie.Close();

        }



        public static List<string> AddTestName(List<string> testList,
string testName)

        {

            testList.Add(testName);

            return testList;

        }

        private static void StartAutomator()

        {

            Thread t = new Thread(new
ThreadStart(RunCredentialAutomator));



            t.Start();

        }



        private static void RunCredentialAutomator()

        {

            WindowFinder main = new WindowFinder();

            WindowFinder company = new WindowFinder();

            WindowFinder userID = new WindowFinder();

            WindowFinder password = new WindowFinder();

            WindowFinder okButton = new WindowFinder();

            WindowFinder yesButton1 = new WindowFinder();

            WindowFinder yesButton2 = new WindowFinder();

            WindowFinder noButton = new WindowFinder();



            IntPtr invalidHandle = IntPtr.Zero;



            do

            {

                //main.Window = main.Find("#32770", "MAS 90 and MAS
200 Database Signon");

                main.Window = main.Find("#32770", "Security Alert");

            } while (main.Window == invalidHandle);



            //company.Window = company.Find(main.Window, "ComboBox",
"");

            //userID.Window = userID.Find(main.Window, company.Window,
"ComboBox", "");

            //password.Window = password.Find(main.Window,
userID.Window, "Edit", "");

            //okButton.Window = okButton.Find(main.Window,
password.Window, "Button", "&OK");



            yesButton1.Window = yesButton1.Find(main.Window,
password.Window, "Button", "&Yes");

            yesButton1.ClickButton();



            yesButton2.Window = yesButton2.Find(main.Window, "Button",
"&Yes");

            yesButton2.ClickButton();



            //company.SelectComboItem(_company);

            //userID.SelectComboItem(_user);

            //password.SetEditText(_password);

            //okButton.ClickButton();

        }



        public class WindowFinder

        {

            private IntPtr _window;

            private const int CB_ERR = -1;

            private const int SEARCH_ALL = -1;

            private const int CB_SELECTSTRING = 0x014D;

            private const int WM_SETTEXT = 0x000C;

            private const int BM_CLICK = 0x00F5;



            public WindowFinder()

            {

            }



            public IntPtr Find(string className, string windowText)

            {

                return FindWindow(className, windowText);

            }



            public IntPtr Find(IntPtr parent, IntPtr after, string
className, string windowText)

            {

                return FindWindowEx(parent, after, className,
windowText);

            }



            public IntPtr Find(IntPtr parent, string className, string
windowText)

            {

                IntPtr zero = new IntPtr(0);

                return FindWindowEx(parent, zero, className,
windowText);

            }



            public void UseWindow(IntPtr handle)

            {

                if (!IsWindowValid(handle))

                    throw new ArgumentException("Window handle does
not exist.", "handle");



                _window = handle;

            }



            public bool IsWindowValid(IntPtr handle)

            {

                return handle != IntPtr.Zero;

            }



            public IntPtr Window

            {

                get { return _window; }

                set { _window = value; }

            }



            public void SetText(string text)

            {

                SetText(this.Window, text);

            }



            public void SetText(IntPtr handle, string text)

            {

                SetWindowText(handle, text);

            }



            public void SetEditText(string text)

            {

                //IntPtr zero = new IntPtr(0);

                SendMessage(this.Window, WM_SETTEXT, 0, text);

            }



            public string GetText()

            {

                return GetText(this.Window);

            }



            public string GetText(IntPtr handle)

            {

                int length = GetWindowTextLength(handle);

                StringBuilder windowText = new StringBuilder(length +
1);

                GetWindowText(handle, windowText,
windowText.Capacity);

                return windowText.ToString();

            }



            public void SetFocus()

            {

                SetFocus(this.Window);

            }



            public void SelectComboItem(string val)

            {

                //IntPtr wParam = new IntPtr(SEARCH_ALL);

                SendMessage(this.Window, CB_SELECTSTRING, SEARCH_ALL,
val);

            }



            public void ClickButton()

            {

                SendMessage(this.Window, BM_CLICK, 0, 0);

            }



            [DllImport("user32.dll")]

            private static extern IntPtr FindWindow(string
lpClassName, string lpWindowName);



            [DllImport("user32.dll")]

            private static extern IntPtr FindWindowEx(IntPtr
hwndParent, IntPtr hwndChildAfter, string lpszClass, string
lpszWindow);



            [DllImport("user32.dll")]

            private static extern bool SetWindowText(IntPtr hWnd,
string lpString);



            [DllImport("user32.dll", SetLastError = true, CharSet =
CharSet.Auto)]

            private static extern int GetWindowText(IntPtr hWnd,
StringBuilder lpString, int nMaxCount);



            [DllImport("user32.dll", SetLastError = true, CharSet =
CharSet.Auto)]

            private static extern int GetWindowTextLength(IntPtr
hWnd);



            [DllImport("user32.dll")]

            private static extern IntPtr SetFocus(IntPtr hWnd);



            [DllImport("user32.dll", CharSet = CharSet.Auto)]

            static extern IntPtr SendMessage(IntPtr hWnd, uint Msg,
int wParam, //was intptr

                string lParam);



            [DllImport("user32.dll", CharSet = CharSet.Auto)]

            static extern IntPtr SendMessage(IntPtr hWnd, uint Msg,
int wParam,

                int lParam);

        }



        // Specify what you want to happen when the Elapsed event is
raised.

                //private static void OnTimedEvent(object source,
ElapsedEventArgs e)

                //{ Console.WriteLine("Hello World!");

                //}



    }

}


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to