Example #1
0
        private static Counter FindCounter(IWebDriver driver, string counter)
        {
            var counterSearch     = counter.ToLower();
            var section           = driver.FindElement(By.Id("metricCharts"));/*
                                                                               * var loading = section.FindElements(By.XPath("//img[@src='Content/images/loader.gif']"));
                                                                               * if(loading!=null && loading.Count>0)
                                                                               * {
                                                                               * Refresh(driver);
                                                                               * Thread.Sleep(TimeSpan.FromSeconds(15));
                                                                               * loading = section.FindElements(By.XPath("//img[@src='Content/images/loader.gif']"));
                                                                               * }*/
            var             tds   = section.FindElements(By.ClassName("data-table-caption"));
            var             list  = new List <CounterInstance>();
            CounterInstance total = null;
            var             found = false;

            foreach (var td in tds)
            {
                var spans = td.FindElements(By.TagName("span"));
                foreach (var span in spans)
                {
                    var text = span.Text.ToLower();
                    if (text.StartsWith(counterSearch))
                    {
                        Logger.Border();
                        Logger.Debug("Counter {0} found", counter);
                        Logger.Border();
                        //var table = span.FindElement(By.XPath("//parent::tbody"));
                        //var dataTable = table.FindElement(By.XPath("//tr/td/table[@class='data-table']"));

                        //var parentTR = span.FindElement(By.XPath("//parent::tr"));
                        //var dataTables = parentTR.FindElements(By.XPath("//td/table[@class='data-table']"));


                        var parent = span.FindElement(By.XPath(".."));
                        while (parent.TagName != "tbody")
                        {
                            parent = parent.FindElement(By.XPath(".."));
                        }

                        //var nexTR = parent.FindElement(By.XPath("//following-sibling::tr"));
                        var others = parent.FindElements(By.XPath("./tr"));
                        if (others.Count != 2)
                        {
                            throw new InvalidOperationException();
                        }
                        var nextTR    = others[1];
                        var container = nextTR.FindElement(By.XPath("./td[@class='container']"));
                        var dataTable = container.FindElement(By.XPath("./table[@class='data-table']"));

                        /*
                         * if (dataTables != null)
                         * {
                         *  if (dataTables.Count == 1)
                         *  {
                         *      var dataTable = dataTables[0];*/
                        //var btn = dataTable.FindElement(By.TagName("button"));
                        //        btn.Click();
                        //dataTable = table.FindElement(By.XPath("//tr/td/table[@class='data-table']"));
                        var rows = dataTable.FindElements(By.TagName("tr"));
                        //var rows = dataTable.FindElements(By.ClassName("data-row"));
                        //var rows = dataTable.FindElements(By.XPath("//tbody/tr[@class='data-row']"));
                        for (int j = 1; j < rows.Count; j++)
                        {
                            var row     = rows[j];
                            var cells   = row.FindElements(By.TagName("td"));
                            var count   = double.Parse(cells[2].Text);
                            var average = double.Parse(cells[4].Text);
                            var inst    = new CounterInstance(count, average);
                            if (j < rows.Count - 1)
                            {
                                list.Add(inst);
                            }
                            else
                            {
                                total = inst;
                            }
                        }

                        /*}
                         * }
                         * else
                         * {
                         * throw new InvalidOperationException(string.Format("Error: Can't access data grid for counter {0}", counter));
                         * }*/
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }
            if (!found)
            {
                throw new InvalidOperationException(string.Format("Error: Unable to find counter '{0}'", counter));
            }
            return(new Counter()
            {
                Instances = list, Total = total
            });
        }
Example #2
0
        private static double ZScore(CounterInstance ca, Result result)
        {
            var diff = ca.Average - result.Average;

            return(diff / result.StandardDeviation);
        }