예제 #1
0
        /// <summary>
        /// Screen Scrape Events
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        static List<EventDetail> FetchEvents(string query)
        {
            var eventDetails = new List<EventDetail>();
            using (var _browser = new IE("http://www.gettyimages.com", false))
            {
                _browser.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Hide);
                _browser.TextField(Find.ById("txtPhrase")).Clear();
                _browser.TextField(Find.ById("txtPhrase")).TypeText(query);
                var editorialChkfield = _browser.CheckBox(Find.ById("cbxEditorial"));

                if (!editorialChkfield.Checked)
                    editorialChkfield.Click();

                _browser.Button(Find.ById("btnSearch")).Click();

                if (_browser.Link(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_lnkSeeMore")).Exists)
                {
                    _browser.Link(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_lnkSeeMore")).Click();
                    _browser.Div(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_refinementContent")).WaitUntilExists();

                    var filterContentDiv = _browser.Div(Find.ById("ctl00_ctl00_ctl12_gcc_mc_re_flEvent_refinementContent"));

                    foreach (var link in filterContentDiv.Links.Filter(Find.ByClass("refineItem")))
                    {
                        var splitList = link.OuterHtml.Split('\'');

                        if (splitList.Length > 5)
                            eventDetails.Add(new EventDetail() { EventId = int.Parse(splitList[1]), EventName = splitList[5].Trim() });
                    }
                }
            }

            return eventDetails;
        }
예제 #2
0
        private static void RunPageTest(TestSettings settings)
        {
            string url;
            using (var browser = new IE(ConfigurationManager.AppSettings["WebpageTestUrl"]))
            {
                browser.TextField(Find.ById("url")).Value = settings.Url;

                if (!string.IsNullOrEmpty(settings.TestLocation))
                    browser.SelectList(Find.ById("location")).SelectByValue(settings.TestLocation);
                if (!string.IsNullOrEmpty(settings.Browser))
                    browser.SelectList(Find.ById("browser")).SelectByValue(settings.Browser);
                browser.Link(Find.ById("advanced_settings")).ClickNoWait();
                if (!string.IsNullOrEmpty(settings.Speed))
                    browser.SelectList(Find.ById("connection")).SelectByValue(settings.Speed);
                if (settings.IsPrivate)
                    browser.CheckBox(Find.ById("keep_test_private")).Change();

                if (!string.IsNullOrEmpty(settings.Username))
                    browser.TextField(Find.ById("username")).TypeText(settings.Username);
                if (!string.IsNullOrEmpty(settings.Password))
                    browser.TextField(Find.ById("password")).TypeText(settings.Password);

                browser.Button(Find.ByName("submit")).Click();

                browser.WaitUntilContainsText("First View", settings.Timeout);
                if (browser.ContainsText("partially complete"))
                {
                    Thread.Sleep(10000);
                    browser.Refresh();
                }

                browser.WaitUntilContainsText("Raw page data", settings.Timeout);

                url = browser.Link(Find.ByText("Raw page data")).Url;
            }
            var csvRequest = (HttpWebRequest) WebRequest.Create(url);
            csvRequest.Accept = "text/csv";

            var data = new List<PageData>();
            using (var stream = csvRequest.GetResponse().GetResponseStream())
            {
                if (stream != null)
                {
                    using (var reader = new StreamReader(stream))
                    {
                        using (var context = new CsvReader(reader))
                        {
                            while (context.Read())
                            {
                                var counter = data.Count;
                                var item = new PageData();
                                item.EventName = counter == 0 ? "Empty Cache" : "Cached Run " + counter;
                                item.Url = context.GetField<string>(3);
                                item.LoadTime = TimeSpan.FromMilliseconds(context.GetField<int>(4));
                                item.TimeToFirstByte = TimeSpan.FromMilliseconds(context.GetField<int>(5));
                                item.Requests = context.GetField<int>(11);
                                data.Add(item);
                            }
                        }
                    }
                }
            }

            var host = ConfigurationManager.AppSettings["MetricTracking:Host"];
            var port = int.Parse(ConfigurationManager.AppSettings["MetricTracking:Port"]);

            using (var metric = new MetricTracker(host, port))
            {
                foreach (var run in data)
                {
                    Console.WriteLine(run.EventName + "\t" + run.LoadTime);

                    var prefix = settings.Prefix + run.EventName.Replace(" ", string.Empty) + ".";
                    metric.Timing(prefix + "LoadTime", run.LoadTime.TotalMilliseconds);
                    metric.Timing(prefix + "TimeToFirstByte", run.TimeToFirstByte.TotalMilliseconds);
                    metric.Value(prefix + "Requests", run.Requests);
                }
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: friism/Patents
        private static void GetPatentsInYear(int year)
        {
            using (var browser = new IE(resource))
            {
                // go to the search form
                browser.Button(Find.ByName("menu")).ClickNoWait();

                // fill out search form and submit
                browser.CheckBox(Find.ByName("brugsmodel")).Click();
                browser.SelectList(Find.ByName("datotype")).Select("Patent/reg. dato");
                browser.TextField(Find.ByName("dato")).Value = string.Format("{0}*", year);
                browser.Button(Find.By("type", "submit")).ClickNoWait();
                browser.WaitForComplete();

                // go to first patent found in search result and save it
                browser.Buttons.Filter(Find.ByValue("Vis")).First().Click();
                GetPatentFromPage(browser, year);

                // hit the 'next' button until it's no longer there
                while (GetNextPatentButton(browser).Exists)
                {
                    GetNextPatentButton(browser).Click();
                    GetPatentFromPage(browser, year);
                }
            }
        }
예제 #4
0
 public static WatiN.Core.CheckBox GetCheckBox(IE ie, HControl control)
 {
     switch (control.Attribute.ToLower())
     {
         case AttributeType.Id:
             {
                 CheckBox txt = ie.CheckBox(Find.ById(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Name:
             {
                 CheckBox txt = ie.CheckBox(Find.ByName(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Class:
             {
                 CheckBox txt = ie.CheckBox(Find.ByClass(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Text:
             {
                 CheckBox txt = ie.CheckBox(Find.ByText(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         case AttributeType.Value:
             {
                 CheckBox txt = ie.CheckBox(Find.ByValue(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
         default:
             {
                 CheckBox txt = ie.CheckBox(Find.ById(control.Value));
                 if (txt.Exists)
                     return txt;
                 return null;
             }
     }
 }
예제 #5
0
 public static object FindControlInBrowserByID(IE ie, string strID, Enumerators.ControlType ctrl)
 {
     if (ctrl == Enumerators.ControlType.Span)
     {
         Span sp = ie.Span(Find.ById(strID));
         Assert.IsTrue(sp.Exists, "Could not Find: " + strID);
         return sp;
     }
     else if (ctrl == Enumerators.ControlType.Link)
     {
         Link lnk = ie.Link(Find.ById(strID));
         Assert.IsTrue(lnk.Exists, "Could not Find: " + strID);
         return lnk;
     }
     else if (ctrl == Enumerators.ControlType.Frame)
     {
         Frame iFrame = ie.Frame(Find.ById(strID));
         return iFrame;
     }
     else if (ctrl == Enumerators.ControlType.Image)
     {
         Image img = ie.Image(Find.ById(strID));
         Assert.IsTrue(img.Exists, "Could not Find: " + strID);
         return img;
     }
     else if (ctrl == Enumerators.ControlType.TableCell)
     {
         TableCell tCell = ie.TableCell(Find.ById(strID));
         Assert.IsTrue(tCell.Exists, "Could not Find: " + strID);
         return tCell;
     }
     else if (ctrl == Enumerators.ControlType.Table)
     {
         Table tbl = ie.Table(Find.ById(strID));
         Assert.IsTrue(tbl.Exists, "Could not Find: " + strID);
         return tbl;
     }
     else if (ctrl == Enumerators.ControlType.TableRow)
     {
         TableRow row = ie.TableRow(Find.ById(strID));
         Assert.IsTrue(row.Exists, "Could not Find: " + strID);
         return row;
     }
     else if (ctrl == Enumerators.ControlType.CheckBox)
     {
         CheckBox chk = ie.CheckBox(Find.ById(strID));
         Assert.IsTrue(chk.Exists, "Could not Find: " + strID);
         return chk;
     }
     else if (ctrl == Enumerators.ControlType.Button)
     {
         Button btn = ie.Button(Find.ById(strID));
         Assert.IsTrue(btn.Exists, "Could not Find: " + strID);
         return btn;
     }
     else if (ctrl == Enumerators.ControlType.TextField)
     {
         TextField txt = ie.TextField(Find.ById(strID));
         Assert.IsTrue(txt.Exists, "Could not Find: " + strID);
         return txt;
     }
     else if (ctrl == Enumerators.ControlType.SelectList)
     {
         SelectList sList = ie.SelectList(Find.ById(strID));
         Assert.IsTrue(sList.Exists, "Could not Find: " + strID);
         return sList;
     }
     else if (ctrl == Enumerators.ControlType.Div)
     {
         Div division = ie.Div(Find.ById(strID));
         Assert.IsTrue(division.Exists, "Could not Find: " + strID);
         return division;
     }
     else if (ctrl == Enumerators.ControlType.TableRow)
     {
         TableRow tRow = ie.TableRow(Find.ById(strID));
         Assert.IsTrue(tRow.Exists, "Could not Find: " + strID);
         return tRow;
     }
     else if (ctrl == Enumerators.ControlType.FileUpload)
     {
         FileUpload fileUpload = ie.FileUpload(Find.ById(strID));
         Assert.IsTrue(fileUpload.Exists, "Could not find: " + strID);
         return fileUpload;
     }
     else
     {
         return null;
     }
 }
예제 #6
0
        public static object FindControlInBrowserByCustom(IE ie, string strCustomAttribute, string strToFind,
                                                          Enumerators.ControlType ctrl)
        {
            if (ctrl == Enumerators.ControlType.Span)
            {
                Span sp = ie.Span(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(sp.Exists, "Could not Find: " + strToFind);
                return sp;
            }
            else if (ctrl == Enumerators.ControlType.Link)
            {
                Link lnk = ie.Link(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(lnk.Exists, "Could not Find: " + strToFind);
                return lnk;
            }
            else if (ctrl == Enumerators.ControlType.Frame)
            {
                Frame frame = ie.Frame(Find.By(strCustomAttribute, strToFind));
                Assert.AreEqual(frame.Name, strToFind);
                return frame;
            }
            else if (ctrl == Enumerators.ControlType.Image)
            {
                Image img;

                if (strCustomAttribute == "src")
                {
                    img = ie.Image(Find.BySrc(strToFind));
                }
                else
                {
                    img = ie.Image(Find.By(strCustomAttribute, strToFind));
                }
                Assert.IsTrue(img.Exists, "Could not Find: " + strToFind);
                return img;
            }
            else if (ctrl == Enumerators.ControlType.TableCell)
            {
                TableCell tCell = ie.TableCell(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(tCell.Exists, "Could not Find: " + strToFind);
                return tCell;
            }
            else if (ctrl == Enumerators.ControlType.Table)
            {
                Table tbl = ie.Table(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(tbl.Exists, "Could not Find: " + strToFind);
                return tbl;
            }
            else if (ctrl == Enumerators.ControlType.TableRow)
            {
                TableRow row = ie.TableRow(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(row.Exists, "Could not Find: " + strToFind);
                return row;
            }
            else if (ctrl == Enumerators.ControlType.CheckBox)
            {
                CheckBox chk = ie.CheckBox(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(chk.Exists, "Could not Find: " + strToFind);
                return chk;
            }
            else if (ctrl == Enumerators.ControlType.Button)
            {
                Button btn = ie.Button(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(btn.Exists, "Could not Find: " + strToFind);
                return btn;
            }
            else if (ctrl == Enumerators.ControlType.TextField)
            {
                TextField txt = ie.TextField(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(txt.Exists, "Could not Find: " + strToFind);
                return txt;
            }
            else if (ctrl == Enumerators.ControlType.SelectList)
            {
                SelectList sList = ie.SelectList(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(sList.Exists, "Could not Find: " + strToFind);
                return sList;
            }
            else if (ctrl == Enumerators.ControlType.Div)
            {
                Div div = ie.Div(Find.By(strCustomAttribute, strToFind));
                Assert.IsTrue(div.Exists, "Could not Find: " + strToFind);
                return div;
            }
            else
            {
                return null;
            }
        }