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();
        }
		public void GoingBackInTimeShouldntThrowExceptions()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			var givenUrl = "http://www.a.com/";

			dr.Navigate().GoToUrl(givenUrl);
			dr.Navigate().Back();
			dr.Navigate().Back();
		}
		public void NavigatingBackwardsAfterSecondShouldNavigateToFirstUrl()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			string[] givenUrls = { "http://www.a.com", "http://www.b.com" };
			foreach (string url in givenUrls)
			{
				dr.Navigate().GoToUrl(url);
			}

			dr.Navigate().Back();

			Assert.That(new Uri(dr.Url), Is.EqualTo(new Uri(givenUrls[0])));
		}
Example #4
0
        public void Seek(string url, string pathToSave)
        {
            /*Creates a SimpleBrowserDriver object and uses Navigate.GoToUrl() to access the given address*/
            IWebDriver browser = new SimpleBrowserDriver();
            browser.Navigate().GoToUrl(url);

            /*Gets page source*/
            string pageSource = browser.PageSource;

            /*Seek for image links if "Images" checkbox is checked*/
            if (images)
            {
                MatchCollection imageLinks = SeekImages(pageSource);
                /*Gets the value of all match objects and adds to the ListOfLinks*/
                FileLinks = FixLinks(url, imageLinks.Cast<Match>().Select(match => match.Value).ToList());
            }
            /*Seek for video links if "videos" checkbox is checked*/
            /*Focused on vimeo*/
            if (videos)
            {
                MatchCollection videoLinks = SeekVideos(pageSource);
                FileLinks = videoLinks.Cast<Match>().Select(match => match.Value).ToList();
            }

            /*Creates Downloader object and uses DownloadList() to download all items in ListOfLinks*/
            Downloader downloader = new Downloader();
            downloader.DownloadList(FileLinks, pathToSave);
        }
		public void ClosingWindows()
		{
			IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker(
				new List<Tuple<string, string>>()
				{
					Tuple.Create("^/otherpage", "<html></html>"),
					Tuple.Create("^.*", @"
										<html>
											<a href=""/otherpage"" target=""_blank"" id=""blanklink"">click</a>
										</html>"),
				}
			)));
			var dr = new SimpleBrowserDriver((IBrowser)b);
			dr.Navigate().GoToUrl("http://blah/");
			dr.FindElement(By.Id("blanklink")).Click();
			Assert.That(dr.Url == "http://blah/");
			Assert.That(dr.WindowHandles.Count == 2);
			string otherWindowName = dr.WindowHandles.First(n => n != dr.CurrentWindowHandle);
			var otherDr = dr.SwitchTo().Window(otherWindowName);
			Assert.That(otherDr.Url == "http://blah/otherpage");

			// Now we will close the first window and see that everything behaves as expected
			dr.Close();
			Assert.That(otherDr.WindowHandles.Count == 1);
			Assert.That(otherDr.Url == "http://blah/otherpage"); // still there
			Assert.Throws<ObjectDisposedException>(() => { var a = dr.Url; });

			
		}
		public void GoingBackInitiallyShouldntCallNavigate()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			dr.Navigate().Back();

			Assert.IsNull(b.LastRequest);
		}
		public void NavigatingToUrlShouldDoIt()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			var givenUrl = "http://www.a.com/";

			dr.Navigate().GoToUrl(givenUrl);

			Assert.AreEqual(dr.Url, givenUrl);
			Assert.AreEqual(b.LastRequest.Url.ToString(), givenUrl);
		}
        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>()));
        }
		public void GoingBackAndForthWithNewUrlShouldCallNavigateWithNewUrl()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			string[] givenUrls = { "http://www.a.com", "http://www.b.com" };
			foreach (string url in givenUrls)
			{
				dr.Navigate().GoToUrl(url);
			}
			dr.Navigate().Back();
			string newUrl = "http://www.c.com";

			dr.Navigate().GoToUrl(newUrl);

			Assert.That(b.LastRequest.Url, Is.EqualTo(new Uri(newUrl)));
		}
		public void GoingForwardInTimeShouldntCallNavigateAgain()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			var givenUrl = "http://www.a.com/";
			dr.Navigate().GoToUrl(givenUrl);
			b.LastRequest = null;
			dr.Navigate().Forward();

			Assert.IsNull(b.LastRequest);
		}
		public void GoingToNullUriShouldntCallNavigate()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			dr.Navigate().GoToUrl((Uri)null);

			Assert.IsNull(b.LastRequest);
		}
		public void Issue9()
		{
			SimpleBrowserDriver driver = new SimpleBrowserDriver();
			driver.Navigate().GoToUrl("http://www.totaljobs.com");
			var txt = driver.FindElement(By.Id("left_0_txtKeywords"));
		}
		public void CtrlClick_Should_Open_Link_In_Other_Window()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			dr.Navigate().GoToUrl("http://www.a.com/link.htm");
			Assert.That(dr.WindowHandles.Count == 1);
			Assert.That(dr.Url == "http://www.a.com/link.htm");

			var link = dr.FindElement(By.LinkText("link"));
			Assert.NotNull(link);
			link.Click();
			Assert.That(dr.Url == "http://www.a.com/otherpage.htm");
			dr.Navigate().Back();
			Assert.That(dr.Url == "http://www.a.com/link.htm");
			link = dr.FindElement(By.LinkText("link"));

			Actions builder = new Actions(dr);
			builder.KeyDown(Keys.Control).Click(link).KeyUp(Keys.Control);
			var act = builder.Build();
			act.Perform();

			Assert.That(dr.Url == "http://www.a.com/link.htm");
			Assert.That(dr.WindowHandles.Count == 2);

		}
		public void SubmitGetForm()
		{
			Browser b = new Browser(Helper.GetAllways200RequestMocker());
			b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm"));
			IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b));
			var form = driver.FindElement(By.CssSelector("form"));
			string lastRequest = "";
			b.RequestLogged += (browser, logged) =>
				{
					Console.WriteLine("Request logged: " + logged.Url.ToString());
					lastRequest = logged.Url.AbsoluteUri;
				};
			form.Submit();
			Assert.That(lastRequest.Contains("radios=first"), "Radio buttons not in correct state");
			// NOTE: this line seems wrong: the line breaks in a textarea should remain preserved. But, XML parsing will remove this.
			//       What are the actual rules around this
			//Assert.That(lastRequest.Contains("textarea_a=This+is+a+full+text+part%0d%0awith"), "Textarea not posted correctly");

      driver.Navigate().Back();
      b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm"));
      form = driver.FindElement(By.CssSelector("form"));
      var firstRadio = driver.FindElement(By.Id("first-radio"));
			var firstRadioLabel = driver.FindElement(By.CssSelector("label[for=first-radio]"));
			var secondRadio = driver.FindElement(By.Id("second-radio"));
			secondRadio.Click();
			form.Submit();
			Assert.That(lastRequest.Contains("radios=second"), "Radio buttons not in correct state");

      b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm"));
      form = driver.FindElement(By.CssSelector("form"));
      firstRadioLabel = driver.FindElement(By.CssSelector("label[for=first-radio]"));
      firstRadioLabel.Click();
			form.Submit();
			Assert.That(lastRequest.Contains("radios=first"), "Radio buttons not in correct state");

      b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm"));
      form = driver.FindElement(By.CssSelector("form"));
      var selectBox = driver.FindElement(By.Id("optionsList"));
			var box = new SelectElement(selectBox);
			Assert.That(box.AllSelectedOptions.Count == 1, "First option should be selected in selectbox");
			form.Submit();
			Assert.That(lastRequest.Contains("optionsList=opt1"), "Selectbox not in correct state");

			Assert.That(!lastRequest.Contains("submitButton=button1"), "Value of submit button should not be posted");

      b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm"));
      form = driver.FindElement(By.CssSelector("form"));
      var submitButton = driver.FindElement(By.CssSelector("input[type=submit]"));
			submitButton.Click();
			Assert.That(lastRequest.Contains("submitButton=button1"), "Value of submit button not posted");
		}
		public void CallingRefreshShouldNavigateAgainToSame()
		{
			var b = GetMockedBrowser();
			var dr = new SimpleBrowserDriver((IBrowser)b);
			var givenUrl = "http://www.a.com/";
			dr.Navigate().GoToUrl(givenUrl);
			b.LastRequest = null;

			dr.Navigate().Refresh();

			Assert.NotNull(b.LastRequest);
		}
Example #16
-1
        private void button1_Click(object sender, EventArgs e)
        {
            WebScraper ws = new WebScraper();
            IWebDriver browser = new SimpleBrowserDriver();
            try
            {
                browser.Navigate().GoToUrl(textBox1.Text);
            }
            catch (System.UriFormatException)
            {

                MessageBox.Show("That is not a valid URL!");
                return;
            }
            if (Directory.Exists(textBox2.Text))
            {
                if (Images.Checked || Audios.Checked || Videos.Checked || Documents.Checked)
                {
                    ws.Seek(textBox1.Text, textBox2.Text);
                }
                else
                {
                    MessageBox.Show("Please choose at least one filter option!");
                }
            }
            else
            {
                MessageBox.Show("invalid path !");
            }
        }
		public void OpeningOtherWindows()
		{
			IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker(
				new List<Tuple<string, string>>()
				{
					Tuple.Create("^/otherpage", "<html></html>"),
					Tuple.Create("^.*", @"
										<html>
											<a href=""/otherpage"" target=""_blank"" id=""blanklink"">click</a>
										</html>"),
				}
			)));
			var dr = new SimpleBrowserDriver((IBrowser)b);
			dr.Navigate().GoToUrl("http://blah/");
			dr.FindElement(By.Id("blanklink")).Click();
			Assert.That(dr.Url == "http://blah/");
			Assert.That(dr.WindowHandles.Count == 2);
			string otherWindowName = dr.WindowHandles.First(n => n != dr.CurrentWindowHandle);
			var otherDr = dr.SwitchTo().Window(otherWindowName);
			Assert.That(otherDr.Url == "http://blah/otherpage");

			// click it again will create a thrid window
			dr.FindElement(By.Id("blanklink")).Click();
			Assert.That(dr.Url == "http://blah/");
			Assert.That(dr.WindowHandles.Count == 3);
		}