Example #1
0
    public DesktopRequest(int cmdType, int cmdSubType, string[] cmdData, ActionKeyboard keyboard, VisualRecorder recorder, DesktopData[] capabilities, DesktopManager desktop, bool keyDown = false)
    {
        CommandType type = (CommandType)cmdType;

        if (type == CommandType.Driver)
        {
            execution = new DriverExecution(cmdSubType, cmdData, capabilities, desktop);
        }
        else if (type == CommandType.Mouse)
        {
            execution = new MouseExecution(cmdSubType, cmdData, desktop);
        }
        else if (type == CommandType.Keyboard)
        {
            execution = new KeyboardExecution(cmdSubType, cmdData, keyboard, keyDown);
        }
        else if (type == CommandType.Window)
        {
            execution = new WindowExecution((WindowType)cmdSubType, cmdData, keyboard, recorder, desktop);
        }
        else if (type == CommandType.Record)
        {
            execution = new RecordExecution(cmdSubType, cmdData, recorder);
        }
        else if (type == CommandType.Element)
        {
            execution = new ElementExecution(cmdSubType, cmdData, desktop);
        }
        else
        {
            execution = new AtsExecution(errorCode, true, errorMessage);
        }
    }
Example #2
0
    public KeyboardExecution(int type, string[] commandsData, ActionKeyboard action, bool keyDown) : base()
    {
        this.action  = action;
        this.type    = (KeyType)type;
        this.keyDown = keyDown;

        if (commandsData.Length > 0)
        {
            data = commandsData[0];
        }
        if (commandsData.Length > 1 && commandsData[1] != "")
        {
            id = commandsData[1];
        }
    }
Example #3
0
    public WindowExecution(WindowType type, string[] commandsData, ActionKeyboard keyboard, VisualRecorder recorder, DesktopManager desktop) : base()
    {
        DesktopWindow window = null;

        if (type == WindowType.Close || type == WindowType.Handle || type == WindowType.State || type == WindowType.Keys)
        {
            _      = int.TryParse(commandsData[0], out int handle);
            window = desktop.GetWindowByHandle(handle);
            if (window != null)
            {
                if (type == WindowType.State)
                {
                    executor = new StateExecutor(window, response, commandsData[1]);
                }
                else if (type == WindowType.Keys)
                {
                    executor = new KeysExecutor(window, response, keyboard, commandsData[1]);
                }
                else if (type == WindowType.Close)
                {
                    executor = new CloseExecutor(window, response);
                }
                else if (type == WindowType.Handle)
                {
                    executor = new HandleExecutor(window, response);
                }
            }
        }
        else if (type == WindowType.ToFront)
        {
            if (commandsData.Length > 1)
            {
                _ = int.TryParse(commandsData[0], out int handle);
                _ = int.TryParse(commandsData[1], out int pid);

                window = desktop.GetWindowByHandle(handle);

                if (window == null)
                {
                    window = desktop.GetWindowIndexByPid(pid, 0);
                }

                recorder.CurrentPid = pid;
            }
            else
            {
                _ = int.TryParse(commandsData[0], out int pid);
                recorder.CurrentPid = pid;

                List <DesktopWindow> windows = desktop.GetOrderedWindowsByPid(pid);
                if (windows.Count > 0)
                {
                    window = windows[0];
                }
            }

            if (window != null)
            {
                window.ToFront();
            }
        }
        else if (type == WindowType.Url)
        {
            _      = int.TryParse(commandsData[0], out int handle);
            window = desktop.GetWindowByHandle(handle);

            if (window.isIE)
            {
                window.ToFront();

                AutomationElement win        = window.Element;
                AutomationElement addressBar = win.FindFirst(TreeScope.Descendants, win.ConditionFactory.ByControlType(ControlType.Pane).And(win.ConditionFactory.ByClassName("Address Band Root")));
                if (addressBar != null)
                {
                    addressBar.Focus();
                    AutomationElement edit = addressBar.FindFirstChild(addressBar.ConditionFactory.ByControlType(ControlType.Edit));

                    if (edit != null)
                    {
                        try
                        {
                            edit.Focus();
                            edit.Click();
                            if (edit.Patterns.Value.IsSupported)
                            {
                                edit.Patterns.Value.Pattern.SetValue(commandsData[1]);
                            }
                            Keyboard.Type(VirtualKeyShort.ENTER);
                        }
                        catch { }
                    }
                }
            }
            else
            {
                string fname = Environment.ExpandEnvironmentVariables(commandsData[1]);
                if (fname.StartsWith("file:///"))
                {
                    fname = fname.Substring(8);
                }

                try
                {
                    if (Directory.Exists(@fname))
                    {
                        window.ToFront();
                        keyboard.AddressBar(Path.GetFullPath(@fname));
                    }
                    else
                    {
                        response.SetError(UNREACHABLE_GOTO_URL, "directory not found : " + fname);
                    }
                }
                catch (Exception e)
                {
                    response.SetError(UNREACHABLE_GOTO_URL, "directory path not valid : " + fname + " (" + e.Message + ")");
                }
            }
        }
        else if (type == WindowType.Title)
        {
            if (commandsData[0].Equals("jx"))
            {
                window = desktop.GetJxWindowPid(commandsData[1]);
            }
            else
            {
                window = desktop.GetWindowByTitle(commandsData[0]);
            }
        }
        else if (type == WindowType.List)
        {
            _        = int.TryParse(commandsData[0], out int pid);
            executor = new ListExecutor(window, response, desktop.GetOrderedWindowsByPid(pid).ToArray());
        }
        else if (type == WindowType.Switch)
        {
            if (commandsData.Length > 1)
            {
                _      = int.TryParse(commandsData[0], out int pid);
                _      = int.TryParse(commandsData[1], out int index);
                window = desktop.GetWindowIndexByPid(pid, index);

                if (window == null)
                {
                    _      = int.TryParse(commandsData[2], out int handle);
                    window = desktop.GetWindowByHandle(handle);
                }
            }
            else
            {
                _      = int.TryParse(commandsData[0], out int handle);
                window = desktop.GetWindowByHandle(handle);
            }

            if (window != null)
            {
                window.ToFront();
            }
        }
        else if (type == WindowType.Move || type == WindowType.Resize)
        {
            _ = int.TryParse(commandsData[0], out int handle);
            _ = int.TryParse(commandsData[1], out int value1);
            _ = int.TryParse(commandsData[2], out int value2);

            window = desktop.GetWindowByHandle(handle);
            if (window != null)
            {
                if (type == WindowType.Move)
                {
                    executor = new MoveExecutor(window, response, value1, value2);
                }
                else
                {
                    executor = new ResizeExecutor(window, response, value1, value2);
                }
            }
        }

        if (executor == null)
        {
            executor = new EmptyExecutor(window, response);
        }
    }
Example #4
0
 public void Dispose()
 {
     keyboard = null;
     keys     = null;
 }
Example #5
0
 public KeysExecutor(DesktopWindow window, DesktopResponse response, ActionKeyboard keyboard, string keys) : base(window, response)
 {
     this.keyboard = keyboard;
     this.keys     = keys;
 }