public void TestGetelementAttributeAndSetAVariable()
        {
            /*
             * This test is importatnt because it saves a value to "variable", later on in another test there will be a Fixture.Recall(variable) will will 
             * replace the variable value for a new one. 
             */
            FireFoxSWATFixture testFixture = new FireFoxSWATFixture();
            SetDebugMode(testFixture, true);
            bool passed = true;

            fit.Parse testParse = new fit.Parse("<table><tr><td>SWATFixture</td></tr><tr><td>OpenBrowser</td></tr><tr><td>NavigateBrowser</td><td>file:///C:/SWAT/trunk/SWAT.Tests/TestPages/TestPage.htm</td></tr><tr><td>GetElementAttribute</td><td>Expression</td><td>id:dd</td><td>innerHTML</td><td>variable</td><td>a</td></tr><tr><td>CloseBrowser</td></tr></table>");

            try
            {
                testFixture.DoTable(testParse);
            }
            catch (Exception)
            {
                passed = false;
            }

            Assert.IsTrue(passed, "Command failed unexpectedly.");
            SetDebugMode(testFixture, false);
        }
        public void TestDisplayVariableCorrectlyDisplaysResultUsingFitnesse()
        {
            FireFoxSWATFixture testFixture = new FireFoxSWATFixture();

            string varName = "var1";
            fit.Parse testParse = new fit.Parse("<table><tr><td>SWATFixture</td></tr><tr><td>OpenBrowser</td></tr><tr><td>NavigateBrowser</td><td>file:///C:/SWAT/trunk/SWAT.Tests/TestPages/TestPage.htm</td></tr><tr><td>GetElementAttribute</td><td>Id</td><td>btnSetVal</td><td>value</td><td>" + varName + "</td></tr><tr><td>DisplayVariable</td><td>" + varName + "</td></tr><tr><td>CloseBrowser</td></tr></table>");

            testFixture.DoTable(testParse);
            string expectedVarValue = "Set Value";

            string result = parseString(testParse.Parts.At(4).Parts.At(1).ToString());

            Assert.AreEqual(expectedVarValue, result);
        }
        public void GetTimerValueWithTimerThatDoesNotExistsTest()
        {
            FireFoxSWATFixture testFixture = new FireFoxSWATFixture();
            SetDebugMode(testFixture, true);
            bool passed = true;

            string timerName = "timer1";
            string variable1 = "var1";
            fit.Parse testParse = new fit.Parse("<table><tr><td>SWATFixture</td></tr><tr><td>GetTimerValue</td><td>" + variable1 + "</td><td>" + timerName + "</td></tr></table>");
            
            try
            {
                testFixture.DoTable(testParse);
                passed = false;
            }
            catch (AssertionFailedException)
            {
                passed = true;
            }

            Assert.IsTrue(passed, "Command failed unexpectedly.");
            SetDebugMode(testFixture, false);
        }
        public void TestDisplayTimerValueCorrectlyDisplaysResultUsingFitnesse()
        {
            FireFoxSWATFixture testFixture = new FireFoxSWATFixture();

            string timerName = "timer1";
            fit.Parse testParse = new fit.Parse("<table><tr><td>SWATFixture</td></tr><tr><td>StartTimer</td><td>" + timerName + "</td></tr><tr><td>Sleep</td><td>1500</td></tr><tr><td>DisplayTimerValue</td><td>" + timerName + "</td></tr></table>");

            testFixture.DoTable(testParse);

            int timerValue;
            string result = parseString(testParse.Parts.At(3).Parts.At(1).ToString());
            System.Console.Write(int.TryParse(result, out timerValue));
            Assert.IsTrue(int.TryParse(result, out timerValue));
        }
        public void CloseBrowsersBeforeTestStartTest()
        {
            // Save the value to reset it later
            bool reset = SWAT.WantCloseBrowsersBeforeTestStart.CloseBrowsersBeforeTestStart;
            string ieProcessName = "iexplore";
            string ffProcessName = "firefox";
            bool areAllIEClosed;
            bool areAllFFClosed;
            WebBrowser _IEBrowser = new WebBrowser(BrowserType.InternetExplorer);
            WebBrowser _FFBrowser = new WebBrowser(BrowserType.FireFox);
            SWAT.Fitnesse.SWATFixture testing;

            // Open multiple windows to close
            _IEBrowser.OpenBrowser();
            _IEBrowser.NavigateBrowser("www.google.com");
            _IEBrowser.OpenBrowser();
            _IEBrowser.NavigateBrowser("www.w3schools.com");

            // Set the user setting to false
            SWAT.WantCloseBrowsersBeforeTestStart.CloseBrowsersBeforeTestStart = false;
            SWAT.UserConfigHandler.Save();

            // SWATFixture's constructor should not kill all open IE browsers
            testing = new InternetExplorerSWATFixture();

            // Assert that all the IE browsers have not closed
            areAllIEClosed = (Process.GetProcessesByName("iexplore").Length == 0);
            Assert.IsFalse(areAllIEClosed, "CloseBrowsersBeforeTestStart failed: " +
                           "closed all windows when the user setting was turned off.");

            // Open multiple windows to close again
            _IEBrowser.OpenBrowser();
            _IEBrowser.NavigateBrowser("www.google.com");
            _IEBrowser.OpenBrowser();
            _IEBrowser.NavigateBrowser("www.w3schools.com");

            // Set the user setting to true
            SWAT.WantCloseBrowsersBeforeTestStart.CloseBrowsersBeforeTestStart = true;
            SWAT.UserConfigHandler.Save();

            // SWATFixture's constructor should kill all open IE browsers
            testing = new InternetExplorerSWATFixture();

            // Assert that all the IE windows have been closed
            areAllIEClosed = (Process.GetProcessesByName(ieProcessName).Length == 0);
            Assert.IsTrue(areAllIEClosed, "CloseBrowsersBeforeTestStart failed: " +
                          "did not close all windows.");

            // Open multiple windows to close again
            _IEBrowser.OpenBrowser();
            _IEBrowser.NavigateBrowser("www.google.com");
            _IEBrowser.OpenBrowser();
            _IEBrowser.NavigateBrowser("www.w3schools.com");

            // Open multiple windows to close again
            _FFBrowser.OpenBrowser();
            _FFBrowser.NavigateBrowser("www.google.com");
            _FFBrowser.OpenBrowser();
            _FFBrowser.NavigateBrowser("www.w3schools.com");

            // SWATFixture's constructor should kill all open IE and FF browsers
            testing = new FireFoxSWATFixture();

            // Assert that all the IE windows have been closed
            areAllIEClosed = (Process.GetProcessesByName(ieProcessName).Length == 0);
            Assert.IsTrue(areAllIEClosed, "CloseBrowsersBeforeTestStart failed: " +
                          "did not close all windows.");

            // Assert that all the FF windows have been closed
            areAllFFClosed = (Process.GetProcessesByName(ffProcessName).Length == 0);
            Assert.IsTrue(areAllFFClosed, "CloseBrowsersBeforeTestStart failed: " +
                          "did not close all windows.");

            // Reset the user config setting
            SWAT.WantCloseBrowsersBeforeTestStart.CloseBrowsersBeforeTestStart = reset;
            SWAT.UserConfigHandler.Save();

        }
        public void TestFitnesseWithMultipleColumnData()
        {
            FireFoxSWATFixture testFixture = new FireFoxSWATFixture();
            SetDebugMode(testFixture, true);
            bool passed = false;

            fit.Parse testParse = new fit.Parse("<table><tr><td>SWATFixture</td></tr><tr><td>BeginCompareData</td></tr><tr><td>Column1</td><td>Column2</td></tr><tr><td>Data1</td><td>Data2</td></tr><tr><td>EndCompareData</td></tr></table>");

            try
            {
                testFixture.DoTable(testParse);
            }
            catch (SWAT.AssertionFailedException)
            {
                passed = true;
            }

            Assert.IsTrue(passed, "Command did not throw an exception as expected.");
            SetDebugMode(testFixture, false);
        }
        public void TestFitnesseWithCommandThatDoesNotPass()
        {
            FireFoxSWATFixture testFixture = new FireFoxSWATFixture();
            SetDebugMode(testFixture, true);
            bool passed = false;

            fit.Parse testParse = new fit.Parse("<table><tr><td>SWATFixture</td></tr><tr><td>OpenBrowser</td></tr><tr><td>CloseBrowser</td></tr><tr><td>GetElementAttribute</td><td>Expression</td><td>id:IdontExist</td><td>value</td><td>variable</td><td>a</td></tr></table>");
            
            try
            {
                testFixture.DoTable(testParse);
            }
            catch (SWAT.AssertionFailedException)
            {
                passed = true;
            }

            Assert.IsTrue(passed, "Command did not throw an exception as expected.");
            SetDebugMode(testFixture, false);
        }
        public void TestFitnesseWithInverserModifier()
        {
            FireFoxSWATFixture testFixture = new FireFoxSWATFixture();
            SetDebugMode(testFixture, true);
            bool passed = true;

            fit.Parse testParse = new fit.Parse("<table><tr><td>SWATFixture</td></tr> <tr><td>OpenBrowser</td></tr><tr><td>NavigateBrowser</td><td>file:///C:/SWAT/trunk/SWAT.Tests/TestPages/TestPage.htm</td></tr><tr><td>&lt;&gt;GetElementAttribute</td><td>Expression</td><td>id:IDontExist</td><td>variable</td><td>a</td></tr><tr><td>CloseBrowser</td></tr></table>");

            try
            {
                testFixture.DoTable(testParse);
            }
            catch (Exception)
            {
                passed = false;
            }

            Assert.IsTrue(passed, "Command failed unexpectedly.");
            SetDebugMode(testFixture, false);
        }
 public void TestFireFoxSWATFixtureTestTable()
 {
     object[] fixtureValues = {
         "<table><tr><td>SWATFixture</td></tr><tr><td>OpenBrowser</td></tr><tr><td>NavigateBrowser</td><td>file:///C:/SWAT/trunk/SWAT.Tests/TestPages/TestPage.htm</td></tr><tr><td>GetElementAttribute</td><td>Expression</td><td>id:dd</td><td>innerHTML</td><td>variable</td><td>a</td></tr><tr><td>CloseBrowser</td> </tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>SetElementAttribute</td><td>Id</td><td>txtOne</td><td>value</td><td>>>variable<<</td><td>*</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>GetElementAttribute</td><td>InnerHtml</td><td>testing</td><td>value</td><td>variable</td><td>*</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetDbRecord</td><td>VariableName</td><td>1</td><td>1</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetDbDate</td><td>VariableName</td><td>1</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetLocation</td><td>Variable</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>OpenBrowser</td></tr><tr><td>GetWindowTitle</td><td>Variable</td></tr><tr><td>CloseBrowser</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>RunScriptSaveResult</td><td>ScriptThatReturnsAValue</td><td>VariableName</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetDbRecordByColumnName</td><td>VariableName</td><td>1</td><td>1</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>BeginCompareData</td></tr></table> ", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>OpenBrowser</td></tr><tr><td>NavigateBrowser</td><td>http://www.google.com</td></tr><tr><td colspan=\"2\">CloseBrowser</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>SetVariable</td><td>variable</td><td>testing</td></tr><tr><td><>SetElementAttribute</td><td>Id</td><td>txtOne</td><td>value</td><td>>>variable<<</td><td>*</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetElementAttribute</td><td>InnerHtml</td><td>testing</td><td>value</td><td>variable</td><td>*</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetDbRecord</td><td>VariableName</td><td>1</td><td>1</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>GetDbDate</td><td>VariableName</td><td>1</td></tr></table> ", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>SaveDbDate</td><td>1</td></tr></table> ", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>GetSavedDbDate</td><td>VariableName</td><td>1</td></tr></table> ", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>GetSavedDbDateDay</td><td>VariableName</td><td>1</td></tr></table> ", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>GetSavedDbDateMonth</td><td>VariableName</td><td>1</td></tr></table> ", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>GetSavedDbDateYear</td><td>VariableName</td><td>1</td></tr></table> ", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetLocation</td><td>Variable</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>OpenBrowser</td></tr><tr><td>GetWindowTitle</td><td>Variable</td></tr><tr><td>CloseBrowser</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>RunScriptSaveResult</td><td>ScriptThatReturnsAValue</td><td>VariableName</td></tr></table> ", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetDbRecordByColumnName</td><td>VariableName</td><td>1</td><td>1</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>SetVariable</td><td>VariableName</td><td>Hello World 123</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>&lt;&gt;BeginCompareData</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td><>OpenBrowser</td></tr><tr><td>@@NavigateBrowser</td><td>http://www.google.com</td></tr><tr><td>@@CloseBrowser</td></tr></table>", false,
         "<table><tr><td>SWATFixture</td></tr><tr><td>EndCompareData</td></tr></table>", true,
         "<table><tr><td>SWATFixture</td></tr><tr><td>GetConfigurationItem</td><td>FindElementTimeout</td><td>configItemVar</td></tr></table>", false
     };
     FireFoxSWATFixture testFixture = new FireFoxSWATFixture();
     for (int i = 0; i < fixtureValues.Length; i += 2)
     {
         TestManager.InCompareData = (bool) fixtureValues[i + 1];
         fit.Parse testParse = new fit.Parse((string)fixtureValues[i]);
         testFixture.DoTable(testParse);
         TestManager.ResetForNewTest();
     }
 }