Exemple #1
0
        private WebSiteResult RunWebSite(RunParameters args)
        {
            if (!Path.IsPathRooted(args.WebSitePath))
            {
                args.WebSitePath = Path.Combine(FileSystem.CurrentDirectory, args.WebSitePath);
            }

            if (!FileSystem.DirectoryExists(args.WebSitePath))
            {
                return(new WebSiteResult()
                {
                    Passed = false,
                    Log = String.Format("Path to website '{0}' not found.", args.WebSitePath)
                });
            }

            string webSiteName = Path.GetFileName(args.WebSitePath);

            WriteLineToConsole(String.Format("Creating virtual directory for '{0}' website...", webSiteName));
            WebServer.CreateVirtualDirectory(webSiteName, args.WebSitePath, "localhost");


            FileSystem.AddDirectoryAccessRule(args.WebSitePath,
                                              new FileSystemAccessRule("NETWORK SERVICE", FileSystemRights.FullControl, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow));

            WriteLineToConsole(String.Format("Executing tests for '{0}' website...", webSiteName));
            string vdirUrl = "http://localhost/" + webSiteName;

            WebSiteResult webResult = this.RunLTAFAndWait(args, vdirUrl);

            webResult.WebSiteName = webSiteName;

            return(webResult);
        }
Exemple #2
0
        private void WriteLog(WebSiteResult result)
        {
            StringBuilder logBuilder = new StringBuilder();

            if (result.Passed)
            {
                logBuilder.AppendLine("Test Run PASSED");
            }
            else
            {
                logBuilder.AppendLine("Test Run FAILED");
            }

            logBuilder.Append(result.Log);

            FileSystem.WriteFile(Path.Combine(FileSystem.CurrentDirectory, LTAF_TESTLOGNAME), logBuilder.ToString());
        }
Exemple #3
0
        public int Run(RunParameters args)
        {
            if (args.PrintHelp)
            {
                this.PrintHelp();
                return(0);
            }

            WebSiteResult result = null;

            try
            {
                result = RunWebSite(args);
            }
            catch (Exception e)
            {
                WriteLineToConsole("Error: " + e.ToString(), ConsoleColor.Red);
            }

            if (result == null)
            {
                return(1);
            }
            else
            {
                WriteLog(result);

                if (result.Passed)
                {
                    WriteLineToConsole(String.Format("Website '{0}' passed!", result.WebSiteName), ConsoleColor.Green);
                    return(0);
                }
                else
                {
                    WriteLineToConsole(String.Format("Website '{0}' failed!", result.WebSiteName), ConsoleColor.Red);
                    return(1);
                }
            }
        }
Exemple #4
0
        private WebSiteResult RunLTAFAndWait(RunParameters args, string vdirUrl)
        {
            string startupPath = Path.Combine(args.WebSitePath, @"Test\" + LTAF_STARTUPFILENAME);
            string logPath     = Path.Combine(args.WebSitePath, @"Test\" + LTAF_TESTLOGNAME);

            if (FileSystem.FileExists(startupPath))
            {
                FileSystem.DeleteFile(startupPath);
            }
            if (FileSystem.FileExists(logPath))
            {
                FileSystem.DeleteFile(logPath);
            }

            WebSiteResult result = new WebSiteResult();

            StringBuilder url = new StringBuilder(vdirUrl.TrimEnd(new char[1] {
                '/'
            }) + "/Test/Default.aspx?");

            // append tag name
            if (!String.IsNullOrEmpty(args.TagName))
            {
                url.Append(String.Format("tag={0}&filter=true&", args.TagName));
            }

            //append auto run and auto log
            url.Append("run=true&log=true&console=false");


            args.Browser.Open(OperatingSystem, url.ToString());

            string content = String.Empty;

            if (WaitForStartup && !WaitForFile(startupPath, StartupTimeoutInMilliseconds, PollForLogInMilliseconds))
            {
                result.Passed = false;
                result.Log    = String.Format("Timed out waiting for browser to start up. Time out: {0} ms.", StartupTimeoutInMilliseconds);
            }
            else if (WaitForLog && !WaitForFile(logPath, args.ExecutionTimeout, PollForLogInMilliseconds, out content))
            {
                result.Passed = false;
                result.Log    = String.Format("Execution timed out. Time out: {0} ms.", args.ExecutionTimeout);
            }
            else
            {
                result.Log    = content;
                result.Passed = false;

                if (result.Log.Contains(LTAF_WEBSITE_FAILED))
                {
                    //if any test failed, then the whole suite failed.
                    result.Passed = false;
                }
                else if (result.Log.Contains(LTAF_WEBSITE_PASSED))
                {
                    //at least must have one testcase
                    result.Passed = true;
                }
            }

            args.Browser.Close(OperatingSystem);

            return(result);
        }