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; }); }
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 GoingBackInitiallyShouldntCallNavigate() { var b = GetMockedBrowser(); var dr = new SimpleBrowserDriver((IBrowser)b); dr.Navigate().Back(); Assert.IsNull(b.LastRequest); }
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 FindingDuplicatesAndNotFinding() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var anchor = driver.FindElement(By.TagName("a")); Assert.That(anchor.TagName == "a"); Assert.Throws(typeof(NoSuchElementException), ()=>driver.FindElement(By.TagName("nosuchtag"))); }
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); }
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); }
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]))); }
public void UsingCheckboxes() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var checkbox1 = driver.FindElement(By.CssSelector(".cb-container #first-checkbox")); var checkbox2 = driver.FindElement(By.CssSelector(".cb-container #second-checkbox")); Assert.That(checkbox1.Selected, "Checkbox 1 should be selected"); Assert.That(!checkbox2.Selected, "Checkbox 2 should not be selected"); checkbox2.Click(); Assert.That(checkbox1.Selected, "Checkbox 1 should still be selected"); Assert.That(checkbox2.Selected, "Checkbox 2 should be selected"); var checkbox1Label = driver.FindElement(By.CssSelector("label[for=first-checkbox]")); Assert.NotNull(checkbox1Label, "Label not found"); checkbox1Label.Click(); Assert.That(checkbox2.Selected, "Checkbox 2 should still be selected"); Assert.That(!checkbox1.Selected, "Checkbox 1 should be not selected"); }
public void IframesShouldLoad() { IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker( new List<Tuple<string, string>>() { Tuple.Create("^/frame", "<html></html>"), Tuple.Create("^.*", @" <html> <iframe src=""/frame""/><iframe src=""/frame""/> </html>"), } ))); var dr = new SimpleBrowserDriver((IBrowser)b); b.Navigate("http://blah/"); var test = dr.FindElement(By.TagName("html")); Assert.That(dr.WindowHandles.Count == 3); var firstFrame = dr.SwitchTo().Frame(0); Assert.IsNull(firstFrame.FindElement(By.TagName("iframe"))); }
public void UsingRadioButtons() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var radio1 = driver.FindElement(By.CssSelector(".rb-container #first-radio")); var radio2 = driver.FindElement(By.CssSelector(".rb-container #second-radio")); var radio1Label = driver.FindElement(By.CssSelector("label[for=first-radio]")); Assert.That(radio1.Selected, "Radiobutton 1 should be selected"); Assert.That(!radio2.Selected, "Radiobutton 2 should not be selected"); radio2.Click(); Assert.That(!radio1.Selected, "Radiobutton 1 should not be selected"); Assert.That(radio2.Selected, "Radiobutton 2 should be selected"); Assert.NotNull(radio1Label, "Label not found"); radio1Label.Click(); Assert.That(radio1.Selected, "Radiobutton 1 should be selected"); Assert.That(!radio2.Selected, "Radiobutton 2 should be not selected"); }
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"); }
public void UsingSelectBoxes() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var selectbox = driver.FindElement(By.Name("sel")); var box = new SelectElement(selectbox); Assert.That(box.SelectedOption.Text == "two"); box.SelectByValue("3"); Assert.That(box.SelectedOption.Text == "three"); box.SelectByText("one"); Assert.That(box.SelectedOption.Text == "one"); selectbox = driver.FindElement(By.Name("sel_multi")); box = new SelectElement(selectbox); Assert.That(box.IsMultiple); box.SelectByValue("3"); box.SelectByText("one"); Assert.That(box.AllSelectedOptions.Count == 3); }
public void UsingLinks() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var link = driver.FindElement(By.CssSelector("a.clickLink")); string lastRequest = ""; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.Url.ToString(); }; link.Click(); Assert.That(lastRequest.Contains("www.google.com/search"), "Link has resulted in unexpected request"); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); link = driver.FindElement(By.CssSelector("a.link-relative")); link.Click(); Assert.That(lastRequest.Contains("/search"), "Link has resulted in unexpected request"); }
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 UsingHtml5Inputs() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var colorBox = driver.FindElement(By.Id("colorBox")); Assert.NotNull(colorBox, "Couldn't find colorbox"); colorBox.SendKeys("ff0000"); Assert.AreEqual(colorBox.Text, "ff0000", "Colorbox did not pick up sent keys"); 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("colorBox=ff0000"), "Color box not posted correctly"); }
public void SubmitPostForm() { Browser b = new Browser(Helper.GetAllways200RequestMocker()); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var form = driver.FindElement(By.CssSelector("form")); NameValueCollection lastRequest = null; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.PostData; }; form.Submit(); Assert.That(lastRequest.AllKeys.Contains("radios") && lastRequest["radios"].Contains("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.AllKeys.Contains("textarea_a") && lastRequest["textarea_a"].Contains("This is a full text part\r\nwith"), "Textarea not posted correctly"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.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.AllKeys.Contains("radios") && lastRequest["radios"].Contains("second"), "Radio buttons not in correct state"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); form = driver.FindElement(By.CssSelector("form")); firstRadioLabel = driver.FindElement(By.CssSelector("label[for=first-radio]")); firstRadioLabel.Click(); form.Submit(); Assert.That(lastRequest.AllKeys.Contains("radios") && lastRequest["radios"].Contains("first"), "Radio buttons not in correct state"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.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.AllKeys.Contains("optionsList") && lastRequest["optionsList"].Contains("opt1"), "Selectbox not in correct state"); Assert.That(!lastRequest.AllKeys.Contains("submitButton"), "Value of submit button should not be posted"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); var submitButton = driver.FindElement(By.CssSelector("input[type=submit]")); submitButton.Click(); Assert.That(lastRequest.AllKeys.Contains("submitButton") && lastRequest["submitButton"].Contains("button1"), "Value of submit button not posted"); Assert.That(!lastRequest.AllKeys.Contains("submitButton2"), "Value of submit button should not be posted"); b.SetContent(Helper.GetFromResources("DriverTest.SimplePostForm.htm")); submitButton = driver.FindElement(By.CssSelector("button[type=submit]")); submitButton.Click(); Assert.That(lastRequest.AllKeys.Contains("submitButton2") && lastRequest["submitButton2"].Contains("button2"), "Value of submit button not posted"); }
public void UsingTextboxes() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var textbox = driver.FindElement(By.CssSelector("#your-repos-filter")); Assert.NotNull(textbox, "Couldn't find textbox"); Assert.That(textbox.Text == String.Empty, "Textbox without a value attribute should have empty text"); textbox.SendKeys("test text"); Assert.That(textbox.Text == "test text", "Textbox did not pick up sent keys"); textbox.SendKeys(" more"); Assert.That(textbox.Text == "test text more", "Textbox did not append second text"); textbox.Clear(); Assert.That(textbox.Text == String.Empty, "Textbox after Clear should have empty text"); }
public void UsingTextareas() { Browser b = new Browser(); b.SetContent(Helper.GetFromResources("DriverTest.SimpleForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var textbox = driver.FindElement(By.Name("textarea_a")); Assert.That(textbox != null); Assert.That(textbox.Text.Contains("\n"), "Textarea should not make line breaks coalesce into space"); }
public void SubmitGetForm() { Browser b = new Browser(); 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"); 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"); firstRadioLabel.Click(); form.Submit(); Assert.That(lastRequest.Contains("radios=first"), "Radio buttons not in correct state"); 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"); 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 FrameSwitchingUsingElementReference() { IBrowser b = new BrowserWrapper(new Browser(Helper.GetAllways200RequestMocker( new List<Tuple<string, string>>() { Tuple.Create("^/frame", "<html></html>"), Tuple.Create("^.*", @" <html> <body> <iframe src=""/frame""/><iframe src=""/frame""/> </body> </html>"), } ))); var dr = new SimpleBrowserDriver((IBrowser)b); b.Navigate("http://blah/"); //traverse document to init var test = dr.FindElement(By.TagName("body")); Assert.That(test.TagName == "body"); Assert.That(dr.WindowHandles.Count >= 3); var iframe = dr.FindElement(By.TagName("iframe")); var firstFrame = dr.SwitchTo().Frame(iframe); Assert.That(firstFrame.Url == "http://blah/frame"); }
public SimpleManage(SimpleBrowserDriver driver) { _my = driver; }
public void PostAspnetPostbackForm() { Browser b = new Browser(Helper.GetAllways200RequestMocker()); b.SetContent(Helper.GetFromResources("DriverTest.PostbackForm.htm")); IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b)); var form = driver.FindElement(By.CssSelector("form")); NameValueCollection lastRequest = null; b.RequestLogged += (browser, logged) => { Console.WriteLine("Request logged: " + logged.Url.ToString()); lastRequest = logged.PostData; }; var postbackLink = driver.FindElement(By.Id("postbackLink")); postbackLink.Click(); Assert.That(lastRequest.AllKeys.Contains("__EVENTTARGET") && lastRequest["__EVENTTARGET"].Contains("colorBox"), "colorBox was not indicated as the postback target"); }
public void GoingToNullUriShouldntCallNavigate() { var b = GetMockedBrowser(); var dr = new SimpleBrowserDriver((IBrowser)b); dr.Navigate().GoToUrl((Uri)null); Assert.IsNull(b.LastRequest); }
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 SimpleManage(SimpleBrowserDriver driver) { _my = driver; }
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); }
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); }
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 !"); } }