private static void Main(string[] args)
        {
            if (args.Length == 2)
            {
                string inputPath = args[0];
                string outputPath = args[1];
                string outputDir = outputPath;

                if (outputPath.LastIndexOf('\\') >= 0)  //check that '\\' exists
                    outputDir = outputPath.Substring(0, outputPath.LastIndexOf('\\'));

                try
                {
                    var handler = new CommandLineHandler(args[0]);
                    handler.Start();
                    handler.Save(args[1]);

                    System.Console.WriteLine(@"Finished!");
                }
                catch(DirectoryNotFoundException e)
                {
                    string unknownDirectory = e.Message.Substring(e.Message.IndexOf('\'') + 1);
                    unknownDirectory = unknownDirectory.Substring(0, unknownDirectory.LastIndexOf('\''));
                    string pathNotFound = "";

                    if (unknownDirectory.Equals(inputPath))
                    {
                        pathNotFound = "Input";

                        if (!Directory.Exists(outputDir))
                        {
                            pathNotFound += " and output";
                            unknownDirectory += " " + outputDir;
                        }
                    }

                    else if (unknownDirectory.Equals(outputPath))
                        pathNotFound = "Output";

                    System.Console.WriteLine(pathNotFound + @" directory not found: " + unknownDirectory);
                }
                catch (FileNotFoundException)
                {
                    System.Console.WriteLine(@"File not found: " + args[0]);
                }
            }
            else
            {
                System.Console.WriteLine(@"Error: Unrecognized or incomplete command line.");
                System.Console.WriteLine(@"USAGE: SWAT.Console input.txt output.html");
            }
        }
        public void CommandLineHandlerWriteFileTest()
        {
            const string inputFile = "testFile.in";
            const string outputFile = "testFile.out";
            const string includeRoot = "C:\\TestSwatMacros";
            const string includeDir = "C:\\TestSwatMacros\\SetBrowser";
            const string includeFile = "C:\\TestSwatMacros\\SetBrowser\\content.txt";

            //Create Include file.
            Directory.CreateDirectory(includeDir);
            var includeWriter = new StreamWriter(includeFile);
            includeWriter.WriteLine("!|FireFoxSWATFixture|");
            includeWriter.WriteLine("This is a nested comment.");
            includeWriter.WriteLine("|OpenBrowser|");
            includeWriter.Close();

            var fileWriter = new StreamWriter(inputFile);
            fileWriter.WriteLine("!include TestSwatMacros.SetBrowser.DoesNotExist");
            fileWriter.WriteLine("!include TestSwatMacros.SetBrowser");
            fileWriter.WriteLine("!|InternetExplorerSWATFixture|");
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.WriteLine("|NavigateBrowser|www.google.com|");
            fileWriter.WriteLine("|GetWindowTitle|currentTitle|");
            fileWriter.WriteLine("|AssertEqualTo|Google|>>currentTitle<<|");
            fileWriter.WriteLine("We expect this to fail.");
            fileWriter.WriteLine("|AssertElementExists|Id|fail)(*&^%$#@!|");
            fileWriter.WriteLine("|CloseBrowser|");
            fileWriter.WriteLine("|@@KillAllOpenBrowsers|");
            fileWriter.WriteLine("|NavigateBrowser|www.google.com|");
            fileWriter.WriteLine("|SetVariable|myVar|allswatcommands|");
            fileWriter.WriteLine("|SetElementAttribute|name|q|value|>>myVar<<|input|");
            fileWriter.WriteLine("|StimulateElement|name|btnG|onclick|input|");
            fileWriter.WriteLine("!include SwatMacros.UltiproEverest.CurrentBrowserType");
            fileWriter.WriteLine("|OpenBrowser|");
            fileWriter.Close();

            try
            {
                var testHandler = new CommandLineHandler(inputFile);
                testHandler.Start();
                testHandler.Save(outputFile);

                string[] expectedOutput =
                    {
                        "<html><head><title>testFile.in Results</title></head>",
                        "<body>",
                        "<center>",
                        "<font size=10>testFile.in Results</font>",
                        "<br>",
                        "<font size=4>Browser: FireFox</font>",
                        "<br>",
                        "<br>",
                        "<table width=30%>",
                        "<td bgcolor=green><font color=white>7 Right.</td>",
                        "<td bgcolor=red><font color=white>3 Wrong.</td>",
                        "<td bgcolor=gray><font color=white>6 Ignored.</td>",
                        "</table>",
                        "<br>",
                        "<table width=80%>",
                        "<td width=5%></td>",
                        "<td width=25%></td>",
                        "<td width=20%></td>",
                        "<td width=8%></td>",
                        "<td width=2%></td>",
                        "<td width=15%></td>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>1</td>",
                        "<td bgcolor=#FFF4D6><font color=black>!include TestSwatMacros.SetBrowser.DoesNotExist</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=red><font color=white>Failure</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black>Could not load macro at C:\\TestSwatMacros\\SetBrowser\\DoesNotExist\\</td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>2</td>",
                        "<td bgcolor=#FFF4D6><font color=black>!include TestSwatMacros.SetBrowser</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=green><font color=white>Success</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "</table>",
                        "<table width=80%>",
                        "<td width=5%></td>",
                        "<td>This is a nested comment.</td>",
                        "</table>",
                        "<table width=80%>",
                        "<td width=5%></td>",
                        "<td width=25%></td>",
                        "<td width=20%></td>",
                        "<td width=8%></td>",
                        "<td width=2%></td>",
                        "<td width=15%></td>",
                        "</table>",
                        "<table width=80%>",
                        "<td width=5%></td>",
                        "<td width=5%></td>",
                        "<td width=25%></td>",
                        "<td width=20%></td>",
                        "<td width=8%></td>",
                        "<td width=2%></td>",
                        "<td width=15%></td>",
                        "<tr>",
                        "<td width=5%></td>",
                        "<td bgcolor=#FFF4D6><font color=black>3</td>",
                        "<td bgcolor=#FFF4D6><font color=black>OpenBrowser</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=green><font color=white>Success</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "</table>",
                        "<table width=80%>",
                        "<td width=5%></td>",
                        "<td width=25%></td>",
                        "<td width=20%></td>",
                        "<td width=8%></td>",
                        "<td width=2%></td>",
                        "<td width=15%></td>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>4</td>",
                        "<td bgcolor=#FFF4D6><font color=black>OpenBrowser</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=green><font color=white>Success</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>5</td>",
                        "<td bgcolor=#FFF4D6><font color=black>NavigateBrowser</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">www.google.com</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=green><font color=white>Success</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>6</td>",
                        "<td bgcolor=#FFF4D6><font color=black>GetWindowTitle</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">currentTitle</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=green><font color=white>Success</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>7</td>",
                        "<td bgcolor=#FFF4D6><font color=black>AssertEqualTo</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">Google</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">Google</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=green><font color=white>Success</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "</table>",
                        "<br>",
                        "<table width=80%>",
                        "<td>We expect this to fail.</td>",
                        "</table>",
                        "<table width=80%>",
                        "<td width=5%></td>",
                        "<td width=25%></td>",
                        "<td width=20%></td>",
                        "<td width=8%></td>",
                        "<td width=2%></td>",
                        "<td width=15%></td>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>9</td>",
                        "<td bgcolor=#FFF4D6><font color=black>AssertElementExists|Id|fail)(*&^%$#@!|</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">Id</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">fail)(*&^%$#@!</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=red><font color=white>Failure</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black>Element with Id fail)(*&^%$#@! was not found.</td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>10</td>",
                        "<td bgcolor=#FFF4D6><font color=black>CloseBrowser</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=gray><font color=white>Ignored</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>11</td>",
                        "<td bgcolor=#FFF4D6><font color=black>@@KillAllOpenBrowsers</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=green><font color=white>Success</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>12</td>",
                        "<td bgcolor=#FFF4D6><font color=black>NavigateBrowser</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">www.google.com</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=gray><font color=white>Ignored</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>13</td>",
                        "<td bgcolor=#FFF4D6><font color=black>SetVariable</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">myVar</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">allswatcommands</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=gray><font color=white>Ignored</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>14</td>",
                        "<td bgcolor=#FFF4D6><font color=black>SetElementAttribute</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">name</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">q</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">value</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">>>myVar<<</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">input</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=gray><font color=white>Ignored</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>15</td>",
                        "<td bgcolor=#FFF4D6><font color=black>StimulateElement</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">name</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">btnG</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">onclick</div>",
                        "</td>",
                        "<td width=0% bgcolor=#FFF4D6>",
                        "<div style=\"border: solid 0 #060; border-left-width:2px; padding-left:0.5ex\">input</div>",
                        "</td>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=gray><font color=white>Ignored</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>16</td>",
                        "<td bgcolor=#FFF4D6><font color=black>!include SwatMacros.UltiproEverest.CurrentBrowserType</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=red><font color=white>Failure</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black>Could not load macro at C:\\SwatMacros\\UltiproEverest\\CurrentBrowserType\\</td>",
                        "</tr>",
                        "<tr>",
                        "<td bgcolor=#FFF4D6><font color=black>17</td>",
                        "<td bgcolor=#FFF4D6><font color=black>OpenBrowser</td>",
                        "<td width=20% bgcolor=#FFF4D6>",
                        "<table width=100%>",
                        "</td>",
                        "</table>",
                        "<td bgcolor=gray><font color=white>Ignored</td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "<td bgcolor=#FFF4D6><font color=black></td>",
                        "</tr>",
                        "</table>",
                        "</center>",
                        "</body>",
                        "</html>"
                    };

                var fileReader = new StreamReader(outputFile);
                string line;
                var actualOutput = new List<string>();
                while ((line = fileReader.ReadLine()) != null)
                    actualOutput.Add(line);

                fileReader.Close();

                for (int i = 0; i < actualOutput.Count; i++)
                    Assert.AreEqual(expectedOutput[i], actualOutput[i]);
            }
            finally
            {
                File.Delete(inputFile);
                File.Delete(outputFile);
                File.Delete(includeFile);
                Directory.Delete(includeDir);
                Directory.Delete(includeRoot);
            }
        }