Пример #1
0
        public void Execute()
        {
            var browsers = ConfigurationManager.AppSettings["browsers"].Split(',');
            foreach (var browser in browsers)
            {

                ExcelRepository target = new ExcelRepository();
                TestManager manager = new TestManager(target);
                string masterfile = Path.IsPathRooted(ConfigurationManager.AppSettings["masterfile"]) ? ConfigurationManager.AppSettings["masterfile"] :
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["masterfile"]);
                string sequenceFilename = Path.IsPathRooted(ConfigurationManager.AppSettings["sequencefile"]) ? ConfigurationManager.AppSettings["sequencefile"] :
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["sequencefile"]);
                string uimapFilename = Path.IsPathRooted(ConfigurationManager.AppSettings["uimapfile"]) ? ConfigurationManager.AppSettings["uimapfile"] :
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["uimapfile"]);
                string dataDirectory = Path.IsPathRooted(ConfigurationManager.AppSettings["datadirectory"]) ? ConfigurationManager.AppSettings["datadirectory"] :
                    Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConfigurationManager.AppSettings["datadirectory"]);
                string resultsFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Results");
                var config = new WebAutoConfiguration();
                config.DataDirectory = dataDirectory;
                config.UIMapFile = uimapFilename;
                config.ResultsFolder = resultsFolder;
                config.Browser = browser.Trim();
                config.FileExtension = ".xlsx";

                manager.Execute(target.GetTestSuites(masterfile, sequenceFilename), config);
            }
        }
Пример #2
0
        public CommandExecutionResult Execute(UITestSuite[] testSuites, WebAutoConfiguration configuration)
        {
            if (!Directory.Exists(configuration.ResultsFolder))
            {
                Directory.CreateDirectory(configuration.ResultsFolder);
            }

            CommandExecutionResult result = new CommandExecutionResult {
                CommandResult = CommandResult.Success, Message = string.Empty
            };
            Assembly assembly = Assembly.LoadFrom("WebAuto.Commands.dll");

            var uiMap = Repository.GetUIMap(configuration.UIMapFile);

            foreach (var testSuite in testSuites)
            {
                Console.WriteLine(testSuite.Name);
                foreach (var testcase in testSuite)
                {
                    Console.WriteLine(string.Format(" {0}", testcase.Value.GroupName));
                    var dataBucket = Repository.GetData(Path.Combine(configuration.DataDirectory, testcase.Value.GroupName + configuration.FileExtension));

                    IWebDriver driver = null;
                    switch (configuration.Browser)
                    {
                    case "firefox":
                        driver = new FirefoxDriver();
                        break;

                    case "chrome":
                        driver = new ChromeDriver();
                        break;

                    case "ie":
                        driver = new InternetExplorerDriver();
                        break;

                    case "htmlunit":
                        driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript());
                        break;

                    default:
                        driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnit());
                        break;
                    }
                    driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 20));
                    new Utility().ResizeTest(driver);

                    var usedData = new Dictionary <string, int>();
                    foreach (var sequence in testcase.Value.CommandGroups.Sequences)
                    {
                        var commandContainer = new UICommandContainer();
                        commandContainer.Name = sequence.Value.Name;

                        Console.WriteLine(string.Format("  {0}", sequence.Value.Name));

                        if (!usedData.ContainsKey(sequence.Value.Name))
                        {
                            usedData.Add(sequence.Value.Name, 1);
                        }
                        else
                        {
                            usedData[sequence.Value.Name]++;
                        }

                        var dataName = usedData[sequence.Value.Name] > 1
                                                                ? string.Format("{0}({1})", sequence.Value.Name.ToLower(), usedData[sequence.Value.Name])
                                                                : sequence.Value.Name.ToLower();

                        // check if sequence uses a list table
                        if (dataBucket.DataTables.ContainsKey(dataName))
                        {
                            var table = dataBucket.DataTables[dataName];
                            foreach (var dataValue in table)
                            {
                                foreach (var command in sequence.Value.Commands)
                                {
                                    var c = new UICommand()
                                    {
                                        CommandName = command.CommandName,
                                        Description = command.Description ?? string.Empty,
                                        Target      = command.Target ?? string.Empty,
                                        Value       = command.Value ?? string.Empty
                                    };
                                    var cmd = PrepareCommand(c, dataValue, uiMap);
                                    Console.WriteLine(string.Format("   {0} {1} {2}",
                                                                    cmd.CommandName,
                                                                    cmd.Target,
                                                                    cmd.Value));

                                    string className = "WebAuto.Commands." + Utility.UppercaseFirst(cmd.CommandName) + "Command";
                                    Type   t         = assembly.GetType(className);
                                    var    cmd2      = (WebAuto.Interfaces.Command)Activator.CreateInstance(t);
                                    cmd2.CommandName = cmd.CommandName;
                                    cmd2.Description = cmd.Description;
                                    cmd2.Target      = cmd.Target;
                                    cmd2.Value       = cmd.Value;

                                    ((ICommand)cmd2).Execute(driver);
                                }
                            }
                        }
                        else
                        {
                            foreach (var command in sequence.Value.Commands)
                            {
                                var c = new UICommand()
                                {
                                    CommandName = command.CommandName,
                                    Description = command.Description ?? string.Empty,
                                    Target      = command.Target ?? string.Empty,
                                    Value       = command.Value ?? string.Empty
                                };
                                var cmd = PrepareCommand(command, dataBucket.DataValues[dataName], uiMap);
                                Console.WriteLine(string.Format("   {0} {1} {2}",
                                                                cmd.CommandName,
                                                                cmd.Target,
                                                                cmd.Value));

                                string className = "WebAuto.Commands." + Utility.UppercaseFirst(cmd.CommandName) + "Command";
                                Type   t         = assembly.GetType(className);
                                var    cmd2      = (WebAuto.Interfaces.Command)Activator.CreateInstance(t);
                                cmd2.CommandName = cmd.CommandName;
                                cmd2.Description = cmd.Description;
                                cmd2.Target      = cmd.Target;
                                cmd2.Value       = cmd.Value;

                                ((ICommand)cmd2).Execute(driver);
                            }
                        }
                    }
                    driver.Close();
                }
            }
            return(result);
        }
Пример #3
0
        public CommandExecutionResult Execute(UITestSuite[] testSuites, WebAutoConfiguration configuration)
        {
            if (!Directory.Exists(configuration.ResultsFolder))
                Directory.CreateDirectory(configuration.ResultsFolder);

            CommandExecutionResult result = new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty };
            Assembly assembly = Assembly.LoadFrom("WebAuto.Commands.dll");

            var uiMap = Repository.GetUIMap(configuration.UIMapFile);
            foreach (var testSuite in testSuites)
            {
                Console.WriteLine(testSuite.Name);
                foreach (var testcase in testSuite)
                {
                    Console.WriteLine(string.Format(" {0}", testcase.Value.GroupName));
                    var dataBucket = Repository.GetData(Path.Combine(configuration.DataDirectory, testcase.Value.GroupName + configuration.FileExtension));

                    IWebDriver driver = null;
                    switch (configuration.Browser)
                    {
                        case "firefox":
                            driver = new FirefoxDriver();
                            break;
                        case "chrome":
                            driver = new ChromeDriver();
                            break;
                        case "ie":
                            driver = new InternetExplorerDriver();
                            break;
                        case "htmlunit":
                            driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript());
                            break;
                        default:
                            driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnit());
                            break;
                    }
                    driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 20));
                    new Utility().ResizeTest(driver);

                    var usedData = new Dictionary<string, int>();
                    foreach (var sequence in testcase.Value.CommandGroups.Sequences)
                    {
                        var commandContainer = new UICommandContainer();
                        commandContainer.Name = sequence.Value.Name;

                        Console.WriteLine(string.Format("  {0}", sequence.Value.Name));

                        if (!usedData.ContainsKey(sequence.Value.Name))
                        {
                            usedData.Add(sequence.Value.Name, 1);
                        }
                        else
                        {
                            usedData[sequence.Value.Name]++;
                        }

                        var dataName = usedData[sequence.Value.Name] > 1
                                       	? string.Format("{0}({1})", sequence.Value.Name.ToLower(), usedData[sequence.Value.Name])
                                       	: sequence.Value.Name.ToLower();

                        // check if sequence uses a list table
                        if (dataBucket.DataTables.ContainsKey(dataName))
                        {
                            var table = dataBucket.DataTables[dataName];
                            foreach (var dataValue in table)
                            {
                                foreach (var command in sequence.Value.Commands)
                                {
                                    var c = new UICommand()
                                    {
                                        CommandName = command.CommandName,
                                        Description = command.Description ?? string.Empty,
                                        Target = command.Target ?? string.Empty,
                                        Value = command.Value ?? string.Empty
                                    };
                                    var cmd = PrepareCommand(c, dataValue, uiMap);
                                    Console.WriteLine(string.Format("   {0} {1} {2}",
                                        cmd.CommandName,
                                        cmd.Target,
                                        cmd.Value));

                                    string className = "WebAuto.Commands." + Utility.UppercaseFirst(cmd.CommandName) + "Command";
                                    Type t = assembly.GetType(className);
                                    var cmd2 = (WebAuto.Interfaces.Command)Activator.CreateInstance(t);
                                    cmd2.CommandName = cmd.CommandName;
                                    cmd2.Description = cmd.Description;
                                    cmd2.Target = cmd.Target;
                                    cmd2.Value = cmd.Value;

                                    ((ICommand) cmd2).Execute(driver);
                                }
                            }
                        }
                        else
                        {
                            foreach (var command in sequence.Value.Commands)
                            {
                                var c = new UICommand()
                                {
                                    CommandName = command.CommandName,
                                    Description = command.Description ?? string.Empty,
                                    Target = command.Target ?? string.Empty,
                                    Value = command.Value ?? string.Empty
                                };
                                var cmd = PrepareCommand(command, dataBucket.DataValues[dataName], uiMap);
                                Console.WriteLine(string.Format("   {0} {1} {2}",
                                        cmd.CommandName,
                                        cmd.Target,
                                        cmd.Value));

                                string className = "WebAuto.Commands." + Utility.UppercaseFirst(cmd.CommandName) + "Command";
                                Type t = assembly.GetType(className);
                                var cmd2 = (WebAuto.Interfaces.Command)Activator.CreateInstance(t);
                                cmd2.CommandName = cmd.CommandName;
                                cmd2.Description = cmd.Description;
                                cmd2.Target = cmd.Target;
                                cmd2.Value = cmd.Value;

                                ((ICommand)cmd2).Execute(driver);
                            }
                        }
                    }
                    driver.Close();
                }
            }
            return result;
        }