Exemplo n.º 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);
            }
        }
Exemplo n.º 2
0
        private void RunTest(MyNode n, DeviceConfig deviceConfig)
        {
            IWebElement element = null;

            #region update screenshot
            MyNode.TpGUIScreenshot guiScreenshot = new MyNode.TpGUIScreenshot();

            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;

            n.GUIScreenshot = guiScreenshot;
            #endregion

            DateTime timeStart = DateTime.Now;

            if (n.WaitElementBySecond > 0)
            {
                System.Threading.Thread.Sleep(n.WaitElementBySecond * 1000);
            }

            List <XPathSelector> xpaths = new List <XPathSelector>();

            xpaths = MyNode.ExtractSelectors(n);


            xpaths = MyNode.OrderBySelectorInOrder(xpaths);

            foreach (XPathSelector selector in xpaths)
            {
                //if (selector.Type != XPathSelector.XPathType.AncestorIndex)
                //    continue;

                try
                {
                    if (n.Platform == "Android" && selector.XPathForAndroid != "")
                    {
                        element = _driver.FindElementByXPath(selector.XPathForAndroid);
                    }
                    else if (n.Platform == "iOS" && selector.XPathForIOS != "")
                    {
                        element = _driver.FindElementByXPath(selector.XPathForIOS);
                    }
                }
                catch
                {
                    continue;
                }

                if (element != null)
                {
                    break;
                }
            }


            if (element != null)
            {
                try
                {
                    if (n.SendClick)
                    {
                        element.Click();
                    }
                    else if (n.SendKeys)
                    {
                        element.Click();
                        element.Clear();
                        element.SendKeys(n.SendKeysText);

                        if (n.Platform == "Android")
                        {
                            _driver.HideKeyboard();
                        }
                        else if (n.Platform == "iOS")
                        {
                            _driver.FindElementByXPath("//*[@name='Hide keyboard']").Click();
                        }
                    }
                }
                catch (Exception ex)
                {
                    RegisterLog("[Run Test] Error - " + ex.Message);
                }

                TimeSpan ts = DateTime.Now.Subtract(timeStart);


                #region Extract status of executation

                //Screenshot screenshotExec = ((ITakesScreenshot)_driver).GetScreenshot();
                //MemoryStream msExec = new MemoryStream(screenshotExec.AsByteArray);

                //MyNode.TpGUIScreenshot guiScreenshotExec = new MyNode.TpGUIScreenshot()
                //{
                //    Screenshot = Image.FromStream(msExec),
                //    Width = _driver.Manage().Window.Size.Width,
                //    Height = _driver.Manage().Window.Size.Height
                //};

                //XDocument xml = XDocument.Parse(_driver.PageSource);

                //n.ExecutationState = new MyNode.TpExecutationState()
                //{
                //    Executed = true,
                //    GUIScreenshot = guiScreenshotExec,
                //    Xml = xml,
                //    Runtime = ts.TotalSeconds
                //};

                #region Reprocess RunTime total for all nodes/events

                double runTimeTotal = 0;
                foreach (MyNode nAux in deviceConfig.Events)
                {
                    runTimeTotal += nAux.ExecutationState.Runtime;
                }

                //update RuntimePercent
                foreach (MyNode nAux in deviceConfig.Events)
                {
                    nAux.ExecutationState.RuntimePercent = (100 * nAux.ExecutationState.Runtime) / runTimeTotal;
                }


                #endregion


                #endregion
            }
        }