Example #1
0
            public static void PerformExpandAndSelectAction(string runtimeId, List <string[]> menuList)
            {
                log.DebugFormat("Executing ExpandAndSelectAction {0}", runtimeId);
                AutomationElement parentElement = SinterUtil.GetAutomationElementFromId(runtimeId, IdType.RuntimeId);

                if (parentElement.TryGetCurrentPattern(ExpandCollapsePatternIdentifiers.Pattern, out object expandCollapsePattern))
                {
                    log.InfoFormat("ExpandAndSelect: expanding {0}", parentElement.Current.Name);
                    try
                    {
                        ((ExpandCollapsePattern)expandCollapsePattern).Expand();
                    }
                    catch (Exception e)
                    {
                        log.Error(e.ToString());
                    }
                }

                foreach (string[] menu in menuList)
                {
                    Condition         propCondition = new PropertyCondition(AutomationElement.NameProperty, menu[0], PropertyConditionFlags.IgnoreCase);
                    AutomationElement targetElement = parentElement.FindFirst(TreeScope.Subtree, propCondition);
                    if (targetElement != null)
                    {
                        PerformDefaultAction(targetElement);
                    }
                    else
                    {
                        log.ErrorFormat("targetElement {0} not found", menu[0]);
                        break;
                    }
                }
            }
Example #2
0
        public bool Render(string xmlfilePattern, Dictionary <string, Entity> dicScraper, Dictionary <string, Entity> dicProxy)
        {
            /* get input xml file and parse it to Sinter object */
            Sinter sinterIn = conn.GetSinterFromFile(resultDir, xmlfilePattern);

            Console.WriteLine(@"Input filename: {0}\*{1}", resultDir, xmlfilePattern);
            Assert.IsTrue(sinterIn != null);

            /* execute the sinter, in this case: ls_l_res */
            bool ret = cmdhlr.CommandExecSinter(sinterIn);

            Assert.IsTrue(ret);

            /* screenshot the render window, save to output folder */
            Bitmap bmp = new Bitmap(proxy.Form.Width, proxy.Form.Height);

            proxy.Form.DrawToBitmap(bmp, new Rectangle(0, 0, proxy.Form.Width, proxy.Form.Height));
            string pngfile = string.Format(@"{0}\{1}.png", TestContext.DeploymentDirectory, TestContext.TestName);

            bmp.Save(pngfile, ImageFormat.Png);
            Console.WriteLine("Output png saved to {0}", pngfile);

            /* create a dummy scraper to scraper our proxy window */
            WindowsScraper.WindowsScraper dummyScraper    = new WindowsScraper.WindowsScraper();
            AutomationElement             renderedElement = SinterUtil.GetAutomationElementFromId(Process.GetCurrentProcess().Id.ToString(), IdType.ProcessId);

            Assert.IsNotNull(renderedElement);
            Entity entityOut = dummyScraper.UIAElement2EntityRecursive(renderedElement);

            /* parse to two dictionay and compare */
            ParseXML(sinterIn.EntityNode, dicScraper, 0);
            ParseXML(entityOut, dicProxy, 0);

            /*
             * foreach (KeyValuePair<string, Entity> kvp in dicScraper)
             * {
             *  Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value.States);
             * }
             * Console.WriteLine("==================================");
             * foreach (KeyValuePair<string, Entity> kvp in dicProxy)
             * {
             *  Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value.States);
             * }
             */

            proxy.dictFormCtrlButtons.Clear(); // this avoid user prompt
            proxy.Form.Close();
            return(true);
        }
Example #3
0
 public void FindStaleElements(ref List <string> keys, AutomationElement parent)
 {
     try
     {
         string runtimeId = SinterUtil.GetRuntimeId(parent, true);
         if (runtimeId != null)
         {
             keys.Remove(runtimeId);
         }
         AutomationElement child = treeWalker.GetFirstChild(parent);
         while (child != null)
         {
             FindStaleElements(ref keys, child);
             child = treeWalker.GetNextSibling(child);
         }
     }
     catch
     {
         //System.Console.WriteLine("@IgnoreExistingElements: " + ex.Message);
     }
 }