Example #1
0
        private void GetScreen()
        {
            RegisterLog("[Get Screen] Trying...");

            MyNode.TpGUIScreenshot guiScreenshot = new MyNode.TpGUIScreenshot();

            try
            {
                Screenshot   screenshot = ((ITakesScreenshot)_driver).GetScreenshot();
                MemoryStream ms         = new MemoryStream(screenshot.AsByteArray);
                guiScreenshot.Screenshot = Image.FromStream(ms);
                guiScreenshot.Width      = _driver.Manage().Window.Size.Width;
                guiScreenshot.Height     = _driver.Manage().Window.Size.Height;

                RegisterLog("[Get Screen] Finish");
            }
            catch (Exception ex)
            {
                RegisterLog("[Get Screen] Error - " + ex.Message);
            }

            RegisterLog("[Check compatibility] Trying...");



            try
            {
                XDocument xml = XDocument.Parse(_driver.PageSource);

                _nodes.Clear();

                List <XElement> nodes = (from n in xml.Descendants() select n).Distinct().ToList();

                int i = 1;

                foreach (XElement item in nodes)
                {
                    MyNode node = new MyNode();
                    node.Platform      = (rbServer1PlatAndroid.Checked ? rbServer1PlatAndroid.Text : rbServer1PlatIOS.Text);
                    node.Element       = item;
                    node.XMLDoc        = xml.ToString();
                    node.GUIScreenshot = guiScreenshot;

                    node.ElementXPathAbsoluteSelector = Support.XMLUtils.GetXPath(item);
                    node.ElementType = item.Name.LocalName;

                    node.KeyAttributes = new Dictionary <string, string>();

                    string[] attrsName;

                    if (rbServer1PlatAndroid.Checked)
                    {
                        attrsName = MyNode.AndroidKeyAttributes;
                    }
                    else
                    {
                        attrsName = MyNode.IOSKeyAttributes;
                    }

                    foreach (string attrName in attrsName)
                    {
                        if (item.Attribute(attrName) != null && item.Attribute(attrName).Value != "")
                        {
                            node.KeyAttributes.Add(attrName, item.Attribute(attrName).Value);
                        }
                    }



                    ////xxxxxxxxxxxxxxxxxxxx.....
                    //List<string> xPathAttrs = new List<string>();
                    //foreach (var attr in node.KeyAttributes)
                    //{
                    //    xPathAttrs.Add("@" + attr.Key + "='" + attr.Value + "'");
                    //}

                    //node.ElementXPathSelectors = new List<string>();
                    //if (node.KeyAttributes.Count > 0)
                    //{
                    //    //based type and key attributes
                    //    string aux = "//*/" + node.ElementType;
                    //    if (xPathAttrs.Count > 0)
                    //    {
                    //        aux += "[" + string.Join(" and ", xPathAttrs.ToArray()) + "]";
                    //    }
                    //    node.ElementXPathSelectors.Add(aux);


                    //   //based only key attributes
                    //   if (xPathAttrs.Count > 0)
                    //    node.ElementXPathSelectors.Add("//*[" + string.Join(" and ", xPathAttrs.ToArray()) + "]");
                    //}



                    float x, y, w, h;
                    MyNode.ExtractElementDimension(node, out x, out y, out w, out h);
                    node.ElementPositionX = x;
                    node.ElementPositionY = y;
                    node.ElementWidth     = w;
                    node.ElementHeight    = h;

                    // MyNode.ExtractSelectors(node, null);

                    _nodes.Add(node);
                    i++;
                }


                dgNodes.DataSource = _nodes.Select(o => new { Element = o.Element }).ToList();

                dgNodes.Refresh();

                RegisterLog("[Check compatibility] Finish");
            }
            catch (Exception ex)
            {
                RegisterLog("[Check compatibility] Error - " + ex.Message);
            }
        }