Beispiel #1
0
 private static void RunSelfTest()
 {
     Outputter.Output("Running self test ...");
     using (BrowserDriver driver = new BrowserDriver())
     {
         driver.TestChrome();
     }
     Outputter.Output("self test ran [OK]");
 }
Beispiel #2
0
        private static bool IsUserOkToContinue(string message)
        {
            Outputter.Output(message);
            var keyInfo = Console.ReadKey();

            Console.WriteLine();
            bool isOk = keyInfo.KeyChar.ToString().ToLowerInvariant() == "y";

            return(isOk);
        }
        internal void Convert(List <TestDescription> tests)
        {
            var dirManager = new DirectoryManager(_argProc);

            foreach (var test in tests)
            {
                Outputter.Output("Accepting latest changes for test: " + test.Name);

                var actualPath   = dirManager.GetActualImageFilePath(test);
                var expectedPath = dirManager.GetExpectedImageFilePath(test);
                File.Copy(actualPath, expectedPath, true);
            }
            Outputter.Output("Accepted latest changes for " + tests.Count + " tests.");
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }
Beispiel #9
0
 private void SaveExpectedPage(DirectoryManager dirManager, TestDescription test, BrowserDriver driver)
 {
     Outputter.Output("Saving expected page for test: " + test.Name);
     driver.SaveDivImageToPath(test.DivSelector, dirManager.GetExpectedImageFilePath(test), test.CropAdjustWidth, test.CropAdjustHeight, test.SleepTimespan);
 }