public void CommandLineHandlerReadFileAndExecuteTest()
        {
            const string testFile = "testFile.in";
            var fileWriter = new StreamWriter(testFile);
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.WriteLine("|CloseBrowser|");
            fileWriter.Close();

            try
            {
                var testHandler = new CommandLineHandler(testFile);
                testHandler.Start();

                List<CommandResult> results = testHandler.GetCommandResults();
                Assert.AreEqual(results.Count, 2);
                Assert.AreEqual(results[0].Command, "OpenBrowser");
                Assert.AreEqual(results[1].Command, "CloseBrowser");
                Assert.IsTrue(results[0].Success);
                Assert.IsTrue(results[1].Success);
            }
            finally
            {
                File.Delete(testFile);
            }
        }
 public void SettingFitnesseVariableWithFakeVariableCausesFailureInCommandLineTest()
 {
     const string testFile = "testFakeFitVar.txt";
     StreamWriter file = new StreamWriter(testFile);
     file.WriteLine("!|Import|");
     file.WriteLine("|SWAT.Fitnesse|");
     file.WriteLine("!define testVar {QUBW1}");
     file.WriteLine("!define testVar2 {${testVa}}");
     file.WriteLine("!|InternetExplorerSWATFixture|");
     file.WriteLine("!|SWAT|");
     file.WriteLine("|OpenBrowser|");
     file.Close();
     try
     {
         CommandLineHandler handler = new CommandLineHandler(testFile);
         handler.Start();
         List<CommandResult> results = handler.GetCommandResults();
         Assert.IsFalse(results[3].Success, results[3].Message);
     }
     finally
     {
         File.Delete(testFile);
     }
 }
 public void GetTimerValueWorksCorrectlyInCommandLineTest()
 {
     const string testFile = "testTimer.txt";
     StreamWriter file = new StreamWriter(testFile);
     file.WriteLine("!|Import|");
     file.WriteLine("|SWAT.Fitnesse|");
     file.WriteLine("!|InternetExplorerSWATFixture|");
     file.WriteLine("!|SWAT|");
     file.WriteLine("|OpenBrowser|");
     file.WriteLine("|NavigateBrowser|www.google.com|");
     file.WriteLine("!|SWAT|");
     file.WriteLine("|StartTimer|timer1|");
     file.WriteLine("|Sleep|4230|");
     file.WriteLine("|DisplayTimerValue|timer1|");
     file.WriteLine("|GetTimerValue|var1|timer1|");
     file.WriteLine("|SetElementAttribute|name|q|value|>>var1<<|input|");
     file.WriteLine("!|SWAT|");
     file.WriteLine("|@@CloseBrowser|");
     file.Close();
     try
     {
         CommandLineHandler handler = new CommandLineHandler(testFile);
         handler.Start();
         List<CommandResult> results = handler.GetCommandResults();
         Assert.IsTrue(results[13].Success, results[13].Message);
     }
     finally
     {
         File.Delete(testFile);
     }
 }
 public void FakeFitnesseVariableCausesFailureInCommandLineTest()
 {
     const string testFile = "testFakeFitVar.txt";
     StreamWriter file = new StreamWriter(testFile);
     file.WriteLine("!|Import|");
     file.WriteLine("|SWAT.Fitnesse|");
     file.WriteLine("!define testVar {QUBW1}");
     file.WriteLine("!|InternetExplorerSWATFixture|");
     file.WriteLine("!|SWAT|");
     file.WriteLine("|OpenBrowser|");
     file.WriteLine("|NavigateBrowser|www.google.com|");
     file.WriteLine("|SetElementAttribute|name|q|value|${testVa}|");
     file.WriteLine("|AssertElementExists|Expression|name:q;value:Search|");
     file.WriteLine("|@@CloseBrowser|");
     file.Close();
     try
     {
         CommandLineHandler handler = new CommandLineHandler(testFile);
         handler.Start();
         List<CommandResult> results = handler.GetCommandResults();
         Assert.IsFalse(results[7].Success, results[7].Message);
     }
     finally
     {
         File.Delete(testFile);
     }
 }
        public void CommandLineHandlerModifiersTest()
        {
            const string testFile = "testFile.in";
            var fileWriter = new StreamWriter(testFile);
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.WriteLine("|NavigateBrowser|" + TestPage + "|");
            fileWriter.WriteLine("|@AssertElementExists|Id|fail$!!!@)(*&^%$#@|");
            fileWriter.WriteLine("|RefreshBrowser|");
            fileWriter.WriteLine("|AssertElementExists|Id|fail$!!!@)(*&^%$#@|");
            fileWriter.WriteLine("|@@RefreshBrowser|");
            fileWriter.WriteLine("|AssertElementExists|Id|fail$!!!@)(*&^%$#@|");
            fileWriter.WriteLine("|@@@RefreshBrowser|");
            fileWriter.WriteLine("|@@<>RefreshBrowser|");
            fileWriter.WriteLine("|@@CloseBrowser|");
            fileWriter.Close();

            try
            {
                var testHandler = new CommandLineHandler(testFile);
                testHandler.Start();

                List<CommandResult> results = testHandler.GetCommandResults();
                Assert.AreEqual(results.Count, 10);
                Assert.AreEqual(results[0].Command, "OpenBrowser");
                Assert.AreEqual(results[1].Command, "NavigateBrowser");
                Assert.AreEqual(results[2].Command, "AssertElementExists");
                Assert.AreEqual(results[3].Command, "RefreshBrowser");
                Assert.AreEqual(results[4].Command, "AssertElementExists");
                Assert.AreEqual(results[5].Command, "RefreshBrowser");
                Assert.AreEqual(results[6].Command, "AssertElementExists");
                Assert.AreEqual(results[7].Command, "RefreshBrowser");
                Assert.AreEqual(results[8].Command, "RefreshBrowser");
                Assert.AreEqual(results[9].Command, "CloseBrowser");

                Assert.IsTrue(results[0].Success);
                Assert.IsTrue(results[1].Success);
                Assert.IsFalse(results[2].Success);
                Assert.IsTrue(results[3].Success);
                Assert.IsFalse(results[4].Success);
                Assert.IsTrue(results[5].Success);
                Assert.IsTrue(results[6].Ignored);
                Assert.IsTrue(results[7].Success);
                Assert.IsFalse(results[8].Success);
                Assert.IsTrue(results[9].Success);
            }
            finally
            {
                File.Delete(testFile);
            }
        }
        public void CommandLineFinishBlockOnFailureModifierTest()
        {
            const string testFile = "testFile.in";
            StreamWriter fileWriter = new StreamWriter(testFile);
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.WriteLine("|NavigateBrowser|"+TestPage+"|");
            fileWriter.WriteLine("|%StimulateElement|Id|btnNwWindow|onclick|input|");
            fileWriter.WriteLine("|StimulateElement|Id|btnNewWindow|onclick|input|");
            fileWriter.WriteLine("|AttachToWindow|Second Window|");
            fileWriter.WriteLine("|CloseBrowser|");
            fileWriter.WriteLine("");
            fileWriter.WriteLine("|StimulateElement|Id|btnDialogNewPage|onclick|input|");
            fileWriter.WriteLine("|AssertJSDialogContent|Please press Ok to open new page|");
            fileWriter.WriteLine("|ClickJSDialog|CANCEL|");
            fileWriter.WriteLine("");
            fileWriter.WriteLine("|@@KillAllOpenBrowsers|");
            fileWriter.Close();
            try
            {
                CommandLineHandler testHandler = new CommandLineHandler(testFile);
                testHandler.Start();
                List<CommandResult> results = testHandler.GetCommandResults();
                Assert.AreEqual(results.Count, 12);
                Assert.AreEqual(results[0].Command, "OpenBrowser");
                Assert.AreEqual(results[1].Command, "NavigateBrowser");
                Assert.AreEqual(results[2].Command, "StimulateElement");
                Assert.AreEqual(results[3].Command, "StimulateElement");
                Assert.AreEqual(results[4].Command, "AttachToWindow");
                Assert.AreEqual(results[5].Command, "CloseBrowser");
                Assert.AreEqual(results[6].Command, null);
                Assert.AreEqual(results[7].Command, "StimulateElement");
                Assert.AreEqual(results[8].Command, "AssertJSDialogContent");
                Assert.AreEqual(results[9].Command, "ClickJSDialog");
                Assert.AreEqual(results[10].Command, null);
                Assert.AreEqual(results[11].Command, "KillAllOpenBrowsers");

                //Block 1
                Assert.IsTrue(results[0].Success);
                Assert.IsTrue(results[1].Success);
                Assert.IsFalse(results[2].Success);
                Assert.IsTrue(results[3].Success);
                Assert.IsTrue(results[4].Success);
                Assert.IsTrue(results[5].Success);
                //Block 2
                Assert.IsFalse(results[7].Success);
                Assert.IsFalse(results[8].Success);
                Assert.IsFalse(results[9].Success);
                //Block3
                Assert.IsTrue(results[11].Success);
            }
            finally
            {
                File.Delete(testFile);
            }
        }
        public void CommandLineHandlerCommentsTest()
        {
            const string testFile = "testFile.in";
            var fileWriter = new StreamWriter(testFile);
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.WriteLine("#|NavigateBrowser|" + TestPage + "|");
            fileWriter.WriteLine("|RefreshBrowser|");
            fileWriter.WriteLine("|CloseBrowser|");
            fileWriter.WriteLine("{|OpenBroser|");
            fileWriter.WriteLine("|CloseBrowser|}");
            fileWriter.Close();

            try
            {
                var testHandler = new CommandLineHandler(testFile);
                testHandler.Start();

                List<CommandResult> results = testHandler.GetCommandResults();
                Assert.AreEqual(results.Count, 6);
                Assert.AreEqual(results[0].Command, "OpenBrowser");
                Assert.AreEqual(results[2].Command, "RefreshBrowser");
                Assert.AreEqual(results[3].Command, "CloseBrowser");

                Assert.IsTrue(results[0].Success);
                Assert.IsFalse(results[1].Success);
                Assert.IsTrue(results[2].Success);
                Assert.IsTrue(results[3].Success);
                Assert.IsFalse(results[4].Success);
            }
            finally
            {
                File.Delete(testFile);
            }
        }
        public void CommandLineHandlerBrowserManipulationTest()
        {
            const string testFile = "testFile.in";
            var fileWriter = new StreamWriter(testFile);
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.WriteLine("|NavigateBrowser|" + TestPage + "|");
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.WriteLine("|AttachToWindow|SWAT Test Page|");
            fileWriter.WriteLine("|RefreshBrowser|");
            fileWriter.WriteLine("|CloseBrowser|");
            fileWriter.WriteLine("|KillAllOpenBrowsers|");
            fileWriter.Close();

            try
            {
                var testHandler = new CommandLineHandler(testFile);
                testHandler.Start();

                List<CommandResult> results = testHandler.GetCommandResults();
                Assert.AreEqual(results.Count, 7);
                Assert.AreEqual(results[0].Command, "OpenBrowser");
                Assert.AreEqual(results[1].Command, "NavigateBrowser");
                Assert.AreEqual(results[2].Command, "OpenBrowser");
                Assert.AreEqual(results[3].Command, "AttachToWindow");
                Assert.AreEqual(results[4].Command, "RefreshBrowser");
                Assert.AreEqual(results[5].Command, "CloseBrowser");
                Assert.AreEqual(results[6].Command, "KillAllOpenBrowsers");

                foreach (CommandResult result in results)
                    Assert.IsTrue(result.Success);
            }
            finally
            {
                File.Delete(testFile);
            }
        }