Esempio n. 1
0
        static void Main(string[] args)
        {
            FirefoxDriver driver = new FirefoxDriver();
            //напрямую в гугл не пробиться - осядем на вводе капчи изза подозрительной деятельности
            //потому пойдем через яндекс
            driver.Url = "https://ya.ru";
            
            //ищем гугл
            driver.FindElementByXPath("//*[@id='text']").SendKeys("Google" + Keys.Enter);

            //теперь переходим по ссылке от яндекса
            driver.Url = driver.FindElementByPartialLinkText("google.ru").Text.ToString();

            driver.Url = "https://www.google.ru/#newwindow=1&q=zerg+rush";

            do
            {

                try
                {
                    driver.FindElementByXPath(".//*[@class='zr_zergling_container']").Click();
                }
                catch
                {
                    //если зерглинга еще нет
                }
            } while (true); //TODO: заменить на число из статистики

            Console.ReadKey();
            driver.Quit();
        }
Esempio n. 2
0
        /// <summary>
        /// Test all links on the Krossover home page
        /// </summary>
        public void testHomePage(FirefoxDriver driver)
        {
            string homePage = "http://www.krossover.com/";
            driver.Navigate().GoToUrl(homePage);
            Thread.Sleep(1000);

            //find all links on the page
            IList<IWebElement> links = driver.FindElementsByTagName("a");

            //loop through all of the links on the page
            foreach (IWebElement link in links)
            {
                try
                {
                    //check if any of the links return a 404
                    link.SendKeys(Keys.Control + Keys.Enter);
                    driver.SwitchTo().Window(driver.WindowHandles.Last());

                    driver.FindElementByXPath("//div[contains(@class, '404')]");
                    log(link.GetAttribute("href") + " is broken.  Returned 404");

                    driver.SwitchTo().Window(driver.WindowHandles.First());
                }
                catch
                {
                    //continue to the next link
                    continue;
                }

            }
            driver.Quit(); //kill the driver
        }
 //log out
 public static void logOut(FirefoxDriver driver)
 {
     if (checkForLogin (driver)) {
         driver.FindElementById ("userNavigationLabel").Click();
         driver.FindElementByXPath ("/html/body/div[2]/div/div/div/div/div[1]/div/div/ul/li[12]/a/span/span").Click ();
         return;
     }
     return false;
 }
 public void Test2()
 {
     var driver = new FirefoxDriver();
     driver.Navigate().GoToUrl("http://www.qtptutorial.net/automation-practice");
     driver.Manage().Window.Maximize();
     driver.FindElementByClassName("buttonClassExample").Click();
     var elementCheck = driver.FindElementByXPath("//p[contains(text(),'Button success')]").Displayed;
     Assert.IsFalse(elementCheck, "Element was not present");
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            FirefoxDriver driver = new FirefoxDriver(); //создаем драйвер файрфокса

            driver.Url = "http://10fastfingers.com/typing-test/russian"; //идем на сайт с клавиатурным вводом

            IWebElement InTextbox = driver.FindElementByXPath(".//*[@id='inputfield']"); // создаем экз интерфейса Iwebelement привязываем его к окошку ввода 

            string sInString = ""; //переменная для хранения слова для ввода (чтобы не создавать и разрушать её в цикле, нагружая бедный GC)

            for (int i = 0; i < 180; i++) // С-way хочешь 50 слов в минуту - пиши 50, 100 - 100 (всего похоже 185-190 слов)
            {
                sInString = driver.FindElementByXPath(".//*[@id='row1']/span[@class = 'highlight']").Text.ToString(); //пихаем в строку текст подсвеченного слова
                InTextbox.SendKeys(sInString); //посылаем его на ввод (выглядит как вставка из буфера)
                InTextbox.SendKeys(Keys.Space); // пробел для перехода на новое слово
            }

            Console.ReadKey(); // держим окно при дебаге

            driver.Quit(); //закрываем драйвер
        }
Esempio n. 6
0
        public void FindingStuff_CarBuzz()
        {
            var browser = new FirefoxDriver();
            browser.Navigate().GoToUrl("http://carbuzz.heroku.com/car_search");

            browser.FindElementByName("make_17").Click();
            browser.FindElementByName("make_14").Click();
            browser.FindElementByName("make_11").Click();

            Assert.That(browser.PageSource.Contains(" 5 car reviews found"));

            browser.FindElementByXPath("//ul[@class='seats']/li/button[@value='4']").Click();

            Assert.That(browser.PageSource.Contains(" 1 car reviews found"));
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            RemoteWebDriver browser = new FirefoxDriver();

            try
            {
                browser.Navigate().GoToUrl("http://alitrack.ru/");

                #region Login
                if (browser.FindElementByName("login") != null)
                {
                    browser.FindElementByName("login").SendKeys(cabinet.alitrack.ru.Properties.Settings.Default.UserName);
                    browser.FindElementByName("pass").SendKeys(cabinet.alitrack.ru.Properties.Settings.Default.Password);
                    browser.FindElementByXPath("//input[@type='submit']").Click();
                }
                #endregion

                WaitForCompleteXPath(browser, "//a[contains(@href,'tracking')]");
                browser.Navigate().GoToUrl("http://cabinet.alitrack.ru/tracking/");
                WaitForCompleteXPath(browser, "//a[contains(@href,'tracking')]");


                if (browser.PageSource.Contains("trackingCheckAllItems"))
                {
                    #region update
                    browser.FindElementById("trackingCheckAllItems").Click();
                    var alert = browser.SwitchTo().Alert();
                    alert.Accept();
                    WaitForCompleteXPath(browser, "//div[@id='processingWindow' and contains(@style,'display: none;')]");
                    var trackingRows = browser.FindElementsByClassName("tracking-row");

                    foreach (var trackingRow in trackingRows)
                    {
                        Console.WriteLine(trackingRow.FindElement(By.ClassName("name")).Text);
                        string number = trackingRow.GetAttribute("id").Replace("trow", string.Empty);
                        if (browser.PageSource.Contains(string.Format("id=\"refresh-button{0}\"", number)))
                        {
                            browser.FindElementById("refresh-button" + number).Click();
                            WaitForCompleteXPath(browser, "//div[@id='processingWindow' and contains(@style,'display: none;')]");
                        }
                    }
                    #endregion

                    #region find new
                    browser.Navigate().GoToUrl("http://cabinet.alitrack.ru/tracking/");
                    WaitForCompleteXPath(browser, "//a[contains(@href,'tracking')]");
                    var trackingNewRows = browser.FindElementsByClassName("tracking-row");
                    Regex regexButtons = new Regex("<div[^>]*class=\"buttons\"[^>]*>(.*?)</div>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    Regex regexFull = new Regex("<div[^>]*class=\"fullinfo\"[^>]*>(.*?)</div>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    int newCount = 0;
                    StringBuilder newItems = new StringBuilder();
                    foreach (var trackingRow in trackingNewRows)
                    {
                        Console.WriteLine(trackingRow.FindElement(By.ClassName("name")).Text);
                        if (!string.IsNullOrEmpty(trackingRow.FindElement(By.ClassName("newSteps")).Text))
                        {
                            newCount++;
                            newItems.AppendLine(regexFull.Replace(regexButtons.Replace(trackingRow.GetAttribute("outerHTML"), string.Empty), string.Empty));
                        }
                    }
                    #endregion

                    if (newCount > 0)
                    {
                        #region Processing
                        newItems.Replace("class=\"clear\"", "style=\"clear: both;\"");
                        newItems.Replace("class=\"newSteps\"", "style=\"font-size: 11px;font-weight: normal;color: #a00;display: inline-block;padding: 0 0 0 4px;margin: -5px 0 0 0;vertical-align: top;\"");
                        newItems.Replace("class=\"info\"", "style=\"padding: 0;	overflow: hidden;	white-space: nowrap;color: #50749b;\"");
                        newItems.Replace("class=\"meta\"", "style=\"padding: 3px 0 0 0;	display:inline-block;overflow: hidden;color: #97adc3;white-space: nowrap;\"");
                        newItems.Replace("class=\"name\"", "style=\"font-size: 18px; padding: 9px 0 5px 0; overflow: hidden; color: #50749b; cursor: pointer; white-space: nowrap;\"");

                        newItems.Replace("class=\"tracking-row hasmoves\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #d0e7ff;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasexport\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #bad2ff;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row haslong\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #c0b4ff;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hascustom\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #e6ff8c;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasnotrace\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #ffc994; border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasnative\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #b3fab3;	border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasarrive\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #161; color: #b3fab3; border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row haswarning\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #ffd0d0; color: #50749B; border-radius: 5px;\"");
                        newItems.Replace("class=\"tracking-row hasrecieved\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #DDD;	border-radius: 5px;\"");


                        newItems.Replace("class=\"tracking-row\"", "style=\"font-family: Arial, Verdana, Tahoma; font-size: 12px; line-height: 1em; margin: 0 0 2px 0; background-color: #ebeff3; border-radius: 5px;\"");

                        newItems.Replace("class=\"main\"", "style=\"padding: 0 0 8px 8px; float: left; background-color: #ebeff3; border-radius: 0 5px 5px 0; cursor: pointer; position: relative;\"");
                        newItems.Replace("class=\"time\"", "style=\"font-size: 10px; line-height: 10px; color: #50749b; text-align: center; padding: 35px 0 0;\"");
                        newItems.Replace("class=\"icon\" style=\"", "style=\"float: left;width: 60px;height: 60px;border-radius: 5px 0 0 5px; overflow: hidden; cursor: default;background: url(trackicons/0.png) 14px 5px no-repeat;");
                        newItems.Replace(" class=\"infopos\"", string.Empty);
                        #endregion

                        #region Send report
                        string report = cabinet.alitrack.ru.Properties.Resources.Template.Replace("{NEW}", newItems.ToString());
                        SmtpClient client = new SmtpClient(cabinet.alitrack.ru.Properties.Settings.Default.SMTP);
                        MailAddress from = new MailAddress(cabinet.alitrack.ru.Properties.Settings.Default.EmailFrom);
                        MailAddress to = new MailAddress(cabinet.alitrack.ru.Properties.Settings.Default.EmailTo);
                        MailMessage message = new MailMessage(from, to);
                        message.Subject = string.Format("{0} new update from alitrack", newCount);
                        message.IsBodyHtml = true;
                        message.Body = report;
                        client.Send(message);
                        #endregion
                    }
                }                
            }
            catch(Exception e)
            {
                SmtpClient client = new SmtpClient(cabinet.alitrack.ru.Properties.Settings.Default.SMTP);
                MailAddress from = new MailAddress(cabinet.alitrack.ru.Properties.Settings.Default.EmailFrom);
                MailAddress to = new MailAddress(cabinet.alitrack.ru.Properties.Settings.Default.EmailTo);
                MailMessage message = new MailMessage(from, to);
                message.Subject = "new update from alitrack Exception";                
                message.Body = e.ToString();
                client.Send(message);
            }
            finally
            {
                browser.Quit();
            }
        }