コード例 #1
0
ファイル: Open.cs プロジェクト: Genyus/FluentAutomation
        public void Execute(CommandManager manager, IRemoteCommandArguments arguments)
        {
            var args = (OpenArguments)arguments;
            Guard.ArgumentNotNullForCommand<ExpectValue>(args.Url);

            manager.Open(args.Url);
        }
コード例 #2
0
ファイル: Click.cs プロジェクト: Genyus/FluentAutomation
        public void Execute(CommandManager manager, IRemoteCommandArguments arguments)
        {
            var args = (ClickArguments)arguments;

            if (args.Selector != null && args.ClickMode != null && args.MatchConditions != null)
            {
                manager.Click(args.Selector, args.ClickMode.Value, args.MatchConditions.Value);
            }
            else if (args.Selector != null && args.ClickMode != null)
            {
                manager.Click(args.Selector, args.ClickMode.Value);
            }
            else if (args.Selector != null && args.Point == null)
            {
                manager.Click(args.Selector);
            }
            else if (args.Selector != null && args.Point != null)
            {
                manager.Click(args.Selector, args.Point);
            }
            else if (args.Point != null)
            {
                manager.Click(args.Point);
            }
            else
            {
                throw new InvalidCommandException<Click>();
            }
        }
コード例 #3
0
        public void Execute(AutomationProvider provider, IEnumerable<RemoteCommandDetails> commands)
        {
            CommandManager manager = new CommandManager(provider);
            Assembly asm = typeof(RemoteCommandManager).Assembly;

            try
            {
                // force remote execution to false, don't want loops of RemoteCommands!
                manager.EnableRemoteExecution = false;
                manager.Record();

                var browserList = new List<BrowserType>();

                foreach (var command in commands)
                {
                    // attempt to locate mapper
                    // TODO: Get rid of the 'magic string' Commands part, make this work with loaded assemblies
                    var type = asm.GetType(string.Format("{0}.{1}.{2}", typeof(RemoteCommandManager).Namespace, "Commands", command.Name));
                    if (type == null)
                    {
                        throw new ArgumentException(string.Format("Unable to locate available command: {0}", command.Name));
                    }

                    CommandArgumentsTypeAttribute commandArgs = (CommandArgumentsTypeAttribute)type.GetCustomAttributes(typeof(CommandArgumentsTypeAttribute), false).FirstOrDefault();
                    if (commandArgs == null)
                    {
                        provider.Cleanup();
                        throw new ArgumentException(string.Format("Unable to locate command arguments handler for command: {0}", command.Name));
                    }

                    IRemoteCommand cmd = (IRemoteCommand)Activator.CreateInstance(type);

                    IRemoteCommandArguments args = null;
                    try
                    {
                        args = DeserializeArguments(commandArgs.ArgsType, command.Arguments);
                    }
                    catch (Exception ex)
                    {
                        throw new ArgumentException(string.Format("An error occurred while processing the arguments provided for command: {0}", command.Name), ex);
                    }

                    if (cmd.GetType() == typeof(Commands.Use))
                    {
                        var useArgs = (Commands.UseArguments)args;
                        Guard.ArgumentExpressionTrueForCommand<Commands.Use>(() => useArgs.BrowserType.Count > 0);

                        browserList.AddRange(useArgs.BrowserType);
                    }
                    else
                    {
                        cmd.Execute(manager, args);
                    }
                }

                if (browserList.Count == 0)
                {
                    browserList.Add(BrowserType.Chrome);
                }

                manager.Execute(browserList.ToArray());
            }
            catch (FluentAutomation.API.Exceptions.AssertException)
            {
                throw;
            }
            catch (ArgumentException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new Exception("An error occurred while executing the specified commands.", ex);
            }
            finally
            {
                provider.Cleanup();
            }
        }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ExpectManager"/> class.
 /// </summary>
 /// <param name="automation">The automation.</param>
 public ExpectManager(AutomationProvider automation, CommandManager manager)
 {
     Provider = automation;
     Manager = manager;
 }
コード例 #5
0
        public TestViewModel()
        {
            MessengerInstance.Register<GenericMessage<TestDetails>>(this, (test) =>
            {
                DispatcherHelper.CheckBeginInvokeOnUI(() =>
                {
                    // only handle one test at a time!
                    if (this.RemoteCommands.Count == 0)
                    {
                        this.Browsers = new ObservableCollection<BrowserType>(test.Content.Browsers);
                        foreach (var commandItem in test.Content.RemoteCommands)
                        {
                            this.RemoteCommands.Add(new RemoteCommandViewModel
                            {
                                CommandName = commandItem.Key.GetType().Name,
                                RemoteCommand = commandItem.Key,
                                RemoteCommandArguments = commandItem.Value
                            });
                        }

                        this.Name = "Received at " + DateTime.Now.ToLongTimeString();
                        this.ExecuteButtonVisibility = this.RemoteCommands.Count == 0 ? Visibility.Collapsed : Visibility.Visible;

                        // new test class so we can grab the proper provider
                        FluentTest testClass = new FluentTest();
                        this._manager = testClass.I;
                        if (this.Browsers.Count > 0)
                        {
                            var selectedBrowser = this.Browsers[0];

                            if (selectedBrowser == BrowserType.InternetExplorer)
                                this._requiresSTA = true;

                            this._manager.Use(this.Browsers[0]);
                        }

                        if (testClass.ProviderName.Contains("WatiN"))
                        {
                            this._requiresSTA = true;
                        }
                    }
                });
            });
        }
コード例 #6
0
        private void STAExecuteCommands(ObservableCollection<RemoteCommandViewModel> remoteCommands, CommandManager manager)
        {
            bool hitBreakpoint = false;

            foreach (var cmd in this.RemoteCommands)
            {
                if (cmd.IsBreakpoint)
                {
                    hitBreakpoint = true;
                    this.ContinueButtonVisibility = Visibility.Visible;

                    break;
                }

                if (cmd.Status == "Executed")
                {
                    continue;
                }

                try
                {
                    cmd.RemoteCommand.Execute(manager, cmd.RemoteCommandArguments);
                    cmd.Status = "Executed";
                }
                catch (Exception ex)
                {
                    cmd.Status = "Error";
                }
            }

            if (!hitBreakpoint)
            {
                manager.Finish();
                this.ExecuteButtonVisibility = Visibility.Visible;
            }
        }
コード例 #7
0
 public CommandBase(AutomationProvider provider, CommandManager manager)
 {
     Provider = provider;
     CommandManager = manager;
 }