예제 #1
0
        private CompareResult RunTest(ArgsProcessor argProc, CompareResult overallResult, ReportSet reportSet, TestDescription test)
        {
            _driver.SetWindowSize(test.WindowSize);

            _driver.OpenUrl(test.Url, test.DivSelector, test.TitleContains);

            var dirManager = new DirectoryManager(argProc);

            if (argProc.IsOptionOn(ArgsProcessor.Options.Run))
            {
                var reportThisTest = CompareActualPageVersusExpected(argProc, dirManager, test, _driver);
                var resultThisTest = reportThisTest.Result.Result;
                if (resultThisTest != CompareResult.Similar)
                {
                    overallResult = resultThisTest;
                }
                reportSet.Reports.Add(reportThisTest);
            }
            else if (argProc.IsOptionOn(ArgsProcessor.Options.Save))
            {
                SaveExpectedPage(dirManager, test, _driver);
            }
            else
            {
                throw new InvalidOperationException("Not a supported set of options");
            }
            return(overallResult);
        }
예제 #2
0
        private static ReportSet CreateReport(ArgsProcessor argProc)
        {
            var reportSet = new ReportSet();

            reportSet.OverallResult = CompareResult.Similar;
            reportSet.Created       = DateTime.Now;
            reportSet.CsvFileName   = Path.GetFileName(argProc.GetArg(ArgsProcessor.Args.CSV_FILE_PATH));
            return(reportSet);
        }
예제 #3
0
        private void AppendResultToCombinedReport(ReportSet reportSet, ArgsProcessor argProc)
        {
            var dirManager      = new DirectoryManager(argProc);
            var combinedPersist = new CombinedReportPersistance(dirManager);

            combinedPersist.AddReportSet(reportSet);

            var htmlCreator = new CombinedHtmlReportCreator();

            htmlCreator.CreateReport(argProc);
        }
예제 #4
0
        private Report CompareActualPageVersusExpected(ArgsProcessor argProc, DirectoryManager dirManager,
                                                       TestDescription test, BrowserDriver driver)
        {
            string actualFilePath = dirManager.GetActualImageFilePath(test);

            driver.SaveDivImageToPath(test.DivSelector, actualFilePath, test.CropAdjustWidth, test.CropAdjustHeight, test.SleepTimespan);

            var comparer      = new CustomImageComparer(argProc);
            var compareResult = comparer.CompareImages(actualFilePath, dirManager.GetExpectedImageFilePath(test), test);

            var report = CreateReport(test, compareResult);

            return(report);
        }
예제 #5
0
        private void CreateReports(ArgsProcessor argProc, ReportSet reports)
        {
            var reporters = ReportCreatorFactory.CreateReporters(argProc);

            foreach (var reporter in reporters)
            {
                if (reporter.HasSaveCapability())
                {
                    reporter.SaveReport(reports);
                }

                reporter.ShowReport(reports, argProc.IsOptionOn(ArgsProcessor.Options.QuietNotShowResults));
            }
        }
예제 #6
0
        private static List <TestDescription> ReadTests(ArgsProcessor argProc)
        {
            List <TestDescription> testsToRun;
            List <TestDescription> tests;

            {
                var reader = new TestConfigReader();
                var path   = argProc.GetArg(ArgsProcessor.Args.CSV_FILE_PATH);
                tests = reader.ReadFromFilePath(path);
                Outputter.Output(string.Format("Read {0} tests from Test Suite: {1}", tests.Count, path));
            }

            testsToRun = TestDescription.GetTestsByName(tests, argProc.GetArg(ArgsProcessor.Args.TEST_NAME));
            return(testsToRun);
        }
예제 #7
0
        private static void ConvertActualToExpected(ArgsProcessor argProc)
        {
            //protect the saved 'expected' files, by prompting the user:
            var message = "Accept recent changes as new 'expected' images? [Y to continue]";

            if (!IsUserOkToContinue(message))
            {
                Outputter.Output("Cancelling...");
                return;
            }

            var testsToRun = ReadTests(argProc);
            var converter  = new ActualToExpectedConverter(argProc);

            converter.Convert(testsToRun);
        }
예제 #8
0
        internal CompareResult RunTests(List <TestDescription> testsToRun, ArgsProcessor argProc)
        {
            ReportSet reportSet = CreateReport(argProc);

            try
            {
                var watch = Stopwatch.StartNew();

                using (_driver = new BrowserDriver())
                {
                    foreach (var test in testsToRun)
                    {
                        Outputter.Output("Running test: " + test.Name + " - " + test.Description);
                        reportSet.OverallResult = RunTest(argProc, reportSet.OverallResult, reportSet, test);
                        Outputter.OutputSeparator();
                    }

                    watch.Stop();
                    reportSet.Duration = watch.Elapsed;

                    if (argProc.IsOptionOn(ArgsProcessor.Options.Run))
                    {
                        CreateReports(argProc, reportSet);
                    }
                }
            }
            catch (Exception ex)
            {
                reportSet.Exception = ex.Message;

                throw;
            }
            finally
            {
                _driver = null;
                //try to log the exception in the combined report:
                AppendResultToCombinedReport(reportSet, argProc);
            }

            return(reportSet.OverallResult);
        }
예제 #9
0
        /// <summary>
        /// the main entry point for the process.
        /// </summary>
        public static int Main(string[] args)
        {
            var isVerbose = false;

            try
            {
                ArgsProcessor argProc = new ArgsProcessor(args);

                string message;
                if (!argProc.Validate(out message))
                {
                    Console.WriteLine(message);
                    Console.WriteLine(argProc.GetUsage());
                    return(1);
                }

                isVerbose = argProc.IsOptionOn(ArgsProcessor.Options.Verbose);

                if (argProc.IsOptionOn(ArgsProcessor.Options.TestSelf))
                {
                    RunSelfTest();
                }
                else if (argProc.IsOptionOn(ArgsProcessor.Options.AcceptChanges))
                {
                    ConvertActualToExpected(argProc);
                }
                else

                {
                    var result = RunTests(argProc);
                    return(GetResultAsReturnCode(result));
                }
            }
            catch (Exception ex)
            {
                Outputter.Output(ex, isVerbose);
                return(2);
            }
            return(0);
        }
예제 #10
0
        private static CompareResult RunTests(ArgsProcessor argProc)
        {
            List <TestDescription> testsToRun = ReadTests(argProc);

            if (argProc.IsOptionOn(ArgsProcessor.Options.Save))
            {
                //protect the saved 'expected' files, by prompting the user:
                var message = "Get new saved 'expected' images? [Y to continue]";
                if (!IsUserOkToContinue(message))
                {
                    Outputter.Output("Cancelling...");
                    return(CompareResult.Cancelled);
                }
            }

            Outputter.OutputSeparator();
            var runner = new TestRunner();
            var result = runner.RunTests(testsToRun, argProc);

            Outputter.Output("Finished running tests:");
            Outputter.Output("[" + CompareResultHelper.GetResultAsString(result) + "]", CompareResultHelper.GetResultAsConsoleColor(result));
            return(result);
        }
예제 #11
0
        public DirectoryManager(ArgsProcessor argProc)
        {
            _argProc = argProc;

            imagesDirPath = argProc.GetArg(ArgsProcessor.Args.IMAGES_DIR_PATH);
        }
 public ActualToExpectedConverter(ArgsProcessor argProc)
 {
     this._argProc = argProc;
 }