Example #1
0
        public static void UpdateLastUi(RecordedUiTask uiTask)
        {
            s_mainWin.Dispatcher.Invoke(new Action(() =>
            {
                TextRange tr = new TextRange(s_mainWin.rtbXPath.Document.ContentStart, s_mainWin.rtbXPath.Document.ContentEnd);
                tr.Text      = uiTask.GetXPath();

                s_mainWin.textBoxXml.Text = uiTask.GetXml();

                s_mainWin.textBoxCode.Text = "";
            }), System.Windows.Threading.DispatcherPriority.ContextIdle);
        }
        public static void AddToUiTree(RecordedUiTask recordedUi)
        {
            if (recordedUi.GetUiTreeNode() == null)
            {
                if (string.IsNullOrEmpty(recordedUi.GetXPath(false)))
                {
                    return;
                }
            }

            var uiNode = recordedUi.GetUiTreeNode();

            if (uiNode == null || uiNode.Items.Count == 0)
            {
                //Log error
                return;
            }

            // Empty root
            if (s_uiTreeNodes.Count == 0)
            {
                s_uiTreeNodes.Add(uiNode);
                return;
            }

            // Add uiNode to s_uiNode
            UiTreeNode        node       = uiNode;
            UiTreeNode        nodeCached = null;
            List <UiTreeNode> listCached = s_uiTreeNodes;

            while (node != null)
            {
                var nodeAddTo = FindInCachedUiTree(node, listCached);

                if (node.Items.Count > 0 && nodeAddTo != null)
                {
                    node       = node.Items.First();
                    listCached = nodeAddTo.Items;
                    nodeCached = nodeAddTo;
                }
                else
                {
                    if (nodeCached != null)
                    {
                        node.Parent = nodeCached;
                        nodeCached.Items.Add(node);
                    }
                    break;
                }
            }
        }
Example #3
0
        private void EditAttribute_Click(object sender, RoutedEventArgs e)
        {
            AppInsights.LogEvent("EditAttribute_Click");

            var uiTreeNode = treeUiPath.SelectedItem as UiTreeNode;

            if (uiTreeNode == null)
            {
                return;
            }

            RecordedUiTask leafUiTask = uiTreeNode.UiTask;

            if (leafUiTask == null)
            {
                if (treeUiPath.Items != null && treeUiPath.Items.Count > 0)
                {
                    var x = (TreeViewItem)treeUiPath.ItemContainerGenerator.ContainerFromItem(treeUiPath.Items[0]);
                    if (x != null)
                    {
                        TreeViewItem tvi = UiTreeNode2TreeViewItem(x, UiTreeNode.s_uiTreeNodes.First(), uiTreeNode);
                        if (tvi != null)
                        {
                            leafUiTask = GetExpandedLeafNode(tvi, uiTreeNode, selectedTreeViewItem);
                            if (leafUiTask == null)
                            {
                                leafUiTask           = GetExpandedLeafNode(tvi, uiTreeNode, null);
                                selectedTreeViewItem = leafUiTask;
                            }
                        }
                    }
                }
            }

            if (leafUiTask == null)
            {
                return;
            }

            string oldNodePath = uiTreeNode.NodePath;

            var winEditAttr = new WindowEditNodeAttribute(uiTreeNode);

            if (true == winEditAttr.ShowDialog())
            {
                var xpath = leafUiTask.GetXPath(false).Replace(oldNodePath, uiTreeNode.NodePath);
                var tr    = new TextRange(rtbXPath.Document.ContentStart, rtbXPath.Document.ContentEnd);
                tr.Text = leafUiTask.UpdateXPath(xpath);
            }
        }
Example #4
0
 public static string MouseHover(RecordedUiTask uiTask, int nOrder)
 {
     return($"string xp{nOrder} = {uiTask.GetXPath()};\n" +
            $"var winElem{nOrder} = MyDesktopSession.FindElementByXPath(xp{nOrder});\n" +
            $"if (winElem{nOrder} != null)\n" +
            "{\n" +
            $"   //TODO: Hover at ({uiTask.GetLeft()},{uiTask.GetTop()}) on winElem{nOrder}\n" +
            "}\n" +
            "else\n" +
            "{\n" +
            "    Console.WriteLine($\"Failed to find element {xp" + $"{nOrder}" + "}\");\n" +
            "    return;\n" +
            "}\n");
 }
Example #5
0
 public static string LeftClick(RecordedUiTask uiTask, int nOrder)
 {
     return($"string xp{nOrder} = {uiTask.GetXPath()};\n" +
            $"var winElem{nOrder} = MyDesktopSession.FindElementByXPath(xp{nOrder});\n" +
            $"if (winElem{nOrder} != null)\n" +
            "{\n" +
            $"    winElem{nOrder}.Click();\n" +
            "}\n" +
            "else\n" +
            "{\n" +
            "    Console.WriteLine($\"Failed to find element {xp" + $"{nOrder}" + "}\");\n" +
            "    return;\n" +
            "}\n");
 }
Example #6
0
 public static string RightClick(RecordedUiTask uiTask, int nOrder)
 {
     return($"string xp{nOrder} = {uiTask.GetXPath()};\n" +
            $"var winElem{nOrder} = MyDesktopSession.FindElementByXPath(xp{nOrder});\n" +
            $"if (winElem{nOrder} != null)\n" +
            "{\n" +
            $"    MyDesktopSession.DesktopSession.Mouse.MouseMove(winElem{nOrder}.Coordinates);\n" +
            "    MyDesktopSession.DesktopSession.Mouse.ContextClick(null);\n" +
            "}\n" +
            "else\n" +
            "{\n" +
            "    Console.WriteLine($\"Failed to find element {xp" + $"{nOrder}" + "}\");\n" +
            "    return;\n" +
            "}\n");
 }
Example #7
0
        public static string GetCodeBlock(RecordedUiTask uiTask, string elemName, string uiActionLine)
        {
            var xpath = "xpath_" + elemName;

            elemName = "winElem_" + elemName;

            string codeBlock = $"string {xpath} = {uiTask.GetXPath(true)};\n" +
                               $"var {elemName} = desktopSession.FindElementByAbsoluteXPath({xpath});\n" +
                               $"if ({elemName} != null)\n" +
                               "{\n" +
                               "CODEBLOCK" +
                               "}\n" +
                               "else\n" +
                               "{\n" +
                               "    Console.WriteLine($\"Failed to find element using xpath: {" + $"{xpath}" + "}\");\n" +
                               "    return;\n" +
                               "}\n";

            return(codeBlock.Replace("CODEBLOCK", uiActionLine));
        }