示例#1
0
        /// <summary>
        /// Runs the specified package.
        /// </summary>
        /// <param name="package">The package.</param>
        /// <returns>The updated package.</returns>
        public static Package Run(Package package)
        {
            using (var driver = GetWebDriver(package))
            {
                var controller = new PackageController(driver);
                package = controller.Run(package);
            }

            return package;
        }
示例#2
0
        /// <summary>
        /// Gets the web driver.
        /// </summary>
        /// <param name="package">The package.</param>
        /// <returns>The web driver.</returns>
        private static IWebDriver GetWebDriver(Package package)
        {
            switch (package.WebBrowser)
            {
                case WebBrowser.InternetExplorer:
                    return new InternetExplorerDriver();

                case WebBrowser.GoogleChrome:
                    return new ChromeDriver();

                case WebBrowser.MozillaFirefox:
                    return new FirefoxDriver();

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
示例#3
0
 public PackageHelper(Package package)
 {
     _package = package;
 }
示例#4
0
        /// <summary>
        /// Runs the specified package.
        /// </summary>
        /// <param name="package">The package.</param>
        /// <returns>A <see cref="Package"/> with the result of the package tests.</returns>
        public Package Run(Package package)
        {
            var actionNumber = 1;
            var defaultColor = Console.ForegroundColor;

            try
            {
                Console.WriteLine("-> [{0}] Running script \"{1}\"", actionNumber++, package.Name);

                foreach (var action in package.Actions)
                {
                    var retryCount = 0;
                    var actionCompleted = false;

                    Console.ForegroundColor = defaultColor;
                    Console.WriteLine("-> [{0}] {1}", actionNumber, action.GetDescriptor());

                    while (!actionCompleted)
                    {
                        try
                        {
                            action.Run(_driver);
                            actionCompleted = true;
                        }
                        catch
                        {
                            retryCount++;

                            if (retryCount > MaximumNumberOfRetries)
                            {
                                throw;
                            }

                            Thread.Sleep(RetryInterval * 1000);
                        }
                    }

                    var test = action as TestAction;
                    if (test != null)
                    {
                        switch (test.GetResult())
                        {
                            case TestStatus.Pass:
                                Console.ForegroundColor = ConsoleColor.Green;
                                Console.WriteLine("-> [{0}] Test Result: {1}", actionNumber, test.GetResult());
                                break;

                            case TestStatus.Fail:
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("-> [{0}] Test Result: {1} : Actual Value: \"{2}\"", actionNumber,
                                    test.GetResult(), test.ActualValue);
                                break;

                            default:
                                Console.ForegroundColor = ConsoleColor.Blue;
                                Console.WriteLine("-> [{0}] Test Result: {1}", actionNumber, test.GetResult());
                                break;
                        }
                    }

                    actionNumber++;
                }
            }
            catch (Exception exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("-> **ERROR: {0}", exception.Message);
            }
            finally
            {
                if (package.AllTests.Any(x => x.GetResult() != TestStatus.Pass))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("-> [{0}] {1}/{2} Tests Failed", actionNumber++,
                        package.AllTests.Count(x => x.GetResult() != TestStatus.Pass), package.AllTests.Count());
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("-> [{0}] {1}/{2} Tests Passed", actionNumber++,
                        package.AllTests.Count(x => x.GetResult() == TestStatus.Pass), package.AllTests.Count());
                }

                Console.ForegroundColor = defaultColor;
                Console.WriteLine("-> [{0}] Finished", actionNumber);
            }

            return package;
        }