コード例 #1
0
        static void Main(string[] args)
        {
            // This is some really stupid testing code. I want to replace this by proper unit test and mock away 
            // the simplebrowser library and the internet using MoQ
            IWebDriver browser = new SimpleBrowserDriver();
            browser.Navigate().GoToUrl("http://*****:*****@placeholder]"));
            inputBox.SendKeys("test");
            Console.WriteLine(inputBox.Text);
            inputBox = browser.FindElement(By.Name("somename"));
            Console.WriteLine(inputBox.Text);

            browser.Navigate().GoToUrl("http://www.funda.nl/koop");
            var firstThings = browser.FindElements(By.CssSelector("*[name!='description' ]"));
            firstThings = browser.FindElements(By.CssSelector("div[class ~= frst]"));
            firstThings = browser.FindElements(By.CssSelector("*[class ^= nav]"));

            var input = browser.FindElement(By.Name("PCPlaats"));
            input.SendKeys("Utrecht");
            input.Submit();
            Console.WriteLine(browser.Title);


            
            Console.ReadLine();
        }
コード例 #2
0
        public void SearchingInKnownDocument()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm"));
            IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b));

            var iconSpans = driver.FindElements(By.CssSelector("span.icon"));
            Assert.That(iconSpans.Count == 4, "There should be 4 spans with class icon");

            var accountSettings = driver.FindElements(By.CssSelector("*[title~= Account]"));
            Assert.That(accountSettings.Count == 1 && accountSettings[0].Text == "Account Settings", "There should be 1 element with title containing the word Account");

            var topStuff = driver.FindElements(By.CssSelector("*[class|=top]"));
            Assert.That(topStuff.Count == 3 , "There should be 3 elements with class starting with top-");

            var h2s = driver.FindElements(By.CssSelector("h2"));
            Assert.That(h2s.Count == 8, "There should be 8 h2 elements");

            var titleContainingTeun = driver.FindElements(By.CssSelector("*[title*=Teun]"));
            Assert.That(titleContainingTeun.Count == 3, "There should be 3 elements with 'Teun' somewhere in the title attrbute");
        }
コード例 #3
0
        private void SetupElementSearch(By by, out Mock<IHtmlResult> mock)
        {
            var browserMock = new Mock<IBrowser>();
            mock = new Mock<IHtmlResult>();
            var foundElement = new Mock<IHtmlResult>();
            var elmEnumerator = new Mock<IEnumerator<IHtmlResult>>();

            foundElement.Setup(h => h.TotalElementsFound).Returns(1);
            foundElement.Setup(h => h.GetEnumerator()).Returns(elmEnumerator.Object);
            elmEnumerator.Setup(e => e.Current).Returns(foundElement.Object);
            elmEnumerator.SetupSequence(e => e.MoveNext()).Returns(true).Returns(false);
            mock.Setup(h => h.TotalElementsFound).Returns(1);
            mock.Setup(h => h.Select(It.IsAny<string>())).Returns(foundElement.Object);
            mock.Setup(root => root.Select(It.IsAny<string>())).Returns(foundElement.Object);
            browserMock.Setup(browser => browser.Find("html", It.IsAny<object>())).Returns(mock.Object);

            string url = "http://testweb.tst";
            SimpleBrowserDriver driver = new SimpleBrowserDriver(browserMock.Object);
            driver.Navigate().GoToUrl(url);
            driver.FindElements(by);

            browserMock.Verify(b => b.Navigate(url));
            browserMock.Verify(b => b.Find("html", It.IsAny<object>()));
        }
コード例 #4
0
		public void Searching_Html_Root_Element_Should_Work()
		{
			Browser b = new Browser();
			b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm"));
			IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b));

			var rootElement = driver.FindElements(By.TagName("html"));
			Assert.NotNull(rootElement);
			Assert.That(rootElement.Count > 0);
		}