Пример #1
0
        private TestSet buildTestSet(string testFileName, string url = "testUrl")
        {
            SetEnvironmentVariable(EnvVar.Browser, "chrome");
            SetEnvironmentVariable(EnvVar.Environment, "");
            SetEnvironmentVariable(EnvVar.TimeOutThreshold, "50");
            SetEnvironmentVariable(EnvVar.WarningThreshold, "50");
            SetEnvironmentVariable(EnvVar.URL, url);
            SetEnvironmentVariable(EnvVar.DataFile, $"{readFileLocation}{testFileName}");
            SetEnvironmentVariable(EnvVar.CsvSaveFileLocation, saveFileLocation);
            SetEnvironmentVariable(EnvVar.LogSaveFileLocation, saveFileLocation);
            SetEnvironmentVariable(EnvVar.ReportSaveFileLocation, saveFileLocation);
            SetEnvironmentVariable(EnvVar.ScreenshotSaveLocation, saveFileLocation);
            SetEnvironmentVariable(EnvVar.TestAutomationDriver, "selenium");
            SetEnvironmentVariable(EnvVar.TestSetDataType, "XML");
            SetEnvironmentVariable(EnvVar.TestSetDataArgs, $"{readFileLocation}{testFileName}");
            SetEnvironmentVariable(EnvVar.TestCaseDataType, GetEnvironmentVariable(EnvVar.TestSetDataType));
            SetEnvironmentVariable(EnvVar.TestStepDataType, GetEnvironmentVariable(EnvVar.TestCaseDataType));
            SetEnvironmentVariable(EnvVar.TestCaseDataArgs, GetEnvironmentVariable(EnvVar.TestSetDataArgs));
            SetEnvironmentVariable(EnvVar.TestStepDataArgs, GetEnvironmentVariable(EnvVar.TestCaseDataArgs));
            SetEnvironmentVariable(EnvVar.RespectRepeatFor, "true");
            SetEnvironmentVariable(EnvVar.RespectRunAODAFlag, "true");

            InformationObject.SetUp();
            TestSetBuilder builder = new TestSetBuilder();

            BuildAutomationDriver();

            return(builder.Build());
        }
        /// <summary>
        /// The Main functionality.
        /// </summary>
        /// <param name="args">Arguments to be passed in.</param>
        /// <returns> 0 if no errors were met. </returns>
        public static int Main(string[] args)
        {
            bool errorParsing;
            int  resultCode = 0;

            errorParsing = ParseCommandLine(args);

            if (!errorParsing)
            {
                if (update.Equals("true"))
                {
                    Logger.Info("Checking for updates...");
                    if (CheckForUpdates(Assembly.GetExecutingAssembly().Location))
                    {
                        string newArgs = string.Join(" ", args.Select(x => string.Format("\"{0}\"", x)).ToList());
                        using (Process p = new Process())
                        {
                            ProcessStartInfo startInfo = new ProcessStartInfo
                            {
                                UseShellExecute        = false,
                                RedirectStandardOutput = false,
                                RedirectStandardError  = false,
                                FileName  = "AutoUpdater.exe",
                                Arguments = newArgs,
                            };

                            p.StartInfo = startInfo;
                            p.Start();
                        }

                        Thread.Sleep(5000);

                        // Closes the current process
                        Environment.Exit(0);
                    }
                    else
                    {
                        Logger.Info("Program is up to date");
                    }
                }

                errorParsing = ParseTestSetParameters();
                SetDefaultParameters();
            }

            Logger.Info($"Running AutomationFramework Version: {FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion}");

            if (!errorParsing)
            {
                // Set up all the parts.
                InformationObject.SetUp();

                TestSetBuilder setBuilder = new TestSetBuilder();
                TestSet        testSet    = setBuilder.Build();

                TestAutomationBuilder automationBuilder = new TestAutomationBuilder();
                automationBuilder.Build();

                // Run main program.
                DateTime start = DateTime.UtcNow;
                AutomationTestSetDriver.RunTestSet(testSet);

                RunAODA();

                DateTime end = DateTime.UtcNow;

                InformationObject.Reporter.Report();

                InformationObject.CSVLogger.AddResults($"Total, {Math.Abs((start - end).TotalSeconds)}");
                InformationObject.CSVLogger.WriteOutResults();

                string resultString = testSet.TestSetStatus.RunSuccessful ? "successful" : "not successful";
                Logger.Info($"Automation Testing Program has finished. It was {resultString}");
            }
            else
            {
                resultCode = 1;
            }

            Environment.Exit(resultCode);
            return(resultCode);
        }