Exemplo n.º 1
0
        public string GetXPath(bool bExcludeSessionRootPath)
        {
            if (string.IsNullOrEmpty(this._strPath))
            {
                this._strPath = GenerateXPath.GenerateXPathToUiElement(this, _pathNodes, ref _uiTreeNode).Trim();
            }

            if (string.IsNullOrEmpty(this._strPath))
            {
                return(string.Empty);
            }

            string xPathRet = this._strPath;

            if (bExcludeSessionRootPath == true && string.IsNullOrEmpty(MainWindow.s_mainWin.RootSessionPath) == false)
            {
                int nPos = xPathRet.IndexOf(MainWindow.s_mainWin.RootSessionPath);
                if (nPos >= 0)
                {
                    xPathRet = "\"" + xPathRet.Substring(nPos + MainWindow.s_mainWin.RootSessionPath.Length);
                }
            }

            return(xPathRet);
        }
Exemplo n.º 2
0
        public string GetLastAutomationId()
        {
            this._strPath = GenerateXPath.GetAutomationIdOfUiElement(this, _pathNodes, ref _uiTreeNode).Trim();
            string xPathRet = this._strPath;

            return(xPathRet);
        }
Exemplo n.º 3
0
        public string GetXPath()
        {
            if (_strXPath == null)
            {
                _strXPath = GenerateXPath.GenerateXPathToUiElement(_strXmlNode).Trim();
            }

            return(_strXPath);
        }
Exemplo n.º 4
0
        public static void AddKeyboardInputTask(ref string strBase64, bool bCapsLock, bool bNumLock, bool bScrollLock)
        {
            if (string.IsNullOrEmpty(strBase64))
            {
                AppInsights.LogException("AddKeyboardInputTask", "strBase64 is null");
                return;
            }

            var keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(strBase64, bCapsLock, bNumLock, bScrollLock);

            StringBuilder sb = new StringBuilder();

            foreach (var strLine in keyboardTaskDescription)
            {
                sb.Append(GenerateXPath.XmlEncode(strLine));
            }

            RecordedUiTask lastRecordedUi = null;

            lock (RecordedUiTask.s_lockRecordedUi)
            {
                if (RecordedUiTask.s_listRecordedUi.Count > 0)
                {
                    lastRecordedUi = RecordedUiTask.s_listRecordedUi.Last();
                }
            }

            if (lastRecordedUi != null && lastRecordedUi.UiTaskName == EnumUiTaskName.KeyboardInput)
            {
                lastRecordedUi.AppendKeyboardInput(strBase64);
            }
            else
            {
                var keyboarTask = new RecordedUiTask(EnumUiTaskName.KeyboardInput, strBase64, bCapsLock, bScrollLock, bNumLock);
                MainWindow.AddRecordedUi(keyboarTask);
            }

            strBase64 = null;
        }
Exemplo n.º 5
0
        public static IntPtr ProcessMessage(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            handled = false;
            string left, top;

            if (msg == (int)UiTaskName.Inspect)
            {
                var nodesRootToLeaf = GetRootToLeafNodes(strUiToRootXmlNodesInspect, out left, out top);
                if (nodesRootToLeaf != null)
                {
                    string strXmlNodes = CreateUiTaskXmlNodeString(nodesRootToLeaf, ((UiTaskName)msg).ToString(), left, top);
                    if (string.IsNullOrEmpty(strXmlNodes) == false)
                    {
                        MainWindow.AddRecordedUi(new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg));
                    }
                }
                return(IntPtr.Zero);
            }

            if (MainWindow.IsRecording() == false)
            {
                return(IntPtr.Zero);
            }

            lock (lockUiPath)
            {
                if (msg == (int)UiTaskName.KeyboardInput)
                {
                    var           keyboardTaskDescription = GenerateCSCode.GetDecodedKeyboardInput(strBase64KeyboardInput, bCapsLock, bNumLock, bScrollLock);
                    StringBuilder sb = new StringBuilder();
                    foreach (var strLine in keyboardTaskDescription)
                    {
                        sb.Append(GenerateXPath.XmlEncode(strLine));
                    }

                    var keyboarTask = new RecordedUiTask($"<UiTask task=\"{UiTaskName.KeyboardInput}\" VirtualKeys=\"{sb.ToString()}\" base64String=\"{strBase64KeyboardInput}\" CapsLock=\"{bCapsLock}\" NumLock=\"{bNumLock}\" ScrollLock=\"{bScrollLock}\"/>\n", (int)wParam, (UiTaskName)msg);
                    MainWindow.AddRecordedUi(keyboarTask);
                }
                else if ((int)UiTaskName.LeftClick <= msg && msg <= (int)UiTaskName.MouseHover)
                {
                    RecordedUiTask lastRecordedUi = null;
                    if (MainWindow.s_listRecordedUi.Count > 0)
                    {
                        lastRecordedUi = MainWindow.s_listRecordedUi.Last();
                    }

                    string        strXmlNodes     = null;
                    List <string> nodesRootToLeaf = GetRootToLeafNodes(strUiToRootXmlNodes, out left, out top);
                    if (nodesRootToLeaf != null && nodesRootToLeaf.Count > 1)
                    {
                        strXmlNodes = CreateUiTaskXmlNodeString(nodesRootToLeaf, ((UiTaskName)msg).ToString(), left, top);
                    }

                    bool bAddNewTask = true;

                    // Completing last UI
                    if (msg == (int)UiTaskName.LeftDblClick && lastRecordedUi != null)
                    {
                        lastRecordedUi.ChangeClickToDoubleClick();
                        bAddNewTask = false;
                    }
                    else if (msg == (int)UiTaskName.DragStop && lastRecordedUi != null)
                    {
                        int deltaX = wParam.ToInt32() - ConstVariables.DragDeltaOffset;
                        int deltaY = lParam.ToInt32() - ConstVariables.DragDeltaOffset;
                        lastRecordedUi.DragComplete(deltaX, deltaY);
                        bAddNewTask = false;
                    }
                    else if (msg == (int)UiTaskName.MouseWheel)
                    {
                        int delta = wParam.ToInt32() - ConstVariables.DragDeltaOffset;

                        if (strXmlNodes != null)
                        {
                            if (lastRecordedUi == null || lastRecordedUi.GetTask() != UiTaskName.MouseWheel)
                            {
                                lastRecordedUi = new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg);
                                MainWindow.AddRecordedUi(lastRecordedUi);
                            }
                        }

                        if (lastRecordedUi != null && lastRecordedUi.GetTask() == UiTaskName.MouseWheel)
                        {
                            lastRecordedUi.UpdateWheelData(delta);
                        }

                        bAddNewTask = false;
                    }

                    // Adding newly recorded UI
                    if (bAddNewTask)
                    {
                        MainWindow.AddRecordedUi(new RecordedUiTask(strXmlNodes, 0, (UiTaskName)msg));
                    }
                    else
                    {
                        MainWindow.UpdateLastUi(lastRecordedUi);
                    }
                }

                return(IntPtr.Zero);
            }
        }