Quit() 공개 메소드

Close the Browser and Dispose of WebDriver
public Quit ( ) : void
리턴 void
		public static IWebDriver Authenticate()
		{
			string email = "admin@test";
			IWebDriver webDriver = new RemoteWebDriver(new Uri("http://localhost:9515"), DesiredCapabilities.Chrome());
			//webDriver.Manage().Window.Maximize();
			webDriver.Navigate().GoToUrl("http://dev.icms/Account/Login");
			//Enter email address on login page
			IWebElement emailLogin = webDriver.FindElement(By.Id("Email"));
			emailLogin.Clear();
			emailLogin.SendKeys(email);
			IWebElement authenticateButton = webDriver.FindElement(By.Id("requestauth"));
			authenticateButton.Click();
			//this should have sent me an email
			//Let's pretend we got the email and check the server for the authtoken and plug it into the URL

			string token = HttpUtility.UrlEncode(TestUtilities.AuthenticationUtil.GetAuthToken(email));
			string goToUrl = string.Format("http://dev.icms/account/authorize/?authtoken={0}&email={1}&returnUrl=%2f", token, email);

			webDriver.Quit();
			webDriver = new RemoteWebDriver(new Uri("http://localhost:9515"), DesiredCapabilities.Chrome());

			webDriver.Navigate().GoToUrl(goToUrl);

			//Check DOM to see if we are logged in
			IWebElement elem = webDriver.FindElement(By.CssSelector("h1"));
			//webDriver.Quit();
			if (elem.Text == "Welcome Admin Development")
			{
				return webDriver;
			}
			return null;
		}
 public void ShouldBeAbleToCreateRemoteWebDriverWithNoSlashAtEndOfUri()
 {
     Environment.EnvironmentManager.Instance.CloseCurrentDriver();
     RemoteWebDriver noSlashDriver = new RemoteWebDriver(new Uri("http://127.0.0.1:6000/wd/hub"), DesiredCapabilities.InternetExplorer());
     noSlashDriver.Url = javascriptPage;
     noSlashDriver.Quit();
 }
예제 #3
0
        public void FindPrice()
        {
            IWebDriver driver_ = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());
            driver_.Navigate().GoToUrl("http://www.momoshop.com.tw");

            driver_.FindElement(By.CssSelector("#keyword")).SendKeys(this.SearchKeyWord_);
            driver_.FindElement(By.CssSelector(".inputbtn")).Click();

            Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();

            try
            {
                if (driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count == 0)
                {
                    ReadProductDetail(driver_.Url, ref info);
                }
                else
                {
                    var PageCount = driver_.FindElements(By.XPath("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li")).ToList().Count;

                    for (var CurrentPage = 1; CurrentPage <= PageCount;)
                    {
                        List<IWebElement> products = driver_.FindElements(By.XPath("//*[@id=\"chessboard\"]/li/a")).ToList();
                        foreach (var product in products)
                        {
                            ReadProductDetail(product.GetAttribute("href"), ref info);
                        }

                        //Last Page
                        if (CurrentPage == PageCount)
                        {
                            break;
                        }

                        //Next Page
                        ++CurrentPage;
                        driver_.FindElement(By.XPath(string.Format("//*[@id=\"BodyBase\"]/form[1]/div/div[2]/div[5]/ul/li[{0}]/a", CurrentPage))).Click();
                    }

                }
            }
            catch (NoSuchElementException)
            {
            }

            this.ProductDetail_.Add("momo", info);
            driver_.Quit();
            if (LocalDriver_ != null)
            {
                LocalDriver_.Quit();
            }
            return;
        }
 private void CheckDriverThenClose(RemoteWebDriver driver)
 {
     try
     {
         Assert.IsNotNull(driver);
         driver.Navigate().GoToUrl("http://google.com");
         Log.Debug(GetUserAgent(driver));
     }
     finally
     {
         driver.Quit();
     }
 }
예제 #5
0
        public void UnitTest()
        {
            //IWebDriver wd = new RemoteWebDriver(DesiredCapabilities.Firefox());

            //wd.Navigate().GoToUrl("http://113.128.163.253/securepay/account/login.aspx");
            DesiredCapabilities caps = DesiredCapabilities.InternetExplorer();
            caps.SetCapability("browser", "IE");
            caps.SetCapability("browser_version", "11.0");
            caps.SetCapability("os", "Windows");
            caps.SetCapability("os_version", "10");
            caps.SetCapability("resolution", "1024x768");
            IWebDriver wd = new RemoteWebDriver(new Uri("http://113.128.163.253/securepay/account/login.aspx"), caps);

            try
            {
                wd.FindElement(By.Id("MainContent_UserName")).Click();
                wd.FindElement(By.Id("MainContent_UserName")).Clear();
                wd.FindElement(By.Id("MainContent_UserName")).SendKeys("Sudhakar");
                wd.FindElement(By.Id("MainContent_Password")).Click();
                wd.FindElement(By.Id("MainContent_Password")).Clear();
                wd.FindElement(By.Id("MainContent_Password")).SendKeys("sudhakar");
                wd.FindElement(By.Id("MainContent_UserEntry")).Click();
                wd.FindElement(By.Id("MainContent_UserEntry")).Clear();
                wd.FindElement(By.Id("MainContent_UserEntry")).SendKeys("646F2");
                wd.FindElement(By.Id("MainContent_LoginButton")).Click();
                wd.FindElement(By.LinkText("Virtual Card")).Click();
                wd.FindElement(By.Id("ContentPlaceHolder1_btnAddNew")).Click();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtCardNumber")).Click();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtCardNumber")).Clear();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtCardNumber")).SendKeys("4566882593");
                wd.FindElement(By.XPath("//div[@id='ContentPlaceHolder1_divAddCard']/table/tbody/tr[1]/td[5]")).Click();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtNameonCard")).Click();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtNameonCard")).Clear();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtNameonCard")).SendKeys("Sudhakar");
                wd.FindElement(By.Id("ContentPlaceHolder1_txtPriority")).Click();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtPriority")).Clear();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtPriority")).SendKeys("2");
                wd.FindElement(By.Id("ContentPlaceHolder1_txtPercentage")).Click();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtPercentage")).Clear();
                wd.FindElement(By.Id("ContentPlaceHolder1_txtPercentage")).SendKeys("20");
                if (!wd.FindElement(By.Id("ContentPlaceHolder1_chkConfirm")).Selected)
                {
                    wd.FindElement(By.Id("ContentPlaceHolder1_chkConfirm")).Click();
                }
                wd.FindElement(By.Id("ContentPlaceHolder1_btnSubmit")).Click();
                wd.FindElement(By.LinkText("Products")).Click();
            }
            finally { wd.Quit(); }
        }
예제 #6
0
        public static void Main(string[] args)
        {
            // find the test application
            Console.WriteLine("Finding Test App");
            string appPath = _GetTestAppPath();
            Console.WriteLine("Using Test App @ \"" + appPath + "\"");

            // set up the remote web driver
            Console.WriteLine("Connecting to Appium server");
            DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.SetCapability("browserName", "iOS");
            capabilities.SetCapability("platform", "Mac");
            capabilities.SetCapability("version", "6.0");
            capabilities.SetCapability("app", appPath);
            RemoteWebDriver driver = new RemoteWebDriver(new Uri("http://127.0.0.1:4723/wd/hub"), capabilities);

            // enter random numbers in all text fields
            Console.WriteLine("Entering addends");
            List<int> addends = new List<int>();
            Random randomNumberGenerator = new Random();
            var elements = driver.FindElementsByTagName("textField");
            foreach(var element in elements)
            {
                int randomNumber = randomNumberGenerator.Next(0,10);
                element.SendKeys(randomNumber.ToString());
                addends.Add(randomNumber);
            }

            // calculate the expected result
            int expectedResult = 0;
            foreach(int i in addends)
                expectedResult += i;

            Console.WriteLine("Submitting the form");
            // submit for computation
            var buttons = driver.FindElementsByTagName("button");
            buttons[0].Click();

            // validate the computation
            var staticTexts = driver.FindElementsByTagName("staticText");
            int actualResult = int.Parse(staticTexts[0].Text);
            bool pass = expectedResult == actualResult;
            _LogWithColor(pass, "EXPECTED: " + expectedResult.ToString() + " ACTUAL: " + actualResult.ToString());

            // shutdown
            driver.Quit();
        }
예제 #7
0
 public static void OpenHtmlUnitDriver()
 {
     // initialize a WebDriver instance
     //IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.HtmlUnit());
     IWebDriver driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnit());
     // load google search page
     driver.Navigate().GoToUrl("https://www.google.ca");
     // print title
     Console.WriteLine("Page title: " + driver.Title);
     // enter search word and submit
     IWebElement element = driver.FindElement(By.Name("q"));
     element.SendKeys("Cheese");
     element.Submit();
     // print title
     Console.WriteLine("Page title: " + driver.Title);
     // quit the driver
     driver.Quit();
 }
        static void Main(string[] args)
        {
            Local local = new Local();

              List<KeyValuePair<string, string>> options = new List<KeyValuePair<string, string>>() {
            new KeyValuePair<string, string>("key", BROWSERSTACK_ACCESS_KEY),
            //new KeyValuePair<string, string>("localIdentifier", "identifier"),
            //new KeyValuePair<string, string>("f", "C:\\Users\\Admin\\Desktop\\"),
            new KeyValuePair<string, string>("onlyAutomate", "true"),
            new KeyValuePair<string, string>("verbose", "true"),
            new KeyValuePair<string, string>("forcelocal", "true"),
            new KeyValuePair<string, string>("binarypath", "C:\\Users\\Admin\\Desktop\\BrowserStackLocal.exe"),
            new KeyValuePair<string, string>("logfile", "C:\\Users\\Admin\\Desktop\\local.log"),
              };
              local.start(options);

              // Run WebDriver Tests
              IWebDriver driver;
              DesiredCapabilities capability = DesiredCapabilities.Firefox();
              capability.SetCapability("browserstack.user", BROWSERSTACK_USERNAME);
              capability.SetCapability("browserstack.key", BROWSERSTACK_ACCESS_KEY);
              //capability.SetCapability("browserstack.localIdentifier", "identifier");
              capability.SetCapability("browserstack.local", true);
              capability.SetCapability("build", "build");

              driver = new RemoteWebDriver(
            new Uri("http://hub.browserstack.com/wd/hub/"), capability
              );
              driver.Navigate().GoToUrl("http://www.google.com");
              Console.WriteLine(driver.Title);

              IWebElement query = driver.FindElement(By.Name("q"));
              query.SendKeys("Browserstack");
              query.Submit();
              Console.WriteLine(driver.Title);

              driver.Quit();
              local.stop();
              Console.WriteLine("Test Completed.");
              Console.ReadLine();
        }
예제 #9
0
 private static void CrawlFirstPage(Uri startUrl)
 {
     ChromeOptions chromeOptions = new ChromeOptions();
     chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
     
     var _driver = new RemoteWebDriver(_options.RemoteHubUrl, chromeOptions.ToCapabilities());
     try
     {
         _driver.Navigate().GoToUrl(startUrl);
         SaveHtmlAndScreenShot(startUrl, _driver);
         pageVisitedURLMapping.TryAdd(startUrl, startUrl);
         _driver.Close();
         _driver.Quit();
     }
     catch (Exception ex)
     {
         logger.Info(" Thread : " + startUrl.PathAndQuery + " Error at " + ex.StackTrace);
         _driver.Close();
         _driver.Quit();
     }
 }
예제 #10
0
        public void FindPrice()
        {
            IWebDriver driver = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());
            driver.Navigate().GoToUrl("http://www.pcstore.com.tw/");
            Thread.Sleep(1000);

            //#id_search_word
            driver.FindElement(By.CssSelector("#id_search_word")).SendKeys(this.SearchKeyWord_);
            driver.FindElement(By.XPath("//*[@id=\"top-search\"]/img")).Click();

            Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();

            for (; ; )
            {
                List<IWebElement> ProductList = driver.FindElements(By.XPath("//*[@id=\"keyad-pro-right3\"]/div[1]/a")).ToList();
                foreach (var product in ProductList)
                {
                    ReadProductDetail(product.GetAttribute("href"), ref info);
                }

                try
                {
                    driver.FindElement(By.XPath("//*[@id=\"container\"]/div[10]/table[1]/tbody/tr/td[5]/a")).Click();
                    Thread.Sleep(1000);
                }
                catch (System.Exception)
                {
                    break;
                }
            }

            this.ProductDetail_.Add("PcHome", info);
            if (LocalDriver_ != null)
            {
                LocalDriver_.Quit();
            }
            driver.Quit();
            return;
        }
예제 #11
0
        public static void CrawlPage(Uri startUrl)
        {
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
            chromeOptions.AddArgument("user-data-dir=C:/Debug/" + startUrl.AbsolutePath);
            var _driver = new RemoteWebDriver(_options.RemoteHubUrl, chromeOptions.ToCapabilities());
            
            try
            {
                ConcurrentDictionary<Uri, Uri> pageToVisit = new ConcurrentDictionary<Uri, Uri>();
                ConcurrentDictionary<Uri, Uri> PartThreading;
                pageToVisit.TryAdd(startUrl, null);
                
                while (true && pageToVisit.Count > 0)
                {
                    PartThreading = new ConcurrentDictionary<Uri, Uri>();
                    logger.Info(_options.Name + " Thread : " + startUrl.PathAndQuery + " Page To Visit Size :{0}", pageToVisit.Count + " SessionId" + _driver.SessionId );
                    foreach (var pTV in pageToVisit)
                    {

                        PartThreading.TryAdd(pTV.Key, pTV.Value);
                        Uri value;
                        pageToVisit.TryRemove(pTV.Key, out value);
                    }
                    foreach (var Key in PartThreading.Keys)
                    {
                        _driver.Navigate().GoToUrl(Key);
                        
                        SaveHtmlAndScreenShot(Key, _driver);
                        pageToVisit = GetUnvisitedLinks(_driver, Key, _driver.Url, PartThreading, pageToVisit, startUrl);
                        pageVisitedURLMapping.TryAdd(Key, PartThreading[Key]);
                        
                        ValidatePage(_driver, Key, PartThreading[Key]);

                    }

                    logger.Info(" Thread : " + startUrl.PathAndQuery + " Page Finish Visit Size :{0}",   pageVisitedURLMapping.Count);

                }
                _driver.Close();
                _driver.Quit();
            }
            catch (Exception ex)
            {
                logger.Info(" Thread : " + startUrl.PathAndQuery + " Error at " + ex.StackTrace);
                _driver.Close();
                _driver.Quit();
            }


        }
예제 #12
0
        public void FindPrice()
        {
            IWebDriver driver = new RemoteWebDriver(new Uri("http://192.168.1.4:4444/wd/hub"), DesiredCapabilities.Firefox());

            //超級商城
            driver.Navigate().GoToUrl("https://tw.mall.yahoo.com/");

            driver.FindElement(By.XPath("//*[@id=\"srp-ac-bar\"]")).SendKeys(this.SearchKeyWord_);
            driver.FindElement(By.XPath("//*[@id=\"UHSearchProperty\"]")).Click();

            Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>> info = new Dictionary<string, Dictionary<ProductInfo.ProductInfo, string>>();

            for (; ; )
            {
                List<IWebElement> products = driver.FindElements(By.XPath("//*[@id=\"srp_result_list\"]/div/div/div[1]/a")).ToList();
                foreach (var product in products)
                {
                    ReadProductDetailMail(product.GetAttribute("href"), ref info);
                }

                try
                {
                    if (driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Text == "下一頁")
                    {
                        driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Click();
                    }
                    else
                    {
                        break;
                    }

                    products.Clear();
                    Thread.Sleep(1000);
                }
                catch (NoSuchElementException e)
                {
                    break;
                }
            }

            //購物中心
            driver.Navigate().GoToUrl("https://tw.buy.yahoo.com/");
            driver.FindElement(By.XPath("//*[@id=\"srp-ac-bar\"]")).SendKeys(this.SearchKeyWord_);
            driver.FindElement(By.XPath("//*[@id=\"UHSearchProperty\"]")).Click();
            List<IWebElement> buyproducts = driver.FindElements(By.XPath("//*[@id=\"srp_result_list\"]/div/div/div[1]/a")).ToList();

            for (; ; )
            {
                List<IWebElement> products = driver.FindElements(By.XPath("//*[@id=\"srp_result_list\"]/div/div/div[1]/a")).ToList();
                foreach (var product in buyproducts)
                {
                    ReadProductDetailBuy(product.GetAttribute("href"), ref info);
                }

                try
                {
                    if (driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Text == "下一頁")
                    {
                        driver.FindElement(By.XPath("//*[@id=\"srp_sl_result\"]/div[3]/ul")).FindElements(
                            By.XPath(".//li/a")).ToList().Last().Click();
                    }
                    else
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
                catch (NoSuchElementException e)
                {
                    break;
                }
            }

            this.ProductDetail_.Add("Yahoo", info);
            driver.Quit();
            if (LocalDriver_ != null)
            {
                LocalDriver_.Quit();
            }
            return;
        }
예제 #13
0
        public void BVT_BrowserStack()
        {
            IWebDriver driver;
            driver = new RemoteWebDriver(
                new Uri("http://hub.browserstack.com/wd/hub/"), base.BrowserCapabilities);
            driver.Navigate().GoToUrl("http://www.google.com/ncr");
            Console.WriteLine(driver.Title);

            IWebElement query = driver.FindElement(By.Name("q"));
            query.SendKeys("Browserstack");
            query.Submit();
            Console.WriteLine(driver.Title);

            if (false == driver.Title.Contains("Google")) {
                Assert.Fail("Expected: '{0}' and Actual: '{1}'", "Google", driver.Title);
            } else {
                Console.WriteLine("Expected: '{0}' and Actual: '{1}'", "Google", driver.Title);
            }
            driver.Quit();
        }